mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Explain output dir decisions and steps
This commit is contained in:
parent
d8f26a789e
commit
245c9c3dcc
@ -174,9 +174,12 @@ class OutputDirectory:
|
|||||||
# since we know that the remote is different from the local files. This
|
# since we know that the remote is different from the local files. This
|
||||||
# includes the case where no local file exists.
|
# includes the case where no local file exists.
|
||||||
if not local_path.is_file():
|
if not local_path.is_file():
|
||||||
|
log.explain("No corresponding file present locally")
|
||||||
# TODO Don't download if on_conflict is LOCAL_FIRST or NO_DELETE
|
# TODO Don't download if on_conflict is LOCAL_FIRST or NO_DELETE
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
log.explain(f"Redownload policy is {redownload.value}")
|
||||||
|
|
||||||
if redownload == Redownload.NEVER:
|
if redownload == Redownload.NEVER:
|
||||||
return False
|
return False
|
||||||
elif redownload == Redownload.ALWAYS:
|
elif redownload == Redownload.ALWAYS:
|
||||||
@ -187,6 +190,10 @@ class OutputDirectory:
|
|||||||
remote_newer = None
|
remote_newer = None
|
||||||
if mtime := heuristics.mtime:
|
if mtime := heuristics.mtime:
|
||||||
remote_newer = mtime.timestamp() > stat.st_mtime
|
remote_newer = mtime.timestamp() > stat.st_mtime
|
||||||
|
if remote_newer:
|
||||||
|
log.explain("Remote file seems to be newer")
|
||||||
|
else:
|
||||||
|
log.explain("Local file seems to be newer")
|
||||||
|
|
||||||
if redownload == Redownload.NEVER_SMART:
|
if redownload == Redownload.NEVER_SMART:
|
||||||
if remote_newer is None:
|
if remote_newer is None:
|
||||||
@ -332,19 +339,25 @@ class OutputDirectory:
|
|||||||
|
|
||||||
# Detect and solve local-dir-remote-file conflict
|
# Detect and solve local-dir-remote-file conflict
|
||||||
if local_path.is_dir():
|
if local_path.is_dir():
|
||||||
|
log.explain("Conflict: There's a dir in place of the local file")
|
||||||
if await self._conflict_ldrf(on_conflict, path):
|
if await self._conflict_ldrf(on_conflict, path):
|
||||||
|
log.explain("Result: Delete the dir")
|
||||||
shutil.rmtree(local_path)
|
shutil.rmtree(local_path)
|
||||||
else:
|
else:
|
||||||
|
log.explain("Result: Keep the dir")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Detect and solve local-file-remote-dir conflict
|
# Detect and solve local-file-remote-dir conflict
|
||||||
for parent in path.parents:
|
for parent in path.parents:
|
||||||
local_parent = self.resolve(parent)
|
local_parent = self.resolve(parent)
|
||||||
if local_parent.exists() and not local_parent.is_dir():
|
if local_parent.exists() and not local_parent.is_dir():
|
||||||
|
log.explain("Conflict: One of the local file's parents is a file")
|
||||||
if await self._conflict_lfrd(on_conflict, path, parent):
|
if await self._conflict_lfrd(on_conflict, path, parent):
|
||||||
|
log.explain("Result: Delete the obstructing file")
|
||||||
local_parent.unlink()
|
local_parent.unlink()
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
log.explain("Result: Keep the obstructing file")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Ensure parent directory exists
|
# Ensure parent directory exists
|
||||||
@ -366,9 +379,12 @@ class OutputDirectory:
|
|||||||
|
|
||||||
async def _after_download(self, info: DownloadInfo) -> None:
|
async def _after_download(self, info: DownloadInfo) -> None:
|
||||||
with self._ensure_deleted(info.tmp_path):
|
with self._ensure_deleted(info.tmp_path):
|
||||||
|
log.explain_topic(f"Processing downloaded file for {fmt_path(info.path)}")
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
if not info.success:
|
if not info.success:
|
||||||
|
log.explain("Download unsuccessful, aborting")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Solve conflicts arising from existing local file
|
# Solve conflicts arising from existing local file
|
||||||
@ -376,13 +392,21 @@ class OutputDirectory:
|
|||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if filecmp.cmp(info.local_path, info.tmp_path):
|
if filecmp.cmp(info.local_path, info.tmp_path):
|
||||||
|
log.explain("Contents identical with existing file")
|
||||||
|
log.explain("Updating metadata on existing file instead")
|
||||||
self._update_metadata(info)
|
self._update_metadata(info)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not await self._conflict_lfrf(info.on_conflict, info.path):
|
log.explain("Conflict: The local and remote versions differ")
|
||||||
|
if await self._conflict_lfrf(info.on_conflict, info.path):
|
||||||
|
log.explain("Result: Keeping the remote version")
|
||||||
|
else:
|
||||||
|
log.explain("Result: Keeping the local version")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
log.explain("Replacing local file with temporary file")
|
||||||
info.tmp_path.replace(info.local_path)
|
info.tmp_path.replace(info.local_path)
|
||||||
|
log.explain("Updating metadata on local file")
|
||||||
self._update_metadata(info)
|
self._update_metadata(info)
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
|
Loading…
Reference in New Issue
Block a user