commit:     041a81dd1b99d538620ea395d1cf1a36c47a7735
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 25 07:42:23 2015 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Aug 26 01:50:59 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=041a81dd

egencache: stable use.local.desc mtime for rsync (bug 557192)

Preserve mtime when the md5sum is identical.

X-Gentoo-Bug: 557192
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=557192
Acked-by: Brian Dolbec <dolsen <AT> gentoo.org>

 bin/egencache | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/bin/egencache b/bin/egencache
index 5c00248..4f4c715 100755
--- a/bin/egencache
+++ b/bin/egencache
@@ -7,6 +7,7 @@ from __future__ import print_function, unicode_literals
 
 import platform
 import signal
+import stat
 import sys
 # This block ensures that ^C interrupts are handled quietly.
 try:
@@ -487,6 +488,8 @@ class GenUseLocalDesc(object):
        def run(self):
                repo_path = self._portdb.porttrees[0]
                ops = {'<':0, '<=':1, '=':2, '>=':3, '>':4}
+               prev_mtime = None
+               prev_md5 = None
 
                if self._output is None or self._output != '-':
                        if self._output is None:
@@ -500,6 +503,12 @@ class GenUseLocalDesc(object):
                                desc_path = self._output
 
                        try:
+                               prev_md5 = 
portage.checksum.perform_md5(desc_path)
+                               prev_mtime = os.stat(desc_path)[stat.ST_MTIME]
+                       except (portage.exception.FileNotFound, OSError):
+                               pass
+
+                       try:
                                if self._preserve_comments:
                                        # Probe in binary mode, in order to 
avoid
                                        # potential character encoding issues.
@@ -651,6 +660,17 @@ class GenUseLocalDesc(object):
                                                output.write('%s:%s - %s\n' % 
(cp, flag, resdesc))
 
                output.close()
+               if (prev_mtime is not None and
+                       prev_md5 == portage.checksum.perform_md5(desc_path)):
+                       # Preserve mtime for rsync.
+                       mtime = prev_mtime
+               else:
+                       # For portability, and consistency with the mtime 
preservation
+                       # code, set mtime to an exact integer value.
+                       mtime = int(time.time())
+
+               os.utime(desc_path, (mtime, mtime))
+
 
 if sys.hexversion < 0x3000000:
        _filename_base = unicode

Reply via email to