fix(pifs): roll back add-created folders

This commit is contained in:
BukeLy 2026-05-31 17:43:18 +08:00
parent 1c5ed63ef8
commit 8cdddb5e5b
3 changed files with 110 additions and 0 deletions

View file

@ -1063,6 +1063,48 @@ class SQLiteFileSystemStore:
conn.execute("DELETE FROM metadata_values WHERE file_ref = ?", (file_ref,))
conn.execute("DELETE FROM files WHERE file_ref = ?", (file_ref,))
def folder_exists(self, path: str) -> bool:
path = normalize_path(path)
with self.connect() as conn:
row = conn.execute(
"SELECT 1 FROM folders WHERE path = ?",
(path,),
).fetchone()
return row is not None
def delete_empty_folder(self, path: str) -> bool:
path = normalize_path(path)
if path == "/":
return False
with self.connect() as conn:
folder = self._folder_by_path(conn, path)
if folder is None:
return False
has_files = conn.execute(
"""
SELECT 1
FROM file_folders
WHERE folder_id = ?
LIMIT 1
""",
(folder["folder_id"],),
).fetchone()
if has_files is not None:
return False
has_children = conn.execute(
"""
SELECT 1
FROM folders
WHERE parent_id = ?
LIMIT 1
""",
(folder["folder_id"],),
).fetchone()
if has_children is not None:
return False
conn.execute("DELETE FROM folders WHERE folder_id = ?", (folder["folder_id"],))
return True
def resolve_file_ref(self, target: str) -> str:
with self.connect() as conn:
return self._resolve_file_ref(conn, target)