summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/__init__.py38
1 files changed, 9 insertions, 29 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index d3081373e..8b5e89bb7 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -7657,37 +7657,17 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
if newmtime is not None:
os.utime(dest, (newmtime, newmtime))
else:
+ newmtime = sstat[stat.ST_MTIME]
if renamefailed:
- # If rename succeeded then this is not necessary, since
- # rename automatically preserves timestamps with complete
- # precision.
- if sstat[stat.ST_MTIME] == long(sstat.st_mtime):
- newmtime = sstat.st_mtime
- else:
- # Prevent mtime from rounding up to the next second.
- # Generate nanosecond resolution (9 decimal places) in
- # order to ensure that the floating point representation
- # is the highest value possible without rounding up.
- int_mtime = sstat[stat.ST_MTIME]
- mtime_str = "%i." % int_mtime
- nonzero_digits = 0
- decimal_places = 9
- for i in range(decimal_places):
- for digit in range(9, -1, -1):
- digit_str = str(digit)
- if int_mtime == long(float(mtime_str + digit_str)):
- break
- if digit > 0:
- nonzero_digits += 1
- mtime_str += digit_str
-
- if nonzero_digits > 0:
- newmtime = float(mtime_str)
- else:
- newmtime = int_mtime
-
+ # If rename succeeded then timestamps are automatically
+ # preserved with complete precision because the source
+ # and destination inode are the same. Otherwise, round
+ # down to the nearest whole second since python's float
+ # st_mtime cannot be used to preserve the st_mtim.tv_nsec
+ # field with complete precision. Note that we have to use
+ # stat_obj[stat.ST_MTIME] here because the float
+ # stat_obj.st_mtime rounds *up* sometimes.
os.utime(dest, (newmtime, newmtime))
- newmtime = sstat[stat.ST_MTIME]
except OSError:
# The utime can fail here with EPERM even though the move succeeded.
# Instead of failing, use stat to return the mtime if possible.