Make movefile() tolerant to EPERM errors that can be raised from utime()
authorZac Medico <zmedico@gentoo.org>
Sun, 13 Apr 2008 07:32:46 +0000 (07:32 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 13 Apr 2008 07:32:46 +0000 (07:32 -0000)
calls. Instead of failing, use stat() to return the mtime if possible.

svn path=/main/trunk/; revision=9864

pym/portage/__init__.py

index 92cacf76ee7db8afc9b14f71c25c1bc7e690b296..6a6d088d76a47ce7fbbafacba1a170212772d565 100644 (file)
@@ -5211,11 +5211,22 @@ def movefile(src,dest,newmtime=None,sstat=None,mysettings=None):
                        print "!!!",e
                        return None
 
-       if newmtime:
-               os.utime(dest,(newmtime,newmtime))
-       else:
-               os.utime(dest, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME]))
-               newmtime=sstat[stat.ST_MTIME]
+       try:
+               if newmtime is not None:
+                       os.utime(dest, (newmtime, newmtime))
+               else:
+                       os.utime(dest, (sstat.st_atime, sstat.st_mtime))
+                       newmtime = long(sstat.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.
+               try:
+                       newmtime = os.stat(dest).st_mtime
+               except OSError, e:
+                       writemsg("!!! Failed to stat in movefile()\n", noiselevel=-1)
+                       writemsg("!!! %s\n" % dest, noiselevel=-1)
+                       writemsg("!!! %s\n" % str(e), noiselevel=-1)
+                       return None
 
        if bsd_chflags:
                # Restore the flags we saved before moving