mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-22 04:56:35 +00:00
Be better about errors during the renaming process
This commit is contained in:
parent
8b611aa71b
commit
14c3b99ef1
@ -46,12 +46,18 @@ def source_pre_save(sender, instance, **kwargs):
|
|||||||
with TemporaryDirectory(suffix=('.'+new_dirpath.name), prefix='.tmp.', dir=work_directory) as tmp_dir:
|
with TemporaryDirectory(suffix=('.'+new_dirpath.name), prefix='.tmp.', dir=work_directory) as tmp_dir:
|
||||||
tmp_dirpath = Path(tmp_dir)
|
tmp_dirpath = Path(tmp_dir)
|
||||||
existed = None
|
existed = None
|
||||||
if new_dirpath.exists():
|
|
||||||
existed = new_dirpath.rename(tmp_dirpath / 'existed')
|
|
||||||
previous = existing_dirpath.rename(tmp_dirpath / 'previous')
|
previous = existing_dirpath.rename(tmp_dirpath / 'previous')
|
||||||
mkdir_p(new_dirpath.parent)
|
try:
|
||||||
previous.rename(new_dirpath)
|
if new_dirpath.exists():
|
||||||
existing_dirpath = previous = None
|
existed = new_dirpath.rename(tmp_dirpath / 'existed')
|
||||||
|
mkdir_p(new_dirpath.parent)
|
||||||
|
previous.rename(new_dirpath)
|
||||||
|
except Exception:
|
||||||
|
# try to preserve the directory, if anything went wrong
|
||||||
|
previous.rename(existing_dirpath)
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
existing_dirpath = previous = None
|
||||||
if existed and existed.is_dir():
|
if existed and existed.is_dir():
|
||||||
existed = existed.rename(new_dirpath / '.existed')
|
existed = existed.rename(new_dirpath / '.existed')
|
||||||
for entry_path in existed.iterdir():
|
for entry_path in existed.iterdir():
|
||||||
|
Loading…
Reference in New Issue
Block a user