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] Manifest.write: stable/predictable Manifest mtime for rsync (bug 557962)
Date: Mon, 17 Aug 2015 03:09:18
Message-Id: 1439780890-1753-1-git-send-email-zmedico@gentoo.org
1 Use the max mtime of the existing Manifest and the files that the updated
2 Manifest contains.
3
4 X-Gentoo-Bug: 557962
5 X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=557962
6 ---
7 pym/portage/manifest.py | 35 +++++++++++++++++++++++++++++++++++
8 1 file changed, 35 insertions(+)
9
10 diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py
11 index 3936b9a..f5cf0f5 100644
12 --- a/pym/portage/manifest.py
13 +++ b/pym/portage/manifest.py
14 @@ -6,6 +6,7 @@ from __future__ import unicode_literals
15 import errno
16 import io
17 import re
18 +import stat
19 import sys
20 import warnings
21
22 @@ -281,6 +282,7 @@ class Manifest(object):
23 try:
24 myentries = list(self._createManifestEntries())
25 update_manifest = True
26 + existing_st = None
27 if myentries and not force:
28 try:
29 f = io.open(_unicode_encode(self.getFullname(),
30 @@ -288,6 +290,7 @@ class Manifest(object):
31 mode='r', encoding=_encodings['repo.content'],
32 errors='replace')
33 oldentries = list(self._parseManifestLines(f))
34 + existing_st = os.fstat(f.fileno())
35 f.close()
36 if len(oldentries) == len(myentries):
37 update_manifest = False
38 @@ -309,6 +312,7 @@ class Manifest(object):
39 # non-empty for all currently known use cases.
40 write_atomic(self.getFullname(), "".join("%s\n" %
41 _unicode(myentry) for myentry in myentries))
42 + self._apply_max_mtime(existing_st, myentries)
43 rval = True
44 else:
45 # With thin manifest, there's no need to have
46 @@ -328,6 +332,37 @@ class Manifest(object):
47 raise
48 return rval
49
50 + def _apply_max_mtime(self, existing_st, entries):
51 + """
52 + Set the Manifest mtime to the max mtime of all relevant files
53 + (the existing Manifest mtime is included in order to account for
54 + eclass modifications that change DIST entries). This results in a
55 + stable/predictable mtime, which is useful when converting thin
56 + manifests to thick manifests for distribution via rsync. For
57 + portability, the mtime is set with 1 second resolution.
58 +
59 + @param existing_st: stat result for existing Manifest
60 + @type existing_st: posix.stat_result
61 + @param entries: list of current Manifest2Entry instances
62 + @type entries: list
63 + """
64 + # Use stat_result[stat.ST_MTIME] for 1 second resolution, since
65 + # it always rounds down. Note that stat_result.st_mtime will round
66 + # up from 0.999999999 to 1.0 when precision is lost during conversion
67 + # from nanosecond resolution to float.
68 + max_mtime = None if existing_st is None else existing_st[stat.ST_MTIME]
69 + for entry in entries:
70 + if entry.type == 'DIST':
71 + continue
72 + abs_path = (os.path.join(self.pkgdir, 'files', entry.name) if
73 + entry.type == 'AUX' else os.path.join(self.pkgdir, entry.name))
74 + mtime = os.stat(abs_path)[stat.ST_MTIME]
75 + if max_mtime is None or mtime > max_mtime:
76 + max_mtime = mtime
77 +
78 + if max_mtime is not None:
79 + os.utime(self.getFullname(), (max_mtime, max_mtime))
80 +
81 def sign(self):
82 """ Sign the Manifest """
83 raise NotImplementedError()
84 --
85 2.4.6

Replies