Fix index file's mtime, which can differ from TIMESTAMP.
authorW-Mark Kubacki <wmark@hurrikane.de>
Wed, 1 Aug 2012 19:12:24 +0000 (21:12 +0200)
committerZac Medico <zmedico@gentoo.org>
Thu, 2 Aug 2012 00:54:44 +0000 (17:54 -0700)
This enables Portage to reliably query for remote indices with
HTTP-header If-Modified-Since.

Without this patch mtime is greater than TIMESTAMP for large
indices and slow storages - because writing a large file takes
time. If the difference spans a second (TIMESTAMP 08:00:00, mtime
08:00:01), then Portage will always fetch the remote index because
it will appear being modified (mtime is used there) after the copy
has been made (local copy's TIMESTAMP is used here).

pym/portage/dbapi/bintree.py

index 16ae8eccf8551556b6f04a870b865f9beaf83b0c..03675031e57086051876113104d14e18c0e77fdc 100644 (file)
@@ -1186,9 +1186,13 @@ class binarytree(object):
                        pkgindex.packages.append(d)
 
                        self._update_pkgindex_header(pkgindex.header)
-                       f = atomic_ofstream(os.path.join(self.pkgdir, "Packages"))
+                       pkgindex_filename = os.path.join(self.pkgdir, "Packages")
+                       f = atomic_ofstream(pkgindex_filename)
                        pkgindex.write(f)
                        f.close()
+                       # some seconds might have elapsed since TIMESTAMP
+                       atime = mtime = long(pkgindex.header["TIMESTAMP"])
+                       os.utime(pkgindex_filename, (atime, mtime))
                finally:
                        if pkgindex_lock:
                                unlockfile(pkgindex_lock)