Skip to content

Commit

Permalink
fix 'part-directory' (#2576)
Browse files Browse the repository at this point in the history
bug introduced in 99cb287
  • Loading branch information
mikf committed May 10, 2022
1 parent feb470d commit 9c8647a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions gallery_dl/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,18 @@ def finalize(self):

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:
Expand Down

0 comments on commit 9c8647a

Please sign in to comment.