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