1 |
On 12/31/2017 11:55 AM, Alec Warner wrote: |
2 |
> On Fri, Dec 29, 2017 at 7:19 PM, Zac Medico <zmedico@g.o |
3 |
> <mailto:zmedico@g.o>> wrote: |
4 |
> |
5 |
> Bug: https://bugs.gentoo.org/642632 |
6 |
> --- |
7 |
> [PATCH v2] fix to copy atime, and split out _set_timestamps function |
8 |
> |
9 |
> bin/doins.py | 28 +++++++++++++++++++++++++--- |
10 |
> pym/portage/tests/bin/test_doins.py | 6 ++++-- |
11 |
> 2 files changed, 29 insertions(+), 5 deletions(-) |
12 |
> |
13 |
> diff --git a/bin/doins.py b/bin/doins.py |
14 |
> index 92e450979..0d03d8fb2 100644 |
15 |
> --- a/bin/doins.py |
16 |
> +++ b/bin/doins.py |
17 |
> @@ -107,6 +107,7 @@ def _parse_install_options( |
18 |
> parser.add_argument('-g', '--group', default=-1, |
19 |
> type=_parse_group) |
20 |
> parser.add_argument('-o', '--owner', default=-1, |
21 |
> type=_parse_user) |
22 |
> parser.add_argument('-m', '--mode', default=0o755, |
23 |
> type=_parse_mode) |
24 |
> + parser.add_argument('-p', '--preserve-timestamps', |
25 |
> action='store_true') |
26 |
> split_options = shlex.split(options) |
27 |
> namespace, remaining = parser.parse_known_args(split_options) |
28 |
> # Because parsing '--mode' option is partially supported. If |
29 |
> unknown |
30 |
> @@ -139,6 +140,24 @@ def _set_attributes(options, path): |
31 |
> os.chmod(path, options.mode) |
32 |
> |
33 |
> |
34 |
> +def _set_timestamps(source_stat, dest): |
35 |
> + """Apply timestamps from source_stat to dest. |
36 |
> + |
37 |
> + Args: |
38 |
> + source_stat: stat result for the source file. |
39 |
> + dest: path to the dest file. |
40 |
> + """ |
41 |
> + os.utime(dest, (source_stat.st_atime, source_stat.st_mtime)) |
42 |
> + |
43 |
> + |
44 |
> +if sys.version_info >= (3, 3): |
45 |
> + def _set_timestamps_ns(source_stat, dest): |
46 |
> + os.utime(dest, ns=(source_stat.st_atime_ns, |
47 |
> source_stat.st_mtime_ns)) |
48 |
> + |
49 |
> + _set_timestamps_ns.__doc__ = _set_timestamps.__doc__ |
50 |
> + _set_timestamps = _set_timestamps_ns |
51 |
> + |
52 |
> + |
53 |
> class _InsInProcessInstallRunner(object): |
54 |
> """Implements `install` command behavior running in a |
55 |
> process.""" |
56 |
> |
57 |
> @@ -168,7 +187,8 @@ class _InsInProcessInstallRunner(object): |
58 |
> True on success, otherwise False. |
59 |
> """ |
60 |
> dest = os.path.join(dest_dir, os.path.basename(source)) |
61 |
> - if not self._is_install_allowed(source, dest): |
62 |
> |
63 |
> |
64 |
> I'm going to be api picky here (so forgive me). |
65 |
> |
66 |
> Previously is_install_allowed seemed to take great care with which stat |
67 |
> was used. But now callers have to just know to use os.stat (as opposed |
68 |
> to lstat, or other stats)? |
69 |
> |
70 |
> Should we update the is_install_allowed comment (perhaps to say that |
71 |
> source_stat prefers os.stat?) |
72 |
|
73 |
Updated the is_install_allowed docstring in v3. |
74 |
|
75 |
> Part of me just wishes the stat was cached at a different layer (so that |
76 |
> code like this wasn't required just to save the syscall ;( |
77 |
|
78 |
The _doins function has an earlier stat call here: |
79 |
|
80 |
if os.path.islink(source): |
81 |
|
82 |
We can implement more caching at some point, but it's beyond the scope |
83 |
of this patch. |
84 |
-- |
85 |
Thanks, |
86 |
Zac |