From c9d61b5e237095519ebd064bbf4da8bf828d4b72 Mon Sep 17 00:00:00 2001 From: yedpodtrzitko Date: Wed, 11 Sep 2024 13:31:22 +0700 Subject: [PATCH] undo the extension check in refresh_dir --- tagstudio/src/core/utils/refresh_dir.py | 27 ++++------------------ tagstudio/tests/macros/test_refresh_dir.py | 7 +----- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/tagstudio/src/core/utils/refresh_dir.py b/tagstudio/src/core/utils/refresh_dir.py index 7e2224e3..e93d35bc 100644 --- a/tagstudio/src/core/utils/refresh_dir.py +++ b/tagstudio/src/core/utils/refresh_dir.py @@ -5,7 +5,7 @@ import structlog -from src.core.constants import TS_FOLDER_NAME, LibraryPrefs +from src.core.constants import TS_FOLDER_NAME from src.core.library import Library, Entry logger = structlog.get_logger(__name__) @@ -44,39 +44,22 @@ def refresh_dir(self, lib_path: Path) -> Iterator[int]: if self.library.library_dir is None: raise ValueError("No library directory set.") - is_exclude_list = self.library.prefs(LibraryPrefs.IS_EXCLUDE_LIST) - exclude_list = set(self.library.prefs(LibraryPrefs.EXTENSION_LIST)) - - def skip_suffix(suffix: str) -> bool: - """Determine if the file extension should be skipped. - - Declared as local function as it's faster. - - - check if the suffix is in the library's "exclude list" - - if library uses "exclude mode", and extensions is in the list, we skip - - if library uses "include mode", and extensions is not in the list, we skip - """ - return (suffix.lower() in exclude_list) == is_exclude_list - start_time_total = time() start_time_loop = time() self.files_not_in_library = [] dir_file_count = 0 - for path_item in lib_path.glob("**/*"): - str_path = str(path_item) - if path_item.is_dir(): + for path in lib_path.glob("**/*"): + str_path = str(path) + if path.is_dir(): continue if "$RECYCLE.BIN" in str_path or TS_FOLDER_NAME in str_path: continue - if skip_suffix(path_item.suffix): - continue - dir_file_count += 1 - relative_path = path_item.relative_to(lib_path) + relative_path = path.relative_to(lib_path) # TODO - load these in batch somehow if not self.library.has_path_entry(relative_path): self.files_not_in_library.append(relative_path) diff --git a/tagstudio/tests/macros/test_refresh_dir.py b/tagstudio/tests/macros/test_refresh_dir.py index 8c4864ff..f5887cd9 100644 --- a/tagstudio/tests/macros/test_refresh_dir.py +++ b/tagstudio/tests/macros/test_refresh_dir.py @@ -22,9 +22,4 @@ def test_refresh_new_files(library, exclude_mode): assert not list(registry.refresh_dir(library.library_dir)) # Then - if exclude_mode: - # .md is in the list & is_exclude_list is True - should not be registered - assert not registry.files_not_in_library - else: - # .md is in the list & is_exclude_list is False - should be registered - assert registry.files_not_in_library == [pathlib.Path("FOO.MD")] + assert registry.files_not_in_library == [pathlib.Path("FOO.MD")]