From 105c027411daec01d16a222e2e6d36a1f4d98765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 20 Jan 2025 20:50:31 +0100 Subject: [PATCH] [path] handle exception when using --rename-to --no-download (#6861) Catch a possible FileExistsError exception when attempting to create a new directory during handling of a FileNotFoundError exception. FileNotFoundError may also occur when the file at self.temppath is missing because it hasn't been downloaded due to --no-download. --- gallery_dl/path.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gallery_dl/path.py b/gallery_dl/path.py index f57b02e1..21e1aa00 100644 --- a/gallery_dl/path.py +++ b/gallery_dl/path.py @@ -342,15 +342,22 @@ class PathFormat(): try: os.replace(self.temppath, self.realpath) except FileNotFoundError: - # delayed directory creation - os.makedirs(self.realdirectory) + try: + # delayed directory creation + os.makedirs(self.realdirectory) + except FileExistsError: + # file at self.temppath does not exist + return False continue except OSError: # move across different filesystems try: shutil.copyfile(self.temppath, self.realpath) except FileNotFoundError: - os.makedirs(self.realdirectory) + try: + os.makedirs(self.realdirectory) + except FileExistsError: + return False shutil.copyfile(self.temppath, self.realpath) os.unlink(self.temppath) break