summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-12-10 01:05:35 +0000
committerZac Medico <zmedico@gentoo.org>2009-12-10 01:05:35 +0000
commit1342d0942648f1408f4924955818cd3b9c1f869a (patch)
tree5d33a45ba883a96fa31e22a8a531f0c1c2b0b0e2
parent83c08281872aef17ff58bfc14f7090e8beb7c38f (diff)
downloadportage-1342d0942648f1408f4924955818cd3b9c1f869a.tar.gz
portage-1342d0942648f1408f4924955818cd3b9c1f869a.tar.bz2
portage-1342d0942648f1408f4924955818cd3b9c1f869a.zip
Detect cases when long(stat_obj.st_mtime) != stat_obj[stat.ST_MTIME] due to
rounding up, and truncate digits as necessary to preserve the integral seconds portion of the mtime. (trunk r14996) svn path=/main/branches/2.1.7/; revision=15012
-rw-r--r--pym/portage/__init__.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index ba6942672..40c6127ba 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -7640,7 +7640,25 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
# If rename succeeded then this is not necessary, since
# rename automatically preserves timestamps with complete
# precision.
- os.utime(dest, (sstat.st_atime, sstat.st_mtime))
+ if sstat[stat.ST_MTIME] == long(sstat.st_mtime):
+ newmtime = sstat.st_mtime
+ else:
+ # Prevent mtime from rounding up to the next second.
+ int_mtime = sstat[stat.ST_MTIME]
+ mtime_str = "%i.9999999" % int_mtime
+ min_len = len(str(int_mtime)) + 2
+ while True:
+ mtime_str = mtime_str[:-1]
+ newmtime = float(mtime_str)
+ if int_mtime == long(newmtime):
+ break
+ elif len(mtime_str) <= min_len:
+ # This shouldn't happen, but let's make sure
+ # we can never have an infinite loop.
+ newmtime = int_mtime
+ break
+
+ os.utime(dest, (newmtime, newmtime))
newmtime = sstat[stat.ST_MTIME]
except OSError:
# The utime can fail here with EPERM even though the move succeeded.