Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/tagstudio/core/library/refresh.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-FileCopyrightText: (c) TagStudio Contributors
# SPDX-License-Identifier: GPL-3.0-only


import platform
import shutil
from collections.abc import Iterator
from dataclasses import dataclass, field
Expand Down Expand Up @@ -39,12 +38,7 @@ def save_new_files(self) -> Iterator[int]:
yield index
end = min(len(self.files_not_in_library), index + batch_size)
entries = [
Entry(
path=entry_path,
folder=unwrap(self.library.folder),
fields=[],
date_added=dt.now(),
)
self.__create_entry(entry_path)
for entry_path in self.files_not_in_library[index:end]
]
self.library.add_entries(entries)
Expand Down Expand Up @@ -167,7 +161,7 @@ def __wc_add(self, library_dir: Path, ignore_patterns: list[str]) -> Iterator[in

try:
for f in pathlib.Path(str(library_dir)).glob(
"***/*", flags=PATH_GLOB_FLAGS, exclude=ignore_patterns
"***/*", flags=PATH_GLOB_FLAGS, exclude=ignore_patterns
):
end_time_loop = time()
# Yield output every 1/30 of a second
Expand Down Expand Up @@ -203,3 +197,24 @@ def __wc_add(self, library_dir: Path, ignore_patterns: list[str]) -> Iterator[in
files_scanned=dir_file_count,
tool_used="wcmatch (internal)",
)

def __create_entry(self, entry_path: Path) -> Entry:
"""Extract metadata and instantiate an Entry database model from a file path."""
library_dir = unwrap(self.library.library_dir)
absolute_path = library_dir / entry_path
file_stat = absolute_path.stat()

if platform.system() == "Windows" or platform.system() == "Darwin":
date_created = dt.fromtimestamp(file_stat.st_birthtime)
else:
date_created = dt.fromtimestamp(file_stat.st_ctime)
date_modified = dt.fromtimestamp(file_stat.st_mtime)

return Entry(
path=entry_path,
folder=unwrap(self.library.folder),
fields=[],
date_added=dt.now(),
date_created=date_created,
date_modified=date_modified
)