]> arthur.barton.de Git - bup.git/commitdiff
metadata.py: be careful with the umask() when restoring symlinks.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 20 Mar 2011 10:45:32 +0000 (03:45 -0700)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 20 Mar 2011 10:56:08 +0000 (03:56 -0700)
On MacOS, the umask affects symlink permissions, although not in any sort of
useful way that I can see.  Still, getting the permissions wrong breaks the
unit tests, so let's be careful about it.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/metadata.py

index 5c4a6900d4fdf70510dca8410d3295f176611354..6dae38b83bc08404b5952ce87e2d5c85c150ecb8 100644 (file)
@@ -271,7 +271,14 @@ class Metadata:
             os.mknod(path, 0600 | stat.S_IFIFO)
         elif stat.S_ISLNK(self.mode):
             if self.symlink_target and create_symlinks:
-                os.symlink(self.symlink_target, path)
+                # on MacOS, symlink() permissions depend on umask, and there's no
+                # way to chown a symlink after creating it, so we have to
+                # be careful here!
+                oldumask = os.umask((self.mode & 0777) ^ 0777)
+                try:
+                    os.symlink(self.symlink_target, path)
+                finally:
+                    os.umask(oldumask)
         # FIXME: S_ISDOOR, S_IFMPB, S_IFCMP, S_IFNWK, ... see stat(2).
         # Otherwise, do nothing.