f
This commit is contained in:
@@ -263,7 +263,31 @@ class API_folder_store:
|
||||
try:
|
||||
# Ensure the library root exists; sqlite cannot create parent dirs.
|
||||
try:
|
||||
# User safety: Folder store must be created in a blank folder/no files in it.
|
||||
# If the DB already exists, we skip this check (it's an existing library).
|
||||
should_check_empty = not self.db_path.exists()
|
||||
|
||||
self.library_root.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if should_check_empty:
|
||||
# Check if there are any files or directories in the library root (excluding the DB itself if it was just created)
|
||||
# We use a generator and next() for efficiency.
|
||||
existing_items = [item for item in self.library_root.iterdir() if item.name != self.DB_NAME]
|
||||
if existing_items:
|
||||
# Log the items found for debugging
|
||||
item_names = [i.name for i in existing_items[:5]]
|
||||
if len(existing_items) > 5:
|
||||
item_names.append("...")
|
||||
raise RuntimeError(
|
||||
f"Safety Check Failed: Local library root must be empty for new stores.\n"
|
||||
f"Directory: {self.library_root}\n"
|
||||
f"Found {len(existing_items)} items: {', '.join(item_names)}\n"
|
||||
f"Please use a clean directory to prevent accidental hashing of existing files."
|
||||
)
|
||||
|
||||
except RuntimeError:
|
||||
# Re-raise our specific safety error
|
||||
raise
|
||||
except Exception as exc:
|
||||
raise RuntimeError(
|
||||
f"Cannot create/open library root directory: {self.library_root}: {exc}"
|
||||
|
||||
Reference in New Issue
Block a user