[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.
This commit is contained in:
Mike Fährmann
2025-01-20 20:50:31 +01:00
parent 05fa6dd354
commit 105c027411

View File

@@ -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