From 9c8647a4fd83eeec181aa705ed1cf9b31ea595a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 10 May 2022 15:55:39 +0200 Subject: [PATCH] fix 'part-directory' (#2576) bug introduced in 99cb2872 --- gallery_dl/path.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gallery_dl/path.py b/gallery_dl/path.py index 4d76863d..c34b8cd1 100644 --- a/gallery_dl/path.py +++ b/gallery_dl/path.py @@ -317,11 +317,18 @@ class PathFormat(): if self.temppath != self.realpath: # Move temp file to its actual location - try: - os.replace(self.temppath, self.realpath) - except OSError: - shutil.copyfile(self.temppath, self.realpath) - os.unlink(self.temppath) + while True: + try: + os.replace(self.temppath, self.realpath) + except FileNotFoundError: + # delayed directory creation + os.makedirs(self.realdirectory, exist_ok=True) + continue + except OSError: + # move across different filesystems + shutil.copyfile(self.temppath, self.realpath) + os.unlink(self.temppath) + break mtime = self.kwdict.get("_mtime") if mtime: