Merged from trunk 9862:9865
authorFabian Groffen <grobian@gentoo.org>
Sun, 13 Apr 2008 10:44:49 +0000 (10:44 -0000)
committerFabian Groffen <grobian@gentoo.org>
Sun, 13 Apr 2008 10:44:49 +0000 (10:44 -0000)
   | 9864    | Make movefile() tolerant to EPERM errors that can be raised  |
   | zmedico | from utime() calls. Instead of failing, use stat() to return |
   |         | the mtime if possible.                                       |

   | 9865    | Convert st_mtime to long for movefile() return type.         |
   | zmedico |                                                              |

svn path=/main/branches/prefix/; revision=9869

pym/portage/__init__.py

index ff42812611a53cdff160d1c1d302f88f23e51e01..7554b8159522301e8e3b0d05c9c24b4a0ca4afa3 100644 (file)
@@ -5262,11 +5262,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 = long(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