portage.util.movefile.movefile(): Try to preserve mtime of symlinks with Python ...
authorArfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Fri, 30 Nov 2012 02:09:00 +0000 (03:09 +0100)
committerArfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Fri, 30 Nov 2012 02:09:00 +0000 (03:09 +0100)
pym/portage/util/movefile.py

index 98cf86a417ff1520cee8475e51cb71fb5e3f73b1..57375f2197ab6517fa3ab9645801882ff8006ef5 100644 (file)
@@ -162,11 +162,17 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
                                        target != os.readlink(dest):
                                        raise
                        lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
-                       # utime() only works on the target of a symlink, so it's not
-                       # possible to preserve mtime on symlinks.
                        if sys.hexversion >= 0x3030000:
-                               return os.stat(dest, follow_symlinks=False).st_mtime_ns
+                               try:
+                                       os.utime(dest, ns=(sstat.st_mtime_ns, sstat.st_mtime_ns), follow_symlinks=False)
+                               except NotImplementedError:
+                                       # utimensat() and lutimes() missing in libc.
+                                       return os.stat(dest, follow_symlinks=False).st_mtime_ns
+                               else:
+                                       return sstat.st_mtime_ns
                        else:
+                               # utime() in Python <3.3 only works on the target of a symlink, so it's not
+                               # possible to preserve mtime on symlinks.
                                return os.lstat(dest)[stat.ST_MTIME]
                except SystemExit as e:
                        raise