Skip to content

Commit 79d3b76

Browse files
committed
Resolved merge conflicts
2 parents fab21ec + 8f17c36 commit 79d3b76

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

src/tagstudio/core/library/alchemy/enums.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ class ItemType(enum.Enum):
6767

6868
class SortingModeEnum(enum.Enum):
6969
DATE_ADDED = "file.date_added"
70+
<<<<<<< HEAD:src/tagstudio/core/library/alchemy/enums.py
7071
FILE_NAME = "generic.filename"
7172
PATH = "file.path"
73+
=======
74+
>>>>>>> 8f17c362203a368c5860599b75c2e89e6c8c1fc5:tagstudio/src/core/library/alchemy/enums.py
7275
DATE_CREATED = "file.date_created"
7376
DATE_MODIFIED = "file.date_modified"
7477

src/tagstudio/core/library/alchemy/library.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def migrate_json_to_sqlite(self, json_lib: JsonLibrary):
304304
)
305305
for entry in json_lib.entries
306306
# if (date_created := get_file_time(entry.path / entry.filename)[0]) is not None
307-
# and (date_modified := get_file_time(entry.path / entry.filename)[1]) is not None # noqa: F821
307+
# and (date_modified := get_file_time(entry.path / entry.filename)[1]) is not None
308308
]
309309
)
310310
for entry in json_lib.entries:
@@ -765,15 +765,6 @@ def get_entry_full_by_path(self, path: Path) -> Entry | None:
765765
make_transient(entry)
766766
return entry
767767

768-
def get_entry_by_path(self, path: Path) -> Entry | None:
769-
"""Get the entry with the corresponding path."""
770-
with Session(self.engine) as session:
771-
entry = session.scalar(select(Entry).where(Entry.path == path))
772-
if entry:
773-
session.expunge(entry)
774-
make_transient(entry)
775-
return entry
776-
777768
@property
778769
def entries_count(self) -> int:
779770
with Session(self.engine) as session:

src/tagstudio/core/utils/refresh_dir.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import datetime as dt
1+
from datetime import datetime as dt
22
from collections.abc import Iterator
33
from dataclasses import dataclass, field
44
from pathlib import Path
@@ -36,11 +36,15 @@ class RefreshDirTracker:
3636
def files_count(self) -> int:
3737
return len(self.files_not_in_library)
3838

39+
<<<<<<< HEAD:src/tagstudio/core/utils/refresh_dir.py
3940
# moving get_file_times to library to avoid circular import
41+
=======
42+
>>>>>>> 8f17c362203a368c5860599b75c2e89e6c8c1fc5:tagstudio/src/core/utils/refresh_dir.py
4043
def get_file_times(self, file_path: Path):
4144
"""Get the creation and modification times of a file."""
4245
stat = file_path.stat()
4346
system = platform.system()
47+
<<<<<<< HEAD:src/tagstudio/core/utils/refresh_dir.py
4448

4549
# st_birthtime on Windows and Mac, st_ctime on Linux.
4650
if system in ['Windows', 'Darwin']: # Windows & macOS
@@ -49,11 +53,25 @@ def get_file_times(self, file_path: Path):
4953
date_created = dt.datetime.fromtimestamp(stat.st_ctime) # Linux lacks st_birthtime
5054

5155
date_modified = dt.datetime.fromtimestamp(stat.st_mtime)
56+
=======
57+
if system == 'Windows': # Windows
58+
date_created = dt.fromtimestamp(stat.st_ctime, dt.timezone.utc)
59+
elif system == 'Darwin': # macOS
60+
date_created = dt.fromtimestamp(stat.st_birthtime, dt.timezone.utc)
61+
else: # Linux and other systems
62+
try:
63+
date_created = dt.fromtimestamp(stat.st_birthtime, dt.timezone.utc)
64+
except AttributeError:
65+
# st_birthtime is not available on some Linux filesystems
66+
date_created = dt.fromtimestamp(stat.st_ctime, dt.timezone.utc)
67+
date_modified = dt.fromtimestamp(stat.st_mtime, dt.timezone.utc)
68+
>>>>>>> 8f17c362203a368c5860599b75c2e89e6c8c1fc5:tagstudio/src/core/utils/refresh_dir.py
5269
return date_created, date_modified
5370

5471
def save_new_files(self):
5572
"""Save the list of files that are not in the library."""
5673
if self.files_not_in_library:
74+
<<<<<<< HEAD:src/tagstudio/core/utils/refresh_dir.py
5775
entries = [
5876
Entry(
5977
path=entry_path,
@@ -67,6 +85,23 @@ def save_new_files(self):
6785
if (date_created := self.get_file_times(entry_path)[0]) is not None
6886
and (date_modified := self.get_file_times(entry_path)[1]) is not None
6987
]
88+
=======
89+
entries = []
90+
for entry_path in self.files_not_in_library:
91+
date_created, date_modified = self.get_file_times(entry_path)
92+
if date_created is None or date_modified is None:
93+
continue # Skip files that could not be processed
94+
entries.append(
95+
Entry(
96+
path=entry_path,
97+
folder=self.library.folder,
98+
fields=[],
99+
date_added=dt.now(),
100+
date_created=dt.now(),
101+
date_modified=dt.now(),
102+
)
103+
)
104+
>>>>>>> 8f17c362203a368c5860599b75c2e89e6c8c1fc5:tagstudio/src/core/utils/refresh_dir.py
70105
self.library.add_entries(entries)
71106

72107
self.files_not_in_library = []
@@ -117,7 +152,19 @@ def refresh_dir(self, lib_path: Path) -> Iterator[int]:
117152
relative_path = f.relative_to(lib_path)
118153
# TODO - load these in batch somehow
119154
if not self.library.has_path_entry(relative_path):
155+
<<<<<<< HEAD:src/tagstudio/core/utils/refresh_dir.py
120156
self.files_not_in_library.append(f)
157+
=======
158+
self.files_not_in_library.append(relative_path)
159+
else:
160+
# Update date_modified for existing entries if it has changed
161+
entry = self.library.get_entry_by_path(relative_path)
162+
if entry:
163+
date_modified = dt.fromtimestamp(f.stat().st_mtime, dt.timezone.utc)
164+
if entry.date_modified != date_modified:
165+
entry.date_modified = date_modified
166+
self.library.update_entry(entry)
167+
>>>>>>> 8f17c362203a368c5860599b75c2e89e6c8c1fc5:tagstudio/src/core/utils/refresh_dir.py
121168

122169
end_time_total = time()
123170
yield dir_file_count

0 commit comments

Comments
 (0)