summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-12-13 03:53:22 +0000
committerZac Medico <zmedico@gentoo.org>2009-12-13 03:53:22 +0000
commit0d5d9c1ac610993815fb58a5d78fb28616214ef6 (patch)
tree4ab393e457dff4ae984bde46a3293e95e6eb35d7 /pym
parentc170cf8bceb2d01a6c253d36dfd036f76700bbc9 (diff)
downloadportage-0d5d9c1ac610993815fb58a5d78fb28616214ef6.tar.gz
portage-0d5d9c1ac610993815fb58a5d78fb28616214ef6.tar.bz2
portage-0d5d9c1ac610993815fb58a5d78fb28616214ef6.zip
In movefile mtime rounding code, generate nanosecond resolution (9 decimal
places) in order to ensure that the floating point representation is the highest value possible without rounding up. (trunk r15046) svn path=/main/branches/2.1.7/; revision=15080
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/__init__.py36
1 files changed, 15 insertions, 21 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 9a0b7265d..82064c35f 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -7671,29 +7671,23 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
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
- digits = 0
- max_digits = 9
- while digits < max_digits:
- if int_mtime == long(float(mtime_str + "9")):
- mtime_str += "9"
- digits += 1
- else:
- if digits < max_digits:
- another_digit = None
- for i in range(1, 9):
- i_str = str(i)
- if int_mtime != \
- long(float(mtime_str + i_str)):
- break
- else:
- another_digit = i_str
- if another_digit is not None:
- mtime_str += another_digit
- digits += 1
- break
- if digits > 0:
+ nonzero_digits = 0
+ decimal_places = 9
+ for i in range(max_digits):
+ 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