Add move operation, fix fuse server
This commit is contained in:
parent
41480a39c9
commit
6470aee802
5 changed files with 90 additions and 45 deletions
|
|
@ -14,6 +14,8 @@ from typing import NamedTuple
|
|||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from . import trove as tr
|
||||
|
||||
NOTE_ROOT_ID = uuid.UUID(int=0)
|
||||
|
||||
class ObjectInfo(NamedTuple):
|
||||
|
|
@ -288,13 +290,21 @@ class Sqlite3Trove:
|
|||
# Tree entry operations
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def link(self, parent_id: SqlObjectId, name: str, child_id: SqlObjectId) -> None:
|
||||
def link(self, parent_id: SqlObjectId, name: str, child_id: SqlObjectId, overwrite: bool = True) -> None:
|
||||
"""
|
||||
Link a child object into a tree under the given name.
|
||||
Replaces any existing entry with the same name in this tree.
|
||||
Replaces any existing entry with the same name in this tree if overwrite=True.
|
||||
Both parent_id and child_id must exist in the objects table
|
||||
(enforced by FK constraints).
|
||||
"""
|
||||
if not overwrite:
|
||||
existing = self._con.execute(
|
||||
"SELECT 1 FROM tree_entries WHERE parent_id = ? AND name = ?",
|
||||
(_sql_id(parent_id), name),
|
||||
).fetchone()
|
||||
if existing:
|
||||
raise tr.ErrorExists(f"Entry '{name}' already exists in tree {parent_id}")
|
||||
|
||||
self._con.execute(
|
||||
"INSERT OR REPLACE INTO tree_entries (parent_id, name, child_id) "
|
||||
"VALUES (?, ?, ?)",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue