]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
Fix creating a repository without re-signing everything.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Dec 2012 15:12:02 +0000 (16:12 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Dec 2012 15:12:02 +0000 (16:12 +0100)
This is also intended to run fast.

python/pakfire/base.py
python/pakfire/cli.py
python/pakfire/repository/local.py

index ef63c55b3359943f8b62aea5483fcd84bee903f2..943a999d86f79f77f12cad26b9ffe646712faf0d 100644 (file)
@@ -732,10 +732,10 @@ class PakfireServer(Pakfire):
 
                # Create new repository.
                repo = repository.RepositoryDir(self, name=name, description="New repository.",
-                       path=path, type=type, key_id=key_id)
+                       path=path, key_id=key_id)
 
                # Add all packages.
-               repo.add_packages(*input_paths)
+               repo.add_packages(input_paths)
 
                # Write metadata to disk.
                repo.save()
index 81e1f566aced858ea56fa025e40ed42e98e0b1fd..615aacdba4842d3c7d7868a51cffb5c3dc81ea6b 100644 (file)
@@ -665,7 +665,7 @@ class CliServer(Cli):
                # Finally parse all arguments from the command line and save them.
                self.args = self.parser.parse_args()
 
-               self.server = server.Server(**self.pakfire_args)
+               #self.server = server.Server(**self.pakfire_args)
 
                self.action2func = {
                        "build"      : self.handle_build,
index d9a0011a6a5ae2f34744b8af72d5a3a00c377105..99def7a442daf9f9e0682810e83cdec88db250e1 100644 (file)
@@ -39,16 +39,12 @@ from pakfire.constants import *
 from pakfire.i18n import _
 
 class RepositoryDir(base.RepositoryFactory):
-       def __init__(self, pakfire, name, description, path, type="binary", key_id=None):
+       def __init__(self, pakfire, name, description, path, key_id=None):
                base.RepositoryFactory.__init__(self, pakfire, name, description)
 
                # Path to files.
                self.path = path
 
-               # Save type.
-               assert type in ("binary", "source",)
-               self.type = type
-
                # The key that is used to sign all added packages.
                self.key_id = key_id
 
@@ -115,7 +111,7 @@ class RepositoryDir(base.RepositoryFactory):
                                except:
                                        pass
 
-       def add_packages(self, files, replace=True):
+       def add_packages(self, files):
                # Search for possible package files in the paths.
                files = self.search_files(*files)
 
@@ -133,7 +129,7 @@ class RepositoryDir(base.RepositoryFactory):
                                pb.update(i)
 
                        # Add the package to the repository.
-                       self.add_package(file, replace=replace, optimize_index=False)
+                       self.add_package(file, optimize_index=False)
 
                # Optimize the index.
                self.optimize_index()
@@ -144,48 +140,49 @@ class RepositoryDir(base.RepositoryFactory):
                # Optimize the index.
                self.index.optimize()
 
-       def add_package(self, filename, replace=True, optimize_index=True):
-               # Open the package file we want to add.
-               pkg = packages.open(self.pakfire, self, filename)
+       def add_package(self, filename, optimize_index=True, check_uuids=False):
+               repo_filename = os.path.join(self.path, os.path.basename(filename))
 
-               # Find all packages with the given type and skip those of
-               # the other type.
-               if not pkg.type == self.type:
-                       return
+               # Check if the package needs to be copied.
+               needs_copy = True
 
-               # Compute the local path.
-               repo_filename = os.path.join(self.path, os.path.basename(pkg.filename))
+               if os.path.exists(repo_filename):
+                       pkg2 = packages.open(self.pakfire, self, repo_filename)
 
-               # If a file with the same name does already exists, we don't replace it.
-               if not replace and os.path.exists(repo_filename):
-                       return pkg
+                       if check_uuids:
+                               pkg1 = packages.open(self.pakfire, None, filename)
 
-               # Copy the file to the repository.
-               repo_dirname = os.path.dirname(repo_filename)
-               if not os.path.exists(repo_dirname):
-                       os.makedirs(repo_dirname)
+                               # Package file does already exist, but the UUID don't match.
+                               # Copy the package file and then re-open it.
+                               if pkg1.uuid == pkg2.uuid:
+                                       needs_copy = False
+                       else:
+                               needs_copy = False
 
-               # Try to hard link the package if possible. Otherwise copy.
-               try:
-                       os.link(pkg.filename, repo_filename)
-               except OSError:
-                       shutil.copy2(pkg.filename, repo_filename)
+               # Copy the package file
+               if needs_copy:
+                       if not os.path.exists(self.path):
+                               os.makedirs(self.path)
 
-               # Re-open the package.
-               pkg = packages.open(self.pakfire, self, repo_filename)
+                       # Copy the file.
+                       try:
+                               os.link(filename, repo_filename)
+                       except OSError:
+                               shutil.copy2(filename, repo_filename)
+
+                       # Re-open the package.
+                       pkg2 = packages.open(self.pakfire, self, repo_filename)
 
-               # Sign package.
-               if self.key_id:
-                       pkg.sign(self.key_id)
+                       # The package needs to be signed.
+                       if self.key_id:
+                               pkg2.sign(self.key_id)
 
                # Add package to the index.
-               self.index.add_package(pkg)
+               self.index.add_package(pkg2)
 
                if optimize_index:
                        self.optimize_index()
 
-               return pkg
-
        def optimize_index(self):
                """
                        Optimize the index.