From 3bd598792a7f4c8aac8b7b40b6c4ffb1fcf4860a Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 12 Dec 2009 18:37:41 +0000 Subject: In movefile mtime preservation code, simply round down to the nearest whole second since python's float cannot 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. svn path=/main/trunk/; revision=15054 --- pym/portage/__init__.py | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 5be9a50d3..69533c7c0 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. -- cgit v1.2.3-1-g7c22