Skip to content

Commit

Permalink
Reset size and digests when retrying downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellweg committed Jan 20, 2022
1 parent d23a1d6 commit b78d4e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/2078.bugfix
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Fixed downloader retry logic with partially written files.
Fixed validation logic in HttpDownloader for retries with partially downloaded files.
6 changes: 3 additions & 3 deletions pulpcore/download/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(
self.semaphore = semaphore
else:
self.semaphore = asyncio.Semaphore() # This will always be acquired
self._digests = {n: pulp_hashlib.new(n) for n in Artifact.DIGEST_FIELDS}
self._digests = {}
self._size = 0
if self.expected_digests:
if not set(self.expected_digests).intersection(set(Artifact.DIGEST_FIELDS)):
Expand All @@ -124,6 +124,8 @@ def _ensure_writer_has_open_file(self):
if not self._writer:
self._writer = tempfile.NamedTemporaryFile(dir=os.getcwd(), delete=False)
self.path = self._writer.name
self._digests = {n: pulp_hashlib.new(n) for n in Artifact.DIGEST_FIELDS}
self._size = 0

async def handle_data(self, data):
"""
Expand Down Expand Up @@ -157,8 +159,6 @@ async def finalize(self):
:meth:`~pulpcore.plugin.download.BaseDownloader.handle_data`.
"""
self._ensure_writer_has_open_file()
self._writer.flush()
os.fsync(self._writer.fileno())
self._writer.close()
self._writer = None
self.validate_digests()
Expand Down

0 comments on commit b78d4e0

Please sign in to comment.