fix(tracks): keep a locked segment file from hiding the download error

On Windows a worker can still hold a .!dev file open when a track fails; cleanup now ignores that OSError and still stashes the segments.
This commit is contained in:
imSp4rky
2026-10-21 18:25:50 -06:00
parent 5086dafff3
commit a7e68b7d20
2 changed files with 56 additions and 13 deletions
+14 -9
View File
@@ -1,4 +1,5 @@
import base64
import contextlib
import html
import logging
import re
@@ -768,6 +769,17 @@ class Track:
shutil.rmtree(save_dir)
resume.clear_sidecar(save_dir)
def abandon() -> None:
"""Clean up a failed or cancelled download and stash its segments when resume is on.
The downloader does not wait for its workers on failure, so on Windows one can still hold a
.!dev file open (WinError 32). A cleanup error must not replace the download's own error.
"""
with contextlib.suppress(OSError):
cleanup()
if keep_segments:
stash_segments(save_dir)
if not DOWNLOAD_LICENCE_ONLY.is_set():
if config.directories.temp.is_file():
raise ValueError(f"Temp Directory '{config.directories.temp}' must be a Directory, not a file")
@@ -927,19 +939,12 @@ class Track:
progress(downloaded="[red]FAILED")
raise
except DownloadCancelled:
try:
cleanup()
if keep_segments:
stash_segments(save_dir)
except OSError:
pass
abandon()
progress(downloaded="[yellow]SKIPPED")
return
except (Exception, KeyboardInterrupt):
if not DOWNLOAD_LICENCE_ONLY.is_set():
cleanup()
if keep_segments:
stash_segments(save_dir)
abandon()
raise
if DOWNLOAD_CANCELLED.is_set():