From 2729696362739e59dd5d99acc5731f26d7c8fb4e Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 21 Dec 2012 16:12:02 +0100 Subject: [PATCH] Fix creating a repository without re-signing everything. This is also intended to run fast. --- python/pakfire/base.py | 4 +- python/pakfire/cli.py | 2 +- python/pakfire/repository/local.py | 69 ++++++++++++++---------------- 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/python/pakfire/base.py b/python/pakfire/base.py index ef63c55b3..943a999d8 100644 --- a/python/pakfire/base.py +++ b/python/pakfire/base.py @@ -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() diff --git a/python/pakfire/cli.py b/python/pakfire/cli.py index 81e1f566a..615aacdba 100644 --- a/python/pakfire/cli.py +++ b/python/pakfire/cli.py @@ -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, diff --git a/python/pakfire/repository/local.py b/python/pakfire/repository/local.py index d9a0011a6..99def7a44 100644 --- a/python/pakfire/repository/local.py +++ b/python/pakfire/repository/local.py @@ -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. -- 2.39.5