Skip to content

Commit

Permalink
download: now check tempfiles more carefully.
Browse files Browse the repository at this point in the history
Now that gdown handles fully transferred files properly, by
ignoring them, the tempfile finder loop should only select files
ending with the right suffix (currently “(random).part”). This
avoids common situations where gdown finds the target file
itself, then tries to update it with a zero-byte partial transfer
in “--continue” mode.

Requiring a particular suffix also helps avoid a possible source
of file corruption when folders contain a lot of similarly named
files.
  • Loading branch information
achadwick committed Feb 17, 2024
1 parent 61f8317 commit 7245742
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion gdown/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def download(
# Alternatively, resume mode can reuse partial tmp_files.
existing_tmp_files = []
for file in os.listdir(osp.dirname(output) or "."):
if file.startswith(osp.basename(output)):
if file.startswith(osp.basename(output)) and file.endswith(TEMPFILE_SUFFIX):
existing_tmp_files.append(osp.join(osp.dirname(output), file))
if resume and existing_tmp_files:
if len(existing_tmp_files) != 1:
Expand Down

0 comments on commit 7245742

Please sign in to comment.