Commits

Armin Rigo committed 81cb7e6 Merge

merge heads

Comments (0)

Files changed (2)

pypy/module/zipimport/interp_zipimport.py

             return mtime
 
     def check_newer_pyfile(self, space, filename, timestamp):
+        # check if the timestamp stored in the .pyc is matching
+        # the actual timestamp of the .py file, if any
         mtime = self._parse_mtime(space, filename)
         if mtime == 0:
             return False
-        return mtime > timestamp
-
-    def check_compatible_mtime(self, space, filename, timestamp):
-        mtime = self._parse_mtime(space, filename)
-        if mtime == 0 or mtime != (timestamp & (~1)):
-            return False
-        return True
+        # Lenient date/time comparison function. The precision of the mtime
+        # in the archive is lower than the mtime stored in a .pyc: we
+        # must allow a difference of at most one second.
+        d = mtime - timestamp
+        if d < 0:
+            d = -d
+        return d > 1    # more than one second => different
 
     def can_use_pyc(self, space, filename, magic, timestamp):
         if magic != importing.get_pyc_magic(space):
             return False
         if self.check_newer_pyfile(space, filename[:-1], timestamp):
             return False
-        if not self.check_compatible_mtime(space, filename, timestamp):
-            return False
         return True
 
     def import_pyc_file(self, space, modname, filename, buf, pkgpath):

pypy/module/zipimport/test/test_zipimport.py

         """)
         self.w_modules = []
 
+    def w_now_in_the_future(self, delta):
+        self.now += delta
+
     def w_writefile(self, filename, data):
         import sys
         import time
         import os
         import zipimport
         data = "saddsadsa"
+        pyc_data = self.test_pyc
+        self.now_in_the_future(+5)   # write the zipfile 5 secs after the .pyc
         self.writefile("xxx", data)
         self.writefile("xx/__init__.py", "5")
         self.writefile("yy.py", "3")
-        self.writefile('uu.pyc', self.test_pyc)
+        self.writefile('uu.pyc', pyc_data)
         z = zipimport.zipimporter(self.zipfile)
         assert z.get_data(self.zipfile + os.sep + "xxx") == data
         assert z.is_package("xx")
         raises(ImportError, "z.get_source('zz')")
         #assert z.get_code('yy') == py.code.Source('3').compile()
         #assert z.get_code('uu') == self.co
+        assert z.get_code('uu')
         assert z.get_code('xx')
         assert z.get_source('xx') == "5"
         assert z.archive == self.zipfile