[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:
@@ -342,15 +342,22 @@ class PathFormat():
|
|||||||
try:
|
try:
|
||||||
os.replace(self.temppath, self.realpath)
|
os.replace(self.temppath, self.realpath)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
# delayed directory creation
|
try:
|
||||||
os.makedirs(self.realdirectory)
|
# delayed directory creation
|
||||||
|
os.makedirs(self.realdirectory)
|
||||||
|
except FileExistsError:
|
||||||
|
# file at self.temppath does not exist
|
||||||
|
return False
|
||||||
continue
|
continue
|
||||||
except OSError:
|
except OSError:
|
||||||
# move across different filesystems
|
# move across different filesystems
|
||||||
try:
|
try:
|
||||||
shutil.copyfile(self.temppath, self.realpath)
|
shutil.copyfile(self.temppath, self.realpath)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
os.makedirs(self.realdirectory)
|
try:
|
||||||
|
os.makedirs(self.realdirectory)
|
||||||
|
except FileExistsError:
|
||||||
|
return False
|
||||||
shutil.copyfile(self.temppath, self.realpath)
|
shutil.copyfile(self.temppath, self.realpath)
|
||||||
os.unlink(self.temppath)
|
os.unlink(self.temppath)
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user