From c4bdbe2ec9fec9e3eefe0d0c55fc386427237254 Mon Sep 17 00:00:00 2001 From: Go1c <1c@live.cn> Date: Tue, 14 Apr 2026 15:51:27 +0800 Subject: [PATCH] fix: recursively remove empty parent dirs after file delete _try_remove_empty_parent previously only checked one level up, leaving ancestor directories (e.g. diagrams/, notes/) as empty shells after all their contents were deleted via pull sync. Now walks up the tree until vault_path, removing each empty directory in turn. --- fns_cli/file_sync.py | 14 +++++++++----- fns_cli/note_sync.py | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/fns_cli/file_sync.py b/fns_cli/file_sync.py index 086fcae..a7cee47 100644 --- a/fns_cli/file_sync.py +++ b/fns_cli/file_sync.py @@ -382,8 +382,12 @@ def _collect_local_files(self) -> list[dict]: def _try_remove_empty_parent(self, file_path: Path) -> None: parent = file_path.parent - try: - if parent != self.vault_path and parent.exists() and not any(parent.iterdir()): - parent.rmdir() - except OSError: - pass + while parent != self.vault_path: + try: + if parent.exists() and not any(parent.iterdir()): + parent.rmdir() + else: + break + except OSError: + break + parent = parent.parent diff --git a/fns_cli/note_sync.py b/fns_cli/note_sync.py index 3640111..6a63f8a 100644 --- a/fns_cli/note_sync.py +++ b/fns_cli/note_sync.py @@ -244,11 +244,15 @@ def _check_all_received(self) -> None: def _try_remove_empty_parent(self, file_path: Path) -> None: parent = file_path.parent - try: - if parent != self.vault_path and parent.exists() and not any(parent.iterdir()): - parent.rmdir() - except OSError: - pass + while parent != self.vault_path: + try: + if parent.exists() and not any(parent.iterdir()): + parent.rmdir() + else: + break + except OSError: + break + parent = parent.parent def _collect_local_notes(self) -> list[dict]: notes = []