From 55b62ae7b7446773b388037d406f0c20ca60e672 Mon Sep 17 00:00:00 2001
From: Franz Chih-Ping Hsieh <chsieh@redhat.com>
Date: Jul 20 2018 08:10:02 +0000
Subject: [PATCH 1/2] copy data from static variable instead of use it directly to prevent caching.


also update test cases to verfiy this issue.

Fixes: #994
https://pagure.io/koji/issue/994

---

diff --git a/koji/rpmdiff.py b/koji/rpmdiff.py
index 2ab6e81..bdb56bd 100644
--- a/koji/rpmdiff.py
+++ b/koji/rpmdiff.py
@@ -81,7 +81,7 @@ class Rpmdiff:
         if self.ignore is None:
             self.ignore = []
 
-        FILEIDX = self.__FILEIDX
+        FILEIDX = [entry[:] for entry in self.__FILEIDX]
         for tag in self.ignore:
             for entry in FILEIDX:
                 if tag == entry[0]:
diff --git a/tests/test_hub/data/rpms/test-pkg-1.0.0-1.el7.noarch.rpm b/tests/test_hub/data/rpms/test-pkg-1.0.0-1.el7.noarch.rpm
new file mode 100644
index 0000000..1180e2e
Binary files /dev/null and b/tests/test_hub/data/rpms/test-pkg-1.0.0-1.el7.noarch.rpm differ
diff --git a/tests/test_hub/data/rpms/test-pkg-1.0.0-1.fc24.noarch.rpm b/tests/test_hub/data/rpms/test-pkg-1.0.0-1.fc24.noarch.rpm
new file mode 100644
index 0000000..e960b67
Binary files /dev/null and b/tests/test_hub/data/rpms/test-pkg-1.0.0-1.fc24.noarch.rpm differ
diff --git a/tests/test_hub/test_rpmdiff.py b/tests/test_hub/test_rpmdiff.py
index c7d00f4..7e647e6 100644
--- a/tests/test_hub/test_rpmdiff.py
+++ b/tests/test_hub/test_rpmdiff.py
@@ -1,6 +1,7 @@
 from __future__ import absolute_import
 import copy
 import mock
+import os
 try:
     import unittest2 as unittest
 except ImportError:
@@ -37,6 +38,30 @@ class TestRPMDiff(unittest.TestCase):
         Rpmdiff.assert_called_once_with('basepath/12/1234/foo', 'basepath/13/1345/bar', ignore='S5TN')
         d.textdiff.assert_called_once_with()
 
+    def test_rpmdiff_real_target(self):
+        data_path = os.path.abspath("tests/test_hub/data/rpms")
+
+        # the only differences between rpm1 and rpm2 are 1) create time 2) file name
+        rpm1 = os.path.join(data_path, 'test-pkg-1.0.0-1.el7.noarch.rpm')
+        rpm2 = os.path.join(data_path, 'test-pkg-1.0.0-1.fc24.noarch.rpm')
+
+        diff_output = "..........T /usr/share/test-pkg/test-doc01.txt\n" + \
+                      "..........T /usr/share/test-pkg/test-doc02.txt\n" + \
+                      "..........T /usr/share/test-pkg/test-doc03.txt\n" + \
+                      "..........T /usr/share/test-pkg/test-doc04.txt"
+
+        # case 1. no ignore option, timestamp is different
+        # perform twice check to verify issue: #994
+        for _ in range(0, 2):
+            d = koji.rpmdiff.Rpmdiff(rpm1, rpm2)
+            self.assertEqual(d.textdiff(), diff_output)
+
+        # case 2. ignore timestamp, two rpms should be the same
+        # perform twice check to verify issue: #994
+        for r in range(0, 2):
+            d = koji.rpmdiff.Rpmdiff(rpm1, rpm2, ignore='S5TN')
+            self.assertEqual(d.textdiff(), '')
+
 class TestCheckNoarchRpms(unittest.TestCase):
     @mock.patch('kojihub.rpmdiff')
     def test_check_noarch_rpms_empty_invocation(self, rpmdiff):

From 14740e031754dfd49a4e0a4dfd0df2223930f9d1 Mon Sep 17 00:00:00 2001
From: Tomas Kopecek <tkopecek@redhat.com>
Date: Jul 20 2018 08:10:02 +0000
Subject: [PATCH 2/2] Correctly ignore all values in rpmdiff


Related: https://pagure.io/koji/issue/994

---

diff --git a/koji/rpmdiff.py b/koji/rpmdiff.py
index bdb56bd..6cbfaeb 100644
--- a/koji/rpmdiff.py
+++ b/koji/rpmdiff.py
@@ -86,7 +86,7 @@ class Rpmdiff:
             for entry in FILEIDX:
                 if tag == entry[0]:
                     # store marked position for erasing data
-                    entry[1] = -entry[1]
+                    entry[1] = -entry[1] - 100
                     break
 
         old = self.__load_pkg(old)
@@ -140,8 +140,8 @@ class Rpmdiff:
                         diff = 1
                     elif entry[1] < 0:
                         # erase fields which are ignored
-                        old_file[-entry[1]] = None
-                        new_file[-entry[1]] = None
+                        old_file[-entry[1] - 100] = None
+                        new_file[-entry[1] - 100] = None
                         format = format + '.'
                     else:
                         format = format + '.'
diff --git a/tests/test_hub/data/rpms/different_size_a.noarch.rpm b/tests/test_hub/data/rpms/different_size_a.noarch.rpm
new file mode 100644
index 0000000..6e8be2f
Binary files /dev/null and b/tests/test_hub/data/rpms/different_size_a.noarch.rpm differ
diff --git a/tests/test_hub/data/rpms/different_size_b.noarch.rpm b/tests/test_hub/data/rpms/different_size_b.noarch.rpm
new file mode 100644
index 0000000..056c222
Binary files /dev/null and b/tests/test_hub/data/rpms/different_size_b.noarch.rpm differ
diff --git a/tests/test_hub/test_rpmdiff.py b/tests/test_hub/test_rpmdiff.py
index 7e647e6..213be78 100644
--- a/tests/test_hub/test_rpmdiff.py
+++ b/tests/test_hub/test_rpmdiff.py
@@ -62,6 +62,27 @@ class TestRPMDiff(unittest.TestCase):
             d = koji.rpmdiff.Rpmdiff(rpm1, rpm2, ignore='S5TN')
             self.assertEqual(d.textdiff(), '')
 
+    def test_rpmdiff_size(self):
+        data_path = os.path.abspath("tests/test_hub/data/rpms")
+
+        # the only differences between rpm1 and rpm2 are 1) create time 2) file name
+        rpm1 = os.path.join(data_path, 'different_size_a.noarch.rpm')
+        rpm2 = os.path.join(data_path, 'different_size_b.noarch.rpm')
+
+        diff_output = "S.5.......T /bin/test"
+
+        # case 1. no ignore option, timestamp is different
+        # perform twice check to verify issue: #994
+        for _ in range(0, 2):
+            d = koji.rpmdiff.Rpmdiff(rpm1, rpm2)
+            self.assertEqual(d.textdiff(), diff_output)
+
+        # case 2. ignore timestamp, two rpms should be the same
+        # perform twice check to verify issue: #994
+        for r in range(0, 2):
+            d = koji.rpmdiff.Rpmdiff(rpm1, rpm2, ignore='S5TN')
+            self.assertEqual(d.textdiff(), '')
+
 class TestCheckNoarchRpms(unittest.TestCase):
     @mock.patch('kojihub.rpmdiff')
     def test_check_noarch_rpms_empty_invocation(self, rpmdiff):

