Skip to content

Commit

Permalink
Comple TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
mshivashankar committed Oct 24, 2023
1 parent 9bebc08 commit 8fb0ec3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions asab/library/providers/libsreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import tarfile
import tempfile
import urllib.parse
import shutil

import aiohttp

Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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 ...
Expand Down

0 comments on commit 8fb0ec3

Please sign in to comment.