mirror of
https://github.com/lllin000/PaperForge.git
synced 2026-07-22 06:50:53 +00:00
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:
parent
db2988d8f0
commit
9c85b30d7f
1 changed files with 10 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue