refactor(858-5-3): 판 한 벌 · 프로젝트 층 저장 잠금 — Template_Layers 판 = Store.version_of · write_template 을 Store._LOCK 안에서
- `Template_Layers.version_of` · `read_template` 판 = `Store.version_of` 한 몸(같은 sha256 앞 16 자 · 판 값 안 바뀜) · hashlib 직접 셈 걷음 - `write_template` 판 대조 · 원자 쓰기를 `Store._LOCK` 안으로(대조와 쓰기 사이가 열려 있던 것) · 부르는 곳(층 길 프로젝트 저장 · B07 도각 · B08 옵션)이 잠금 안에서 부르지 않음 확인 - `Store` 는 고침 없음 · `Item_Source.version_of` 는 855 B9-5 몫이라 안 고침 - 지킴: test_858_shelf_golden 지문 같음 · 관련 시험 + 826_1 · 204_2 · 572 · 855_golden 485 통과 · typecheck 0 · openapi 길 480 그대로 · 검증_sub4 프로젝트 집계표 저장 = 판 같음 · 옛 판 409 · 파일 그대로 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
@@ -137,10 +136,13 @@ def template_path(layer_dir: str | Path, kind: str, name: str) -> Path:
|
||||
|
||||
|
||||
def version_of(path: str | Path) -> str | None:
|
||||
"""파일 판 — 몸은 `Store.version_of` 한 벌(858 5-3 · Store 가 이 파일을 불러 안에서 부름)."""
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
|
||||
path = Path(path)
|
||||
if not path.is_file():
|
||||
return None
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()[:16]
|
||||
return store.version_of(path.read_bytes())
|
||||
|
||||
|
||||
def _modified(path: Path) -> str:
|
||||
@@ -176,11 +178,13 @@ def read_template(layer_dir: str | Path, kind: str, name: str) -> dict[str, Any]
|
||||
path = template_path(layer_dir, kind, name)
|
||||
if not path.is_file():
|
||||
return None
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
|
||||
raw = path.read_bytes()
|
||||
return {
|
||||
"종류": kind,
|
||||
"이름": name,
|
||||
"판": hashlib.sha256(raw).hexdigest()[:16],
|
||||
"판": store.version_of(raw),
|
||||
"문서": json.loads(raw.decode("utf-8")),
|
||||
}
|
||||
|
||||
@@ -257,16 +261,20 @@ def write_template(
|
||||
version: str | None = None,
|
||||
check_version: bool = False,
|
||||
) -> str:
|
||||
"""원자 쓰기 → 새 판. `check_version` 이면 `version` 이 지금 판과 같아야 함(새 파일은 None)."""
|
||||
"""원자 쓰기 → 새 판. `check_version` 이면 `version` 이 지금 판과 같아야 함(새 파일은 None) ·
|
||||
판 대조 · 쓰기 = `Store._LOCK` 안(858 5-3 — 대조와 쓰기 사이가 열려 있던 것)."""
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
|
||||
if not isinstance(document, dict):
|
||||
raise ValueError("양식 문서는 JSON 객체여야 합니다.")
|
||||
path = template_path(layer_dir, kind, name)
|
||||
if check_version:
|
||||
current = version_of(path)
|
||||
if current != (version or None):
|
||||
raise StaleTemplate(current)
|
||||
atomic_write_json(path, document)
|
||||
return version_of(path) or ""
|
||||
with store._LOCK:
|
||||
if check_version:
|
||||
current = version_of(path)
|
||||
if current != (version or None):
|
||||
raise StaleTemplate(current)
|
||||
atomic_write_json(path, document)
|
||||
return version_of(path) or ""
|
||||
|
||||
|
||||
def delete_template(
|
||||
|
||||
Reference in New Issue
Block a user