From: Michael Tremer Date: Fri, 18 Aug 2023 09:53:30 +0000 (+0000) Subject: packages: Fail more gracefully if a package has been deleted from disk X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b19e86e16024508a8ad8dc14a35fd1e83154a4f4;p=pbs.git packages: Fail more gracefully if a package has been deleted from disk Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index f58dc593..5c27b9ab 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -284,6 +284,10 @@ class Builds(base.Object): if not package.is_source(): raise RuntimeError("Can only build source packages, not %s" % package.arch) + # Check if the package exists + if not package.path or not await self.backend.exists(package.path): + raise RuntimeError("Package %s does not exist (path = %s)" % (package, package.path)) + build = self._get_build(""" INSERT INTO builds diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 0a812636..53249155 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -953,14 +953,18 @@ class Job(base.DataObject): # Fetch the commandline repository repo = p.get_repo("@commandline") - # Open the archive - archive = await asyncio.to_thread(p.open, self.pkg.path) - - # Fetch the package - package = archive.get_package(repo) - # Perform the installcheck try: + # Check if the source package exists + if not self.pkg.path: + raise DependencyError("Source package does not exist") + + # Open the archive + archive = await asyncio.to_thread(p.open, self.pkg.path) + + # Fetch the package + package = await asyncio.to_thread(archive.get_package, repo) + await asyncio.to_thread(package.installcheck) # Store any dependency errors diff --git a/src/buildservice/packages.py b/src/buildservice/packages.py index e2ddf02c..cdcd6f9a 100644 --- a/src/buildservice/packages.py +++ b/src/buildservice/packages.py @@ -473,16 +473,13 @@ class Package(base.DataObject): log.debug("Importing %s to %s..." % (self, path)) - # Do nothing if the file already exists - if await self.backend.exists(path): - return - - # Copy the file - await self.backend.copy(archive.path, path, mode=0o444) - # Store the path self._set_attribute("path", path) + # Copy the file if it doesn't exist, yet + if not await self.backend.exists(path): + await self.backend.copy(archive.path, path, mode=0o444) + async def _import_filelist(self, archive): log.debug("Importing filelist for %s" % self) diff --git a/src/buildservice/repository.py b/src/buildservice/repository.py index f27a4bc1..fe6cc3a9 100644 --- a/src/buildservice/repository.py +++ b/src/buildservice/repository.py @@ -943,7 +943,10 @@ class Repository(base.DataObject): packages = self.get_packages(arch) # Make filelist (if they exist) - files = [p.path for p in packages if os.path.exists(p.path)] + files = [ + p.path for p in packages \ + if p.path and await self.backend.exists(p.path) + ] # Write repository metadata await asyncio.to_thread(p.repo_compose, path=path, key=key, files=files)