From 8fb0ec39e0956ceba7b5897155d0c9c3c872537b Mon Sep 17 00:00:00 2001 From: mshivashankar Date: Tue, 24 Oct 2023 07:29:40 +0200 Subject: [PATCH] Comple TODOs --- asab/library/providers/libsreg.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/asab/library/providers/libsreg.py b/asab/library/providers/libsreg.py index 691498bc6..9578630f9 100644 --- a/asab/library/providers/libsreg.py +++ b/asab/library/providers/libsreg.py @@ -5,6 +5,7 @@ import tarfile import tempfile import urllib.parse +import shutil import aiohttp @@ -110,7 +111,7 @@ async def _periodic_pull(self, event_name): # Download new version newtarfname = os.path.join(self.RootPath, "new.tar.xz") - with open(fname, 'wb') as ftmp: + with open(newtarfname, 'wb') as ftmp: while True: chunk = await response.content.read(16 * 1024) if not chunk: @@ -122,6 +123,11 @@ async def _periodic_pull(self, event_name): self.RootPath, "new" ) + + # Remove temp_extract_dir if it exists (from the last, failed run) + if os.path.exists(temp_extract_dir): + shutil.rmtree(temp_extract_dir) + # TODO: Remove temp_extract_dir if exists (from last, failed run) with tarfile.open(newtarfname, mode='r:xz') as tar: tar.extractall(temp_extract_dir) @@ -132,8 +138,13 @@ async def _periodic_pull(self, event_name): with open(etag_fname, 'w') as f: f.write(etag_incoming) - # TODO: Remove temp_extract_dir - # TODO: Remove newtarfname + # Remove temp_extract_dir + if os.path.exists(temp_extract_dir): + shutil.rmtree(temp_extract_dir) + + # Remove newtarfname + if os.path.exists(newtarfname): + os.remove(newtarfname) elif response.status == 304: # The repository has not changed ...