Skip to content

Commit cc92ff8

Browse files
wei1710mirkobrombin
authored andcommitted
manager: fix crash when encountering 0-byte ghost files
Force re-download if a temp file is empty, resolving issue #4418.
1 parent d8a7a21 commit cc92ff8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

bottles/backend/managers/component.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,21 @@ def download(
165165
temp_dest = os.path.join(Paths.temp, file)
166166
just_downloaded = False
167167

168-
if os.path.isfile(os.path.join(Paths.temp, existing_file)):
168+
file_path = os.path.join(Paths.temp, existing_file)
169+
if os.path.isfile(file_path):
169170
"""
170171
Check if the file already exists in the /temp directory.
171-
If so, then skip the download process and set the update_func
172-
to completed.
172+
If it's a 0-byte empty file, remove it to allow a fresh download.
173+
Otherwise, skip the download.
173174
"""
174-
logging.warning(f"File [{existing_file}] already exists in temp, skipping.")
175-
else:
175+
if os.path.getsize(file_path) == 0:
176+
logging.warning(f"File [{existing_file}] is a 0-byte empty file. Removing to force re-download.")
177+
os.remove(file_path)
178+
else:
179+
logging.warning(f"File [{existing_file}] already exists in temp, skipping.")
180+
return Result(True)
181+
182+
if not os.path.isfile(file_path):
176183
"""
177184
As some urls can be redirect, we need to take care of this
178185
and make sure to use the final url. This check should be

0 commit comments

Comments
 (0)