Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH v2] egencache: stable use.local.desc mtime for rsync (bug 557192)
Date: Tue, 25 Aug 2015 16:34:50
Message-Id: 1440520456-24786-1-git-send-email-zmedico@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] egencache: stable use.local.desc mtime for rsync (bug 557192) by Zac Medico
1 Preserve mtime when the md5sum is identical.
2
3 X-Gentoo-Bug: 557192
4 X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=557192
5 ---
6 [PATCH v2] ensures exact integer mtime when there is not an existing file, for
7 consistency with the mtime preservation code.
8
9 bin/egencache | 20 ++++++++++++++++++++
10 1 file changed, 20 insertions(+)
11
12 diff --git a/bin/egencache b/bin/egencache
13 index 5c00248..4f4c715 100755
14 --- a/bin/egencache
15 +++ b/bin/egencache
16 @@ -7,6 +7,7 @@ from __future__ import print_function, unicode_literals
17
18 import platform
19 import signal
20 +import stat
21 import sys
22 # This block ensures that ^C interrupts are handled quietly.
23 try:
24 @@ -487,6 +488,8 @@ class GenUseLocalDesc(object):
25 def run(self):
26 repo_path = self._portdb.porttrees[0]
27 ops = {'<':0, '<=':1, '=':2, '>=':3, '>':4}
28 + prev_mtime = None
29 + prev_md5 = None
30
31 if self._output is None or self._output != '-':
32 if self._output is None:
33 @@ -500,6 +503,12 @@ class GenUseLocalDesc(object):
34 desc_path = self._output
35
36 try:
37 + prev_md5 = portage.checksum.perform_md5(desc_path)
38 + prev_mtime = os.stat(desc_path)[stat.ST_MTIME]
39 + except (portage.exception.FileNotFound, OSError):
40 + pass
41 +
42 + try:
43 if self._preserve_comments:
44 # Probe in binary mode, in order to avoid
45 # potential character encoding issues.
46 @@ -651,6 +660,17 @@ class GenUseLocalDesc(object):
47 output.write('%s:%s - %s\n' % (cp, flag, resdesc))
48
49 output.close()
50 + if (prev_mtime is not None and
51 + prev_md5 == portage.checksum.perform_md5(desc_path)):
52 + # Preserve mtime for rsync.
53 + mtime = prev_mtime
54 + else:
55 + # For portability, and consistency with the mtime preservation
56 + # code, set mtime to an exact integer value.
57 + mtime = int(time.time())
58 +
59 + os.utime(desc_path, (mtime, mtime))
60 +
61
62 if sys.hexversion < 0x3000000:
63 _filename_base = unicode
64 --
65 2.4.6

Replies