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