Skip to content

Commit b82b186

Browse files
committed
fix: check if backup_folder exists before loading backup
1 parent a954406 commit b82b186

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

tagstudio/src/core/library.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -507,24 +507,25 @@ def open_library(self, path: str | Path, is_path_file: bool = False) -> int:
507507

508508
except (ujson.JSONDecodeError, FileNotFoundError):
509509
logging.info(
510-
"[LIBRARY][WARNING] Blank/Corrupted Library file found. Searching for Auto Backup..."
510+
"[LIBRARY][ERROR] Blank/Corrupted Library file found. Searching for Auto Backup..."
511511
)
512512
backup_folder: Path = (
513513
self._fix_lib_path(path) / TS_FOLDER_NAME / BACKUP_FOLDER_NAME
514514
)
515-
auto_backup: Path = None
516-
dir_obj = os.scandir(backup_folder)
515+
if backup_folder.exists():
516+
auto_backup: Path = None
517+
dir_obj = os.scandir(backup_folder)
517518

518-
for backup_file in dir_obj:
519-
if backup_file.is_file() and "ts_library_backup_auto" in str(
520-
backup_file
521-
):
522-
auto_backup = Path(backup_file)
523-
break
519+
for backup_file in dir_obj:
520+
if backup_file.is_file() and "ts_library_backup_auto" in str(
521+
backup_file
522+
):
523+
auto_backup = Path(backup_file)
524+
break
524525

525-
if auto_backup and "ts_library_backup_auto" not in str(path):
526-
logging.info(f"[LIBRARY] Loading Auto Backup: {auto_backup}")
527-
return self.open_library(auto_backup, is_path_file=True)
526+
if auto_backup and "ts_library_backup_auto" not in str(path):
527+
logging.info(f"[LIBRARY] Loading Auto Backup: {auto_backup}")
528+
return self.open_library(auto_backup, is_path_file=True)
528529

529530
else:
530531
self.library_dir = self._fix_lib_path(path)
@@ -727,7 +728,7 @@ def open_library(self, path: str | Path, is_path_file: bool = False) -> int:
727728
c = Collation(
728729
id=id,
729730
title=title,
730-
e_ids_and_pages=e_ids_and_pages, # type: ignore
731+
e_ids_and_pages=e_ids_and_pages,
731732
sort_order=sort_order,
732733
cover_id=cover_id,
733734
)

0 commit comments

Comments
 (0)