From b51b6c42d25c16bdaf8c722e21dd65090a29bc57 Mon Sep 17 00:00:00 2001 From: Andrew Chadwick <61299+achadwick@users.noreply.github.com> Date: Sat, 17 Feb 2024 00:05:13 +0000 Subject: [PATCH] download: now check tempfiles more carefully. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- gdown/download.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdown/download.py b/gdown/download.py index 281ae28..e57c9eb 100644 --- a/gdown/download.py +++ b/gdown/download.py @@ -310,7 +310,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: