From: Michael Tremer Date: Mon, 18 Jul 2022 14:22:30 +0000 (+0000) Subject: packages: Use async copy when importing archives X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0550b3c4e518ea4caf9216d1606c16301ec1c51f;p=pbs.git packages: Use async copy when importing archives Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index b9eb58c8..e15ca870 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -168,7 +168,7 @@ class Builds(base.Object): return build - def create_from_source_package(self, filename, distro, commit=None, type="release", + async def create_from_source_package(self, filename, distro, commit=None, type="release", arches=None, check_for_duplicates=True, owner=None): assert distro @@ -181,7 +181,7 @@ class Builds(base.Object): return # Open the package and add it to the database - pkg = self.backend.packages.create(filename) + pkg = await self.backend.packages.create(filename) # Associate the package to the processed commit if commit: diff --git a/src/buildservice/packages.py b/src/buildservice/packages.py index e1a53a9b..a24720af 100644 --- a/src/buildservice/packages.py +++ b/src/buildservice/packages.py @@ -76,7 +76,7 @@ class Packages(base.Object): uuid, ) - def create(self, archive): + async def create(self, archive): # Extract package metadata from archive package = archive.get_package() @@ -151,7 +151,7 @@ class Packages(base.Object): pkg._import_filelist(archive.filelist) # Import package data - pkg._import_archive(archive) + await pkg._import_archive(archive) # Refresh the search index self.refresh_search_index() @@ -353,30 +353,23 @@ class Package(base.DataObject): def filesize(self): return self.data.filesize - def _import_archive(self, archive): + async def _import_archive(self, archive): """ Imports the package into the filesystem """ - # Create path to directory + # Determine the new path path = os.path.join( PACKAGES_DIR, self.uuid[0:2], self.uuid[2:4], self.uuid[4:], + "%s.pfm" % self.nevra, ) - # Create directory - os.makedirs(path) - - # Append package name to path - path = os.path.join(path, "%s.pfm" % self.nevra) - log.debug("Importing %s to %s..." % (self, path)) # Copy the file - shutil.copyfile(archive.path, path) - - # XXX use async copy here + await self.backend.copy(archive.path, path) # Store the path self._set_attribute("path", path) diff --git a/src/hub/builds.py b/src/hub/builds.py index 04551032..25cf8bbf 100644 --- a/src/hub/builds.py +++ b/src/hub/builds.py @@ -53,7 +53,7 @@ class CreateHandler(BaseHandler): repo = self.backend.repos.get_by_id(1) # Import the package - package = self.backend.packages.create(archive) + package = await self.backend.packages.create(archive) # Create a new build build = self.backend.builds.create(repo, package)