Gentoo Archives: gentoo-commits

From: Arfrever Frehtes Taifersar Arahesis <arfrever.fta@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/
Date: Tue, 31 Jul 2012 23:06:55
Message-Id: 1343775768.e9951cc2d1f39af8222d55385d43e0ad1eeb548a.arfrever@gentoo
1 commit: e9951cc2d1f39af8222d55385d43e0ad1eeb548a
2 Author: Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache <DOT> Org>
3 AuthorDate: Tue Jul 31 23:02:48 2012 +0000
4 Commit: Arfrever Frehtes Taifersar Arahesis <arfrever.fta <AT> gmail <DOT> com>
5 CommitDate: Tue Jul 31 23:02:48 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=e9951cc2
7
8 Use nanosecond precision in portage.util.movefile.movefile().
9
10 ---
11 pym/portage/dbapi/vartree.py | 20 +++++++++++----
12 pym/portage/util/movefile.py | 55 +++++++++++++++++++++++++++++-------------
13 2 files changed, 53 insertions(+), 22 deletions(-)
14
15 diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
16 index ea62f6b..08580e8 100644
17 --- a/pym/portage/dbapi/vartree.py
18 +++ b/pym/portage/dbapi/vartree.py
19 @@ -4262,8 +4262,9 @@ class dblink(object):
20 @type stufftomerge: String or List
21 @param cfgfiledict: { File:mtime } mapping for config_protected files
22 @type cfgfiledict: Dictionary
23 - @param thismtime: The current time (typically long(time.time())
24 - @type thismtime: Long
25 + @param thismtime: None or new mtime for merged files (expressed in seconds
26 + in Python <3.3 and nanoseconds in Python >=3.3)
27 + @type thismtime: None or Int
28 @rtype: None or Boolean
29 @return:
30 1. True on failure
31 @@ -4396,7 +4397,10 @@ class dblink(object):
32 encoding=_encodings['merge'])
33 if mymtime != None:
34 showMessage(">>> %s -> %s\n" % (mydest, myto))
35 - outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime)+"\n")
36 + if sys.hexversion >= 0x3030000:
37 + outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime // 1000000000)+"\n")
38 + else:
39 + outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime)+"\n")
40 else:
41 showMessage(_("!!! Failed to move file.\n"),
42 level=logging.ERROR, noiselevel=-1)
43 @@ -4550,7 +4554,10 @@ class dblink(object):
44 cfgprot = cfgfiledict["IGNORE"]
45 if not moveme:
46 zing = "---"
47 - mymtime = mystat[stat.ST_MTIME]
48 + if sys.hexversion >= 0x3030000:
49 + mymtime = mystat.st_mtime_ns
50 + else:
51 + mymtime = mystat[stat.ST_MTIME]
52 else:
53 moveme = 1
54 cfgprot = 1
55 @@ -4587,7 +4594,10 @@ class dblink(object):
56 zing = ">>>"
57
58 if mymtime != None:
59 - outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime)+"\n")
60 + if sys.hexversion >= 0x3030000:
61 + outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime // 1000000000)+"\n")
62 + else:
63 + outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime)+"\n")
64 showMessage("%s %s\n" % (zing,mydest))
65 else:
66 # we are merging a fifo or device node
67
68 diff --git a/pym/portage/util/movefile.py b/pym/portage/util/movefile.py
69 index 10577b5..b9c4183 100644
70 --- a/pym/portage/util/movefile.py
71 +++ b/pym/portage/util/movefile.py
72 @@ -7,6 +7,7 @@ import errno
73 import os as _os
74 import shutil as _shutil
75 import stat
76 +import sys
77 import subprocess
78 import textwrap
79
80 @@ -78,8 +79,9 @@ else:
81 def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
82 hardlink_candidates=None, encoding=_encodings['fs']):
83 """moves a file from src to dest, preserving all permissions and attributes; mtime will
84 - be preserved even when moving across filesystems. Returns true on success and false on
85 - failure. Move is atomic."""
86 + be preserved even when moving across filesystems. Returns mtime as integer on success
87 + and None on failure. mtime is expressed in seconds in Python <3.3 and nanoseconds in
88 + Python >=3.3. Move is atomic."""
89
90 if mysettings is None:
91 mysettings = portage.settings
92 @@ -265,35 +267,54 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
93 writemsg("!!! %s\n" % a, noiselevel=-1)
94 return None # failure
95
96 - # Always use stat_obj[stat.ST_MTIME] for the integral timestamp which
97 - # is returned, since the stat_obj.st_mtime float attribute rounds *up*
98 + # In Python <3.3 always use stat_obj[stat.ST_MTIME] for the integral timestamp
99 + # which is returned, since the stat_obj.st_mtime float attribute rounds *up*
100 # if the nanosecond part of the timestamp is 999999881 ns or greater.
101 try:
102 if hardlinked:
103 - newmtime = os.stat(dest)[stat.ST_MTIME]
104 + if sys.hexversion >= 0x3030000:
105 + newmtime = os.stat(dest).st_mtime_ns
106 + else:
107 + newmtime = os.stat(dest)[stat.ST_MTIME]
108 else:
109 # Note: It is not possible to preserve nanosecond precision
110 # (supported in POSIX.1-2008 via utimensat) with the IEEE 754
111 # double precision float which only has a 53 bit significand.
112 if newmtime is not None:
113 - os.utime(dest, (newmtime, newmtime))
114 + if sys.hexversion >= 0x3030000:
115 + os.utime(dest, ns=(newmtime, newmtime))
116 + else:
117 + os.utime(dest, (newmtime, newmtime))
118 else:
119 - newmtime = sstat[stat.ST_MTIME]
120 + if sys.hexversion >= 0x3030000:
121 + newmtime = sstat.st_mtime_ns
122 + else:
123 + newmtime = sstat[stat.ST_MTIME]
124 if renamefailed:
125 - # If rename succeeded then timestamps are automatically
126 - # preserved with complete precision because the source
127 - # and destination inode are the same. Otherwise, round
128 - # down to the nearest whole second since python's float
129 - # st_mtime cannot be used to preserve the st_mtim.tv_nsec
130 - # field with complete precision. Note that we have to use
131 - # stat_obj[stat.ST_MTIME] here because the float
132 - # stat_obj.st_mtime rounds *up* sometimes.
133 - os.utime(dest, (newmtime, newmtime))
134 + if sys.hexversion >= 0x3030000:
135 + # If rename succeeded then timestamps are automatically
136 + # preserved with complete precision because the source
137 + # and destination inodes are the same. Otherwise, manually
138 + # update timestamps with nanosecond precision.
139 + os.utime(dest, ns=(newmtime, newmtime))
140 + else:
141 + # If rename succeeded then timestamps are automatically
142 + # preserved with complete precision because the source
143 + # and destination inodes are the same. Otherwise, round
144 + # down to the nearest whole second since python's float
145 + # st_mtime cannot be used to preserve the st_mtim.tv_nsec
146 + # field with complete precision. Note that we have to use
147 + # stat_obj[stat.ST_MTIME] here because the float
148 + # stat_obj.st_mtime rounds *up* sometimes.
149 + os.utime(dest, (newmtime, newmtime))
150 except OSError:
151 # The utime can fail here with EPERM even though the move succeeded.
152 # Instead of failing, use stat to return the mtime if possible.
153 try:
154 - newmtime = os.stat(dest)[stat.ST_MTIME]
155 + if sys.hexversion >= 0x3030000:
156 + newmtime = os.stat(dest).st_mtime_ns
157 + else:
158 + newmtime = os.stat(dest)[stat.ST_MTIME]
159 except OSError as e:
160 writemsg(_("!!! Failed to stat in movefile()\n"), noiselevel=-1)
161 writemsg("!!! %s\n" % dest, noiselevel=-1)