From e0a961047ce64f1478e4e72bdacf91d67a8329ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 12 Jun 2025 16:44:41 +0200 Subject: [PATCH] [dl:http] fix potential FileExistsError when '.part' file moved (#5385) when the downloader detects a '.part' file and attempts to resume its download, a FileExistsError was raised while trying to create an assumed missing directory path when said '.part' file was (re)moved during the time it was detected and the downloader attempted to open it in 'a+b' mode. --- gallery_dl/downloader/http.py | 3 +++ gallery_dl/path.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/gallery_dl/downloader/http.py b/gallery_dl/downloader/http.py index 101baced..87ca71ba 100644 --- a/gallery_dl/downloader/http.py +++ b/gallery_dl/downloader/http.py @@ -308,6 +308,9 @@ class HttpDownloader(DownloaderBase): # download content self.downloading = True with pathfmt.open(mode) as fp: + if fp is None: + # '.part' file no longer exists + break if file_header: fp.write(file_header) offset += len(file_header) diff --git a/gallery_dl/path.py b/gallery_dl/path.py index 1404b847..ff0c9649 100644 --- a/gallery_dl/path.py +++ b/gallery_dl/path.py @@ -171,6 +171,9 @@ class PathFormat(): try: return open(self.temppath, mode) except FileNotFoundError: + if "r" in mode: + # '.part' file no longer exists + return util.NullContext() os.makedirs(self.realdirectory) return open(self.temppath, mode)