fix(854-2): M01 키 대장 쓰기 원자적 · 파일 쓰기 중간 실패 때 대장 · 파일 저장 전으로 되돌림 — 묶음 ②
- master_keys.save_book = 임시 파일 → 교체(반쪽 대장 없음 · 빌더도 같은 길) - Store_Save.save = 대장 → 파일 차례 그대로 · 파일 쓰기가 끊기면 쓴(쓰려던) 파일 · 기계 대 · 대장을 저장 전 글로(대장만 앞서가지 않음) - 시험 test_854_2_m01_key_book — 첫 파일 · 둘째 파일(반쯤 쓴 뒤) 끊김 = 바이트 그대로 · 끊김 없음 = 대장 · 파일 같이 감 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from decimal import Decimal
|
||||
from pathlib import Path
|
||||
@@ -77,7 +78,9 @@ def save_book(book: dict, path: Path = BOOK) -> None:
|
||||
comma = "," if i < len(items) - 1 else ""
|
||||
lines.append(f" {json.dumps(key)}: {json.dumps(v, ensure_ascii=False)}{comma}")
|
||||
lines += [" }", "}"]
|
||||
path.write_text("\n".join(lines) + "\n", encoding="utf-8", newline="\n")
|
||||
tmp = path.with_name(f".{path.name}.tmp") # 임시 파일 → 교체(원자적 · 끊겨도 반쪽 대장 없음)
|
||||
tmp.write_text("\n".join(lines) + "\n", encoding="utf-8", newline="\n")
|
||||
os.replace(tmp, path)
|
||||
|
||||
|
||||
def lookup(book: dict) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user