[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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user