text stringlengths 0 1.47k |
|---|
with self._conn() as c: |
rows = c.execute("SELECT vid, props FROM vertices WHERE label=?", (label,)).fetchall() |
out = [] |
for vid, props_json in rows: |
p = json.loads(props_json) |
if eq and any(str(p.get(k, "")) != str(v) for k, v in eq.items()): |
continue |
if neq and any(str(p.get(k, "")) == str(v) for k, v in neq.items()): |
continue |
out.append({"id": vid, **p}) |
return out |
try: |
return await asyncio.to_thread(_do) |
except Exception: # noqa: BLE001 |
return [] |
async def probe(self) -> None: |
def _do(): |
with self._conn() as c: |
c.execute("SELECT 1 FROM vertices LIMIT 1").fetchone() |
await asyncio.to_thread(_do) |
# ── local: filesystem blobs ─────────────────────────────────────────────────────── |
class FileBlobStore: |
"""Objects as plain files under {root}/{kb}/{file_id}. Listing is ascending-lexical over the |
relative keys — the SAME ordering contract the trace machinery relies on from Azure blob |
listing (inverted-timestamp keys ⇒ newest-first).""" |
def __init__(self, root: str): |
self._root = Path(root) |
def _p(self, kb: str, file_id: str) -> Path: |
p = (self._root / kb / file_id).resolve() |
base = (self._root / kb).resolve() |
if not str(p).startswith(str(base)): # refuse path escape |
raise ValueError(f"blob id escapes store: {file_id!r}") |
return p |
async def get(self, kb: str, file_id: str) -> bytes | None: |
def _do(): |
try: |
return self._p(kb, file_id).read_bytes() |
except (OSError, ValueError): |
return None |
return await asyncio.to_thread(_do) |
async def put(self, kb: str, file_id: str, data: bytes) -> bool: |
if not data: |
return False |
def _do(): |
try: |
p = self._p(kb, file_id) |
p.parent.mkdir(parents=True, exist_ok=True) |
tmp = p.with_suffix(p.suffix + ".tmp") |
tmp.write_bytes(data) |
tmp.replace(p) # atomic: a torn write never replaces a good blob |
return True |
except (OSError, ValueError): |
return False |
return await asyncio.to_thread(_do) |
async def delete(self, kb: str, file_id: str) -> bool: |
def _do(): |
try: |
path = self._p(kb, file_id) |
path.unlink(missing_ok=True) |
except (OSError, ValueError): |
return False |
# The directories a key's slashes created go with the last object in them, up to the |
# store root. A blob store has no directories; this one only borrows them from the file |
# system, and left alone they outlive every object: hr-test held 3,696 empty |
# sessions/<sid>/ shells on 2026-09-16, one per session ever deleted. rmdir refuses a |
# directory that still holds anything, which is the whole check. |
base = (self._root / kb).resolve() |
for parent in path.parents: |
if parent == base or base not in parent.parents: |
break |
try: |
parent.rmdir() |
except OSError: |
break |
return True |
return await asyncio.to_thread(_do) |
async def purge(self, kb: str, prefix: str) -> None: |
"""Remove everything under a folder-shaped prefix ("sessions/<sid>/"), including the |
temporary files a torn write leaves and `list` does not show. A deleted session's folder |
held a lone `changed.json.tmp` after every listed object was gone (hr-test copy, |
2026-10-08).""" |
def _do(): |
base = (self._root / kb).resolve() |
if not prefix.endswith("/") or prefix.strip("/") == "": |
return |
top = (base / prefix).resolve() |
if top == base or base not in top.parents or not top.is_dir(): |
return |
shutil.rmtree(top, ignore_errors=True) |
for parent in top.parents: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.