]> git.decadent.org.uk Git - dak.git/commitdiff
HashedFile: Allow to use a different filename for input
authorAnsgar Burchardt <ansgar@debian.org>
Wed, 12 Aug 2015 13:30:03 +0000 (15:30 +0200)
committerAnsgar Burchardt <ansgar@debian.org>
Thu, 13 Aug 2015 09:44:36 +0000 (11:44 +0200)
This allows retrieving files using a temporary name, but to install
them into the archive using their proper name.

daklib/archive.py
daklib/upload.py

index 3b55b3f79092fe55429e0bc599a0a77822b29474..0891922df1dbe02a3ace550379bc930152659cc3 100644 (file)
@@ -110,7 +110,7 @@ class ArchiveTransaction(object):
             session.flush()
 
             path = os.path.join(archive.path, 'pool', component.component_name, poolname)
-            hashed_file_path = os.path.join(directory, hashed_file.filename)
+            hashed_file_path = os.path.join(directory, hashed_file.input_filename)
             self.fs.copy(hashed_file_path, path, link=False, mode=archive.mode)
 
         return poolfile
index 2cc70743baba35a3f7ca21da660ee48d225946cd..b78d100fe55c5e59d48f03338a9ec11a9a0edff9 100644 (file)
@@ -73,12 +73,21 @@ class FileDoesNotExist(UploadException):
 class HashedFile(object):
     """file with checksums
     """
-    def __init__(self, filename, size, md5sum, sha1sum, sha256sum, section=None, priority=None):
+    def __init__(self, filename, size, md5sum, sha1sum, sha256sum, section=None, priority=None, input_filename=None):
         self.filename = filename
         """name of the file
         @type: str
         """
 
+        if input_filename is None:
+            input_filename = filename
+        self.input_filename = input_filename
+        """name of the file on disk
+
+        Used for temporary files that should not be installed using their on-disk name.
+        @type: str
+        """
+
         self.size = size
         """size in bytes
         @type: long
@@ -146,13 +155,13 @@ class HashedFile(object):
 
         @raise InvalidHashException: hash mismatch
         """
-        path = os.path.join(directory, self.filename)
+        path = os.path.join(directory, self.input_filename)
         try:
             with open(path) as fh:
                 self.check_fh(fh)
         except IOError as e:
             if e.errno == errno.ENOENT:
-                raise FileDoesNotExist(self.filename)
+                raise FileDoesNotExist(self.input_filename)
             raise
 
     def check_fh(self, fh):
@@ -445,7 +454,7 @@ class Binary(object):
         @type: HashedFile
         """
 
-        path = os.path.join(directory, hashed_file.filename)
+        path = os.path.join(directory, hashed_file.input_filename)
         data = apt_inst.DebFile(path).control.extractdata("control")
 
         self.control = apt_pkg.TagSection(data)
@@ -518,7 +527,7 @@ class Source(object):
         # make sure the hash for the dsc is valid before we use it
         self._dsc_file.check(directory)
 
-        dsc_file_path = os.path.join(directory, self._dsc_file.filename)
+        dsc_file_path = os.path.join(directory, self._dsc_file.input_filename)
         data = open(dsc_file_path, 'r').read()
         self._signed_file = SignedFile(data, keyrings, require_signature)
         self.dsc = apt_pkg.TagSection(self._signed_file.contents)