From: Michael Tremer Date: Wed, 19 Oct 2022 14:17:13 +0000 (+0000) Subject: backend: Add function to create parent directories X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da59fff3ff037bcef256263aba1a4f5a19fe8738;p=pbs.git backend: Add function to create parent directories Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/__init__.py b/src/buildservice/__init__.py index c2b76f17..52d01aa2 100644 --- a/src/buildservice/__init__.py +++ b/src/buildservice/__init__.py @@ -239,7 +239,17 @@ class Backend(object): """ log.debug("Copying %s to %s" % (src, dst)) - path = os.path.dirname(dst) + # Create parent directory + await self.make_parent_directory(dst) + + # Copy data without any metadata + await asyncio.to_thread(shutil.copyfile, src, dst) + + async def make_parent_directory(self, path): + """ + Creates the parent directory of path + """ + path = os.path.dirname(path) # Create destination path (if it does not exist) try: @@ -247,9 +257,6 @@ class Backend(object): except FileExistsError: pass - # Copy data without any metadata - await asyncio.to_thread(shutil.copyfile, src, dst) - async def unlink(self, path): """ Unlinks path