From 2dce55b63fe7fb3e8b07e1163576f08da2d4f91b Mon Sep 17 00:00:00 2001 From: arkohut <39525455+arkohut@users.noreply.github.com> Date: Fri, 25 Oct 2024 12:27:08 +0800 Subject: [PATCH] fix(scan): only delete files if it is not in scanning path --- memos/cmds/library.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/memos/cmds/library.py b/memos/cmds/library.py index 800c1d5..1820a8a 100644 --- a/memos/cmds/library.py +++ b/memos/cmds/library.py @@ -395,8 +395,12 @@ def scan( path = Path(path).expanduser().resolve() # Check if the path is a folder or a subdirectory of a library folder folder = next( - (folder for folder in library_folders if path.is_relative_to(Path(folder["path"]).resolve())), - None + ( + folder + for folder in library_folders + if path.is_relative_to(Path(folder["path"]).resolve()) + ), + None, ) if not folder: print(f"Error: The path {path} is not part of any folder in the library.") @@ -450,7 +454,10 @@ def scan( pbar2.refresh() for existing_file in existing_files: - if existing_file["filepath"] not in scanned_files: + if ( + Path(existing_file["filepath"]).is_relative_to(folder_path) + and existing_file["filepath"] not in scanned_files + ): # File has been deleted delete_response = httpx.delete( f"{BASE_URL}/libraries/{library_id}/entities/{existing_file['id']}"