From eb3e4b15eed241ae133d1bbd38718ac718056ad7 Mon Sep 17 00:00:00 2001 From: Helmut Date: Sat, 13 Jun 2026 22:00:32 +0200 Subject: [PATCH] fix(ytdl): skip file deletion for cleared downloads with no filename When DELETE_FILE_ON_TRASHCAN is enabled and a download that never produced a file is cleared, dl.info.filename is unset, so os.remove(...) raises AttributeError. It is caught and logged as a misleading 'deleting file ... failed' warning even though there is nothing on disk to remove. Guard with getattr and skip deletion when there is no filename. --- app/ytdl.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/ytdl.py b/app/ytdl.py index 31bca5e..20e36b2 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -1387,11 +1387,18 @@ class DownloadQueue: continue if self.config.DELETE_FILE_ON_TRASHCAN: dl = self.done.get(id) - try: - dldirectory, _ = self.__calc_download_path(dl.info.download_type, dl.info.folder) - os.remove(os.path.join(dldirectory, dl.info.filename)) - except Exception as e: - log.warning(f'deleting file for download {id} failed with error message {e!r}') + # `filename` is only set once a download has produced a file; a + # download that errored (or was cleared) before that point never + # gets one. Skip deletion instead of dereferencing a missing + # attribute, which otherwise logs a misleading + # "deleting file ... failed: AttributeError" warning. + filename = getattr(dl.info, 'filename', None) + if filename: + try: + dldirectory, _ = self.__calc_download_path(dl.info.download_type, dl.info.folder) + os.remove(os.path.join(dldirectory, filename)) + except Exception as e: + log.warning(f'deleting file for download {id} failed with error message {e!r}') self.done.delete(id) await self.notifier.cleared(id) return {'status': 'ok'}