Skip to content

Commit

Permalink
undo the extension check in refresh_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
yedpodtrzitko committed Sep 11, 2024
1 parent c71d63c commit d4f0597
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
19 changes: 1 addition & 18 deletions tagstudio/src/core/utils/refresh_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -44,20 +44,6 @@ 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()

Expand All @@ -72,9 +58,6 @@ def skip_suffix(suffix: str) -> bool:
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)
# TODO - load these in batch somehow
Expand Down
7 changes: 1 addition & 6 deletions tagstudio/tests/macros/test_refresh_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit d4f0597

Please sign in to comment.