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 = []