]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/fstransactions.py
Add by-hash support
[dak.git] / daklib / fstransactions.py
index 8fb737674fecb30a9bb4d43e3d4433543399b857..eb4874a1083ef083781270480165a77dfb1e975a 100644 (file)
@@ -38,10 +38,19 @@ class _FilesystemCopyAction(_FilesystemAction):
         self.destination = destination
         self.need_cleanup = False
 
+        dirmode = 0o2755
+        if mode is not None:
+            dirmode = 0o2700 | mode
+            # Allow +x for group and others if they have +r.
+            if dirmode & 0o0040:
+                dirmode = dirmode | 0o0010
+            if dirmode & 0o0004:
+                dirmode = dirmode | 0o0001
+
         self.check_for_temporary()
         destdir = os.path.dirname(self.destination)
         if not os.path.exists(destdir):
-            os.makedirs(destdir, 0o2775)
+            os.makedirs(destdir, dirmode)
         if symlink:
             os.symlink(source, self.destination)
         elif link:
@@ -113,53 +122,66 @@ class FilesystemTransaction(object):
     def __init__(self):
         self.actions = []
 
-    def copy(self, source, destination, link=True, symlink=False, mode=None):
-        """copy `source` to `destination`
+    def copy(self, source, destination, link=False, symlink=False, mode=None):
+        """copy C{source} to C{destination}
+
+        @type  source: str
+        @param source: source file
+
+        @type  destination: str
+        @param destination: destination file
 
-        Args:
-           source (str): source file
-           destination (str): destination file
+        @type  link: bool
+        @param link: try hardlinking, falling back to copying
 
-        Kwargs:
-           link (bool): Try hardlinking, falling back to copying.
-           symlink (bool): Create a symlink instead
-           mode (int): Permissions to change `destination` to.
+        @type  symlink: bool
+        @param symlink: create a symlink instead of copying
+
+        @type  mode: int
+        @param mode: permissions to change C{destination} to
         """
+        if isinstance(mode, str) or isinstance(mode, unicode):
+            mode = int(mode, 8)
+
         self.actions.append(_FilesystemCopyAction(source, destination, link=link, symlink=symlink, mode=mode))
 
     def move(self, source, destination, mode=None):
-        """move `source` to `destination`
+        """move C{source} to C{destination}
 
-        Args:
-           source (str): source file
-           destination (str): destination file
+        @type  source: str
+        @param source: source file
 
-        Kwargs:
-           mode (int): Permissions to change `destination` to.
+        @type  destination: str
+        @param destination: destination file
+
+        @type  mode: int
+        @param mode: permissions to change C{destination} to
         """
         self.copy(source, destination, link=True, mode=mode)
         self.unlink(source)
 
     def unlink(self, path):
-        """unlink `path`
+        """unlink C{path}
 
-        Args:
-           path (str): file to unlink
+        @type  path: str
+        @param path: file to unlink
         """
         self.actions.append(_FilesystemUnlinkAction(path))
 
     def create(self, path, mode=None):
-        """create `filename` and return file handle
+        """create C{filename} and return file handle
 
-        Args:
-           filename (str): file to create
+        @type  filename: str
+        @param filename: file to create
 
-        Kwargs:
-           mode (int): Permissions for the new file
+        @type  mode: int
+        @param mode: permissions for the new file
 
-        Returns:
-           file handle of the new file
+        @return: file handle of the new file
         """
+        if isinstance(mode, str) or isinstance(mode, unicode):
+            mode = int(mode, 8)
+
         destdir = os.path.dirname(path)
         if not os.path.exists(destdir):
             os.makedirs(destdir, 0o2775)