fix(bib): attach_file resolves symlinks in storage_path; repair P37 worktree path on BIEQHVTM (closes #628)

This commit is contained in:
kert
2026-08-17 11:09:59 -04:00
parent c9e8e1e298
commit 18c1066b1d
2 changed files with 30 additions and 1 deletions

View File

@@ -523,7 +523,10 @@ class Store:
att_key,
title or path.name,
content_type,
str(dest),
# resolve(): through a symlinked storage dir (a git
# worktree's data/ pointing at the real data dir) the
# unresolved path dies with the worktree (#628).
str(dest.resolve()),
),
)
con.commit()

View File

@@ -566,6 +566,32 @@ class TestAttachments:
assert dest.exists()
s.close()
def test_attach_file_resolves_symlinked_storage(self, tmp_path: Path) -> None:
"""Regression #628: attaching through a symlinked storage dir
(e.g. a git worktree whose data/ points at the real data dir)
must record the canonical path — the P37 worktree left a dead
.worktrees/ storage_path behind after the worktree was removed."""
real_storage = tmp_path / "real" / "storage"
real_storage.mkdir(parents=True)
link = tmp_path / "worktree-storage"
link.symlink_to(real_storage, target_is_directory=True)
s = Store(tmp_path / "bib.sqlite", storage_dir=link)
key = s.create(Rule(title="Test"))
src = tmp_path / "doc.pdf"
src.write_bytes(b"fake pdf content")
att_key = s.attach_file(key, src)
row = (
s._con()
.execute("SELECT storage_path FROM attachments WHERE key = ?", (att_key,))
.fetchone()
)
stored = Path(row["storage_path"])
assert stored == real_storage.resolve() / att_key / "doc.pdf"
assert stored.exists()
s.close()
def test_attach_file_missing_item(self, tmp_path: Path) -> None:
db = tmp_path / "bib.sqlite"
s = Store(db)