fix(bib): attach_file resolves symlinks in storage_path; repair P37 worktree path on BIEQHVTM (closes #628)
This commit is contained in:
@@ -523,7 +523,10 @@ class Store:
|
|||||||
att_key,
|
att_key,
|
||||||
title or path.name,
|
title or path.name,
|
||||||
content_type,
|
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()
|
con.commit()
|
||||||
|
|||||||
@@ -566,6 +566,32 @@ class TestAttachments:
|
|||||||
assert dest.exists()
|
assert dest.exists()
|
||||||
s.close()
|
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:
|
def test_attach_file_missing_item(self, tmp_path: Path) -> None:
|
||||||
db = tmp_path / "bib.sqlite"
|
db = tmp_path / "bib.sqlite"
|
||||||
s = Store(db)
|
s = Store(db)
|
||||||
|
|||||||
Reference in New Issue
Block a user