MOVE write_state and load_state functions to paths.py

This is to encapsulate all path and state file related operations within the paths module.
This commit is contained in:
2025-12-17 23:52:00 +00:00
parent 35a68b04a8
commit d98dc8fa70
2 changed files with 32 additions and 22 deletions

View File

@@ -12,9 +12,14 @@ def state_dir() -> Path:
def get_state_file_path() -> Path:
return state_dir() / "state.json"
def get_state_file() -> dict:
path = get_state_file_path()
if not path.exists():
def load_state() -> dict:
if not get_state_file_path.exists():
return {"files": []}
with path.open() as f:
return json.load(f)
with get_state_file_path.open() as f:
return json.load(f)
def write_state(state: dict):
tmp = get_state_file_path().with_suffix(".tmp")
with tmp.open("w") as f:
json.dump(state, f, indent=2)
tmp.replace(get_state_file_path()) # atomic