fix: write_vector_build_state fallback when file locked

Windows: tmp.replace(path) fails when Obsidian plugin is reading
vector-build-state.json. Fall back to direct write to avoid crashing
the embed build. Stale tmp files cleaned up lazily.
This commit is contained in:
LLLin000 2026-07-07 02:12:27 +08:00
parent db2988d8f0
commit 9c85b30d7f

View file

@ -39,8 +39,16 @@ def write_vector_build_state(vault: Path, state: dict) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
tmp = path.with_suffix(".tmp")
tmp.write_text(json.dumps(state, ensure_ascii=False, indent=2), encoding="utf-8")
tmp.replace(path)
try:
tmp.replace(path)
except OSError:
# Windows: target file may be locked (e.g., Obsidian plugin reading it).
# Fall back to direct write — atomicity is secondary to avoiding crash.
path.write_text(tmp.read_text(encoding="utf-8"), encoding="utf-8")
try:
tmp.unlink()
except OSError:
pass
def mark_vector_build_state(vault: Path, **fields) -> dict:
state = read_vector_build_state(vault)