Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions PFERD/output_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,13 @@ async def _cleanup(self, path: Path, pure: PurePath) -> None:
await self._cleanup_file(path, pure)

async def _cleanup_dir(self, path: Path, pure: PurePath, delete_self: bool = True) -> None:
if self._on_conflict in {
OnConflict.NO_DELETE,
OnConflict.NO_DELETE_PROMPT_OVERWRITE,
} and not self.report.contains_marked(pure):
self._report_not_deleted(pure)
return

for child in sorted(path.iterdir()):
pure_child = pure / child.name
await self._cleanup(child, pure_child)
Expand All @@ -551,8 +558,11 @@ async def _cleanup_file(self, path: Path, pure: PurePath) -> None:
except OSError:
pass
else:
log.not_deleted("[bold bright_magenta]", "Not deleted", fmt_path(pure))
self._report.not_delete_file(pure)
self._report_not_deleted(pure)

def _report_not_deleted(self, path: PurePath) -> None:
log.not_deleted("[bold bright_magenta]", "Not deleted", fmt_path(path))
self._report.not_delete_file(path)

def load_prev_report(self) -> None:
log.explain_topic(f"Loading previous report from {fmt_real_path(self._report_path)}")
Expand Down
3 changes: 3 additions & 0 deletions PFERD/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def marked(self) -> set[PurePath]:
def is_marked(self, path: PurePath) -> bool:
return path in self.marked

def contains_marked(self, path: PurePath) -> bool:
return any(marked_file.is_relative_to(path) for marked_file in self.marked)

def add_file(self, path: PurePath) -> None:
"""
Unlike mark(), this function accepts any paths.
Expand Down
Loading