1 |
Signed-off-by: Michał Górny <mgorny@g.o> |
2 |
--- |
3 |
bin/chpathtool.py | 8 +-- |
4 |
bin/doins.py | 14 +---- |
5 |
lib/portage/_emirrordist/FetchTask.py | 13 ++-- |
6 |
lib/portage/dbapi/vartree.py | 25 ++------ |
7 |
lib/portage/util/_compare_files.py | 22 +++---- |
8 |
.../util/_dyn_libs/PreservedLibsRegistry.py | 7 +-- |
9 |
lib/portage/util/movefile.py | 60 +++++-------------- |
10 |
lib/portage/util/mtimedb.py | 7 +-- |
11 |
8 files changed, 39 insertions(+), 117 deletions(-) |
12 |
|
13 |
diff --git a/bin/chpathtool.py b/bin/chpathtool.py |
14 |
index fbd18b987..c036046ae 100755 |
15 |
--- a/bin/chpathtool.py |
16 |
+++ b/bin/chpathtool.py |
17 |
@@ -128,12 +128,8 @@ def chpath_inplace(filename, is_text_file, old, new): |
18 |
|
19 |
f.close() |
20 |
if modified: |
21 |
- if sys.hexversion >= 0x3030000: |
22 |
- orig_mtime = orig_stat.st_mtime_ns |
23 |
- os.utime(filename, ns=(orig_mtime, orig_mtime)) |
24 |
- else: |
25 |
- orig_mtime = orig_stat[stat.ST_MTIME] |
26 |
- os.utime(filename, (orig_mtime, orig_mtime)) |
27 |
+ orig_mtime = orig_stat.st_mtime_ns |
28 |
+ os.utime(filename, ns=(orig_mtime, orig_mtime)) |
29 |
return modified |
30 |
|
31 |
def chpath_inplace_symlink(filename, st, old, new): |
32 |
diff --git a/bin/doins.py b/bin/doins.py |
33 |
index 98dc4f810..a08e3f8c9 100644 |
34 |
--- a/bin/doins.py |
35 |
+++ b/bin/doins.py |
36 |
@@ -110,10 +110,6 @@ def _parse_install_options( |
37 |
parser.add_argument('-p', '--preserve-timestamps', action='store_true') |
38 |
split_options = shlex.split(options) |
39 |
namespace, remaining = parser.parse_known_args(split_options) |
40 |
- if namespace.preserve_timestamps and sys.version_info < (3, 3): |
41 |
- # -p is not supported in this case, since timestamps cannot |
42 |
- # be preserved with full precision |
43 |
- remaining.append('-p') |
44 |
# Because parsing '--mode' option is partially supported. If unknown |
45 |
# arg for --mode is passed, namespace.mode is set to None. |
46 |
if remaining or namespace.mode is None: |
47 |
@@ -151,15 +147,7 @@ def _set_timestamps(source_stat, dest): |
48 |
source_stat: stat result for the source file. |
49 |
dest: path to the dest file. |
50 |
""" |
51 |
- os.utime(dest, (source_stat.st_atime, source_stat.st_mtime)) |
52 |
- |
53 |
- |
54 |
-if sys.version_info >= (3, 3): |
55 |
- def _set_timestamps_ns(source_stat, dest): |
56 |
- os.utime(dest, ns=(source_stat.st_atime_ns, source_stat.st_mtime_ns)) |
57 |
- |
58 |
- _set_timestamps_ns.__doc__ = _set_timestamps.__doc__ |
59 |
- _set_timestamps = _set_timestamps_ns |
60 |
+ os.utime(dest, ns=(source_stat.st_atime_ns, source_stat.st_mtime_ns)) |
61 |
|
62 |
|
63 |
class _InsInProcessInstallRunner(object): |
64 |
diff --git a/lib/portage/_emirrordist/FetchTask.py b/lib/portage/_emirrordist/FetchTask.py |
65 |
index 322de79ba..a1ba58822 100644 |
66 |
--- a/lib/portage/_emirrordist/FetchTask.py |
67 |
+++ b/lib/portage/_emirrordist/FetchTask.py |
68 |
@@ -1,4 +1,4 @@ |
69 |
-# Copyright 2013-2019 Gentoo Authors |
70 |
+# Copyright 2013-2020 Gentoo Authors |
71 |
# Distributed under the terms of the GNU General Public License v2 |
72 |
|
73 |
from __future__ import division |
74 |
@@ -385,14 +385,9 @@ class FetchTask(CompositeTask): |
75 |
# Apply the timestamp from the source file, but |
76 |
# just rely on umask for permissions. |
77 |
try: |
78 |
- if sys.hexversion >= 0x3030000: |
79 |
- os.utime(copier.dest_path, |
80 |
- ns=(self._current_stat.st_mtime_ns, |
81 |
- self._current_stat.st_mtime_ns)) |
82 |
- else: |
83 |
- os.utime(copier.dest_path, |
84 |
- (self._current_stat[stat.ST_MTIME], |
85 |
- self._current_stat[stat.ST_MTIME])) |
86 |
+ os.utime(copier.dest_path, |
87 |
+ ns=(self._current_stat.st_mtime_ns, |
88 |
+ self._current_stat.st_mtime_ns)) |
89 |
except OSError as e: |
90 |
msg = "%s %s utime failed unexpectedly: %s" % \ |
91 |
(self.distfile, current_mirror.name, e) |
92 |
diff --git a/lib/portage/dbapi/vartree.py b/lib/portage/dbapi/vartree.py |
93 |
index abb0a9308..2e29b25e5 100644 |
94 |
--- a/lib/portage/dbapi/vartree.py |
95 |
+++ b/lib/portage/dbapi/vartree.py |
96 |
@@ -435,10 +435,7 @@ class vardbapi(dbapi): |
97 |
if mysplit[0] == '*': |
98 |
mysplit[0] = mysplit[0][1:] |
99 |
try: |
100 |
- if sys.hexversion >= 0x3030000: |
101 |
- mystat = os.stat(self.getpath(mysplit[0])).st_mtime_ns |
102 |
- else: |
103 |
- mystat = os.stat(self.getpath(mysplit[0])).st_mtime |
104 |
+ mystat = os.stat(self.getpath(mysplit[0])).st_mtime_ns |
105 |
except OSError: |
106 |
mystat = 0 |
107 |
if use_cache and mycp in self.cpcache: |
108 |
@@ -586,10 +583,7 @@ class vardbapi(dbapi): |
109 |
return list(self._iter_match(mydep, |
110 |
self.cp_list(mydep.cp, use_cache=use_cache))) |
111 |
try: |
112 |
- if sys.hexversion >= 0x3030000: |
113 |
- curmtime = os.stat(os.path.join(self._eroot, VDB_PATH, mycat)).st_mtime_ns |
114 |
- else: |
115 |
- curmtime = os.stat(os.path.join(self._eroot, VDB_PATH, mycat)).st_mtime |
116 |
+ curmtime = os.stat(os.path.join(self._eroot, VDB_PATH, mycat)).st_mtime_ns |
117 |
except (IOError, OSError): |
118 |
curmtime=0 |
119 |
|
120 |
@@ -4921,10 +4915,7 @@ class dblink(object): |
121 |
mymd5 = None |
122 |
myto = None |
123 |
|
124 |
- if sys.hexversion >= 0x3030000: |
125 |
- mymtime = mystat.st_mtime_ns |
126 |
- else: |
127 |
- mymtime = mystat[stat.ST_MTIME] |
128 |
+ mymtime = mystat.st_mtime_ns |
129 |
|
130 |
if stat.S_ISREG(mymode): |
131 |
mymd5 = perform_md5(mysrc, calc_prelink=calc_prelink) |
132 |
@@ -5067,10 +5058,7 @@ class dblink(object): |
133 |
% (relative_path, myabsto)]) |
134 |
|
135 |
showMessage("%s %s -> %s\n" % (zing, mydest, myto)) |
136 |
- if sys.hexversion >= 0x3030000: |
137 |
- outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime // 1000000000)+"\n") |
138 |
- else: |
139 |
- outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime)+"\n") |
140 |
+ outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime // 1000000000)+"\n") |
141 |
else: |
142 |
showMessage(_("!!! Failed to move file.\n"), |
143 |
level=logging.ERROR, noiselevel=-1) |
144 |
@@ -5219,10 +5207,7 @@ class dblink(object): |
145 |
pass |
146 |
|
147 |
if mymtime != None: |
148 |
- if sys.hexversion >= 0x3030000: |
149 |
- outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime // 1000000000)+"\n") |
150 |
- else: |
151 |
- outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime)+"\n") |
152 |
+ outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime // 1000000000)+"\n") |
153 |
showMessage("%s %s\n" % (zing,mydest)) |
154 |
else: |
155 |
# we are merging a fifo or device node |
156 |
diff --git a/lib/portage/util/_compare_files.py b/lib/portage/util/_compare_files.py |
157 |
index bd993e501..c3223d956 100644 |
158 |
--- a/lib/portage/util/_compare_files.py |
159 |
+++ b/lib/portage/util/_compare_files.py |
160 |
@@ -1,4 +1,4 @@ |
161 |
-# Copyright 2019 Gentoo Authors |
162 |
+# Copyright 2019-2020 Gentoo Authors |
163 |
# Distributed under the terms of the GNU General Public License v2 |
164 |
|
165 |
__all__ = ["compare_files"] |
166 |
@@ -49,20 +49,12 @@ def compare_files(file1, file2, skipped_types=()): |
167 |
if "xattr" not in skipped_types and sorted(xattr.get_all(file1, nofollow=True)) != sorted(xattr.get_all(file2, nofollow=True)): |
168 |
differences.append("xattr") |
169 |
|
170 |
- if sys.hexversion >= 0x3030000: |
171 |
- if "atime" not in skipped_types and file1_stat.st_atime_ns != file2_stat.st_atime_ns: |
172 |
- differences.append("atime") |
173 |
- if "mtime" not in skipped_types and file1_stat.st_mtime_ns != file2_stat.st_mtime_ns: |
174 |
- differences.append("mtime") |
175 |
- if "ctime" not in skipped_types and file1_stat.st_ctime_ns != file2_stat.st_ctime_ns: |
176 |
- differences.append("ctime") |
177 |
- else: |
178 |
- if "atime" not in skipped_types and file1_stat.st_atime != file2_stat.st_atime: |
179 |
- differences.append("atime") |
180 |
- if "mtime" not in skipped_types and file1_stat.st_mtime != file2_stat.st_mtime: |
181 |
- differences.append("mtime") |
182 |
- if "ctime" not in skipped_types and file1_stat.st_ctime != file2_stat.st_ctime: |
183 |
- differences.append("ctime") |
184 |
+ if "atime" not in skipped_types and file1_stat.st_atime_ns != file2_stat.st_atime_ns: |
185 |
+ differences.append("atime") |
186 |
+ if "mtime" not in skipped_types and file1_stat.st_mtime_ns != file2_stat.st_mtime_ns: |
187 |
+ differences.append("mtime") |
188 |
+ if "ctime" not in skipped_types and file1_stat.st_ctime_ns != file2_stat.st_ctime_ns: |
189 |
+ differences.append("ctime") |
190 |
|
191 |
if "type" in differences: |
192 |
pass |
193 |
diff --git a/lib/portage/util/_dyn_libs/PreservedLibsRegistry.py b/lib/portage/util/_dyn_libs/PreservedLibsRegistry.py |
194 |
index 7909f258c..b82b11cb5 100644 |
195 |
--- a/lib/portage/util/_dyn_libs/PreservedLibsRegistry.py |
196 |
+++ b/lib/portage/util/_dyn_libs/PreservedLibsRegistry.py |
197 |
@@ -34,12 +34,9 @@ class PreservedLibsRegistry(object): |
198 |
|
199 |
_json_write_opts = { |
200 |
"ensure_ascii": False, |
201 |
- "indent": "\t", |
202 |
- "sort_keys": True |
203 |
+ "indent": 4, |
204 |
+ "sort_keys": True, |
205 |
} |
206 |
- if sys.hexversion < 0x30200F0: |
207 |
- # indent only supports int number of spaces |
208 |
- _json_write_opts["indent"] = 4 |
209 |
|
210 |
def __init__(self, root, filename): |
211 |
""" |
212 |
diff --git a/lib/portage/util/movefile.py b/lib/portage/util/movefile.py |
213 |
index e6180e9f1..e7be8792c 100644 |
214 |
--- a/lib/portage/util/movefile.py |
215 |
+++ b/lib/portage/util/movefile.py |
216 |
@@ -1,4 +1,4 @@ |
217 |
-# Copyright 2010-2018 Gentoo Foundation |
218 |
+# Copyright 2010-2020 Gentoo Authors |
219 |
# Distributed under the terms of the GNU General Public License v2 |
220 |
|
221 |
from __future__ import absolute_import |
222 |
@@ -188,18 +188,13 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, |
223 |
except OSError: |
224 |
pass |
225 |
|
226 |
- if sys.hexversion >= 0x3030000: |
227 |
- try: |
228 |
- os.utime(dest, ns=(sstat.st_mtime_ns, sstat.st_mtime_ns), follow_symlinks=False) |
229 |
- except NotImplementedError: |
230 |
- # utimensat() and lutimes() missing in libc. |
231 |
- return os.stat(dest, follow_symlinks=False).st_mtime_ns |
232 |
- else: |
233 |
- return sstat.st_mtime_ns |
234 |
+ try: |
235 |
+ os.utime(dest, ns=(sstat.st_mtime_ns, sstat.st_mtime_ns), follow_symlinks=False) |
236 |
+ except NotImplementedError: |
237 |
+ # utimensat() and lutimes() missing in libc. |
238 |
+ return os.stat(dest, follow_symlinks=False).st_mtime_ns |
239 |
else: |
240 |
- # utime() in Python <3.3 only works on the target of a symlink, so it's not |
241 |
- # possible to preserve mtime on symlinks. |
242 |
- return os.lstat(dest)[stat.ST_MTIME] |
243 |
+ return sstat.st_mtime_ns |
244 |
except SystemExit as e: |
245 |
raise |
246 |
except Exception as e: |
247 |
@@ -312,49 +307,26 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, |
248 |
# if the nanosecond part of the timestamp is 999999881 ns or greater. |
249 |
try: |
250 |
if hardlinked: |
251 |
- if sys.hexversion >= 0x3030000: |
252 |
- newmtime = os.stat(dest).st_mtime_ns |
253 |
- else: |
254 |
- newmtime = os.stat(dest)[stat.ST_MTIME] |
255 |
+ newmtime = os.stat(dest).st_mtime_ns |
256 |
else: |
257 |
# Note: It is not possible to preserve nanosecond precision |
258 |
# (supported in POSIX.1-2008 via utimensat) with the IEEE 754 |
259 |
# double precision float which only has a 53 bit significand. |
260 |
if newmtime is not None: |
261 |
- if sys.hexversion >= 0x3030000: |
262 |
- os.utime(dest, ns=(newmtime, newmtime)) |
263 |
- else: |
264 |
- os.utime(dest, (newmtime, newmtime)) |
265 |
+ os.utime(dest, ns=(newmtime, newmtime)) |
266 |
else: |
267 |
- if sys.hexversion >= 0x3030000: |
268 |
- newmtime = sstat.st_mtime_ns |
269 |
- else: |
270 |
- newmtime = sstat[stat.ST_MTIME] |
271 |
+ newmtime = sstat.st_mtime_ns |
272 |
if renamefailed: |
273 |
- if sys.hexversion >= 0x3030000: |
274 |
- # If rename succeeded then timestamps are automatically |
275 |
- # preserved with complete precision because the source |
276 |
- # and destination inodes are the same. Otherwise, manually |
277 |
- # update timestamps with nanosecond precision. |
278 |
- os.utime(dest, ns=(newmtime, newmtime)) |
279 |
- else: |
280 |
- # If rename succeeded then timestamps are automatically |
281 |
- # preserved with complete precision because the source |
282 |
- # and destination inodes are the same. Otherwise, round |
283 |
- # down to the nearest whole second since python's float |
284 |
- # st_mtime cannot be used to preserve the st_mtim.tv_nsec |
285 |
- # field with complete precision. Note that we have to use |
286 |
- # stat_obj[stat.ST_MTIME] here because the float |
287 |
- # stat_obj.st_mtime rounds *up* sometimes. |
288 |
- os.utime(dest, (newmtime, newmtime)) |
289 |
+ # If rename succeeded then timestamps are automatically |
290 |
+ # preserved with complete precision because the source |
291 |
+ # and destination inodes are the same. Otherwise, manually |
292 |
+ # update timestamps with nanosecond precision. |
293 |
+ os.utime(dest, ns=(newmtime, newmtime)) |
294 |
except OSError: |
295 |
# The utime can fail here with EPERM even though the move succeeded. |
296 |
# Instead of failing, use stat to return the mtime if possible. |
297 |
try: |
298 |
- if sys.hexversion >= 0x3030000: |
299 |
- newmtime = os.stat(dest).st_mtime_ns |
300 |
- else: |
301 |
- newmtime = os.stat(dest)[stat.ST_MTIME] |
302 |
+ newmtime = os.stat(dest).st_mtime_ns |
303 |
except OSError as e: |
304 |
writemsg(_("!!! Failed to stat in movefile()\n"), noiselevel=-1) |
305 |
writemsg("!!! %s\n" % dest, noiselevel=-1) |
306 |
diff --git a/lib/portage/util/mtimedb.py b/lib/portage/util/mtimedb.py |
307 |
index 30922a901..e1605310e 100644 |
308 |
--- a/lib/portage/util/mtimedb.py |
309 |
+++ b/lib/portage/util/mtimedb.py |
310 |
@@ -1,4 +1,4 @@ |
311 |
-# Copyright 2010-2012 Gentoo Foundation |
312 |
+# Copyright 2010-2020 Gentoo Authors |
313 |
# Distributed under the terms of the GNU General Public License v2 |
314 |
|
315 |
__all__ = ['MtimeDB'] |
316 |
@@ -29,12 +29,9 @@ class MtimeDB(dict): |
317 |
|
318 |
_json_write_opts = { |
319 |
"ensure_ascii": False, |
320 |
- "indent": "\t", |
321 |
+ "indent": 4, |
322 |
"sort_keys": True |
323 |
} |
324 |
- if sys.hexversion < 0x30200F0: |
325 |
- # indent only supports int number of spaces |
326 |
- _json_write_opts["indent"] = 4 |
327 |
|
328 |
def __init__(self, filename): |
329 |
dict.__init__(self) |
330 |
-- |
331 |
2.27.0 |