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 c9d61b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
27 changes: 5 additions & 22 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,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)
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 c9d61b5

Please sign in to comment.