Skip to content

Commit

Permalink
Resume download cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jake authored and jake committed Apr 11, 2024
1 parent 5d279d0 commit 6fbf40f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internetarchive/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ def download(# noqa: max-complexity=38

if not return_responses \
and not ignore_existing \
and self.name != f'{self.identifier}_files.xml' \
and os.path.exists(file_path.encode('utf-8')):
st = os.stat(file_path.encode('utf-8'))
if st.st_size != self.size and not ignore_existing:
if st.st_size != self.size and not checksum:
headers = {"Range": f"bytes={st.st_size}-{self.size}"}

response = self.item.session.get(self.url,
Expand Down Expand Up @@ -275,6 +276,7 @@ def download(# noqa: max-complexity=38
print(f' {msg}', file=sys.stderr)
return
elif not fileobj:
st = os.stat(file_path.encode('utf-8'))
if st.st_mtime == last_mod_mtime:
if self.name == f'{self.identifier}_files.xml' \
or (st.st_size == self.size):
Expand Down Expand Up @@ -327,7 +329,9 @@ def download(# noqa: max-complexity=38
except AssertionError:
msg = (f"\"{file_path}\" corrupt, "
"checksums do not match. "
"Remote file may have been modified, retry download.")
"Remote file may have been modified, "
"retry download.")
os.remove(file_path.encode('utf-8'))
raise exceptions.InvalidChecksumError(msg)
break
except (RetryError, HTTPError, ConnectTimeout, OSError, ReadTimeout,
Expand Down

0 comments on commit 6fbf40f

Please sign in to comment.