From 35a68b04a8e0dfad5e96895e6469de8c0aa4b3b0 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Wed, 17 Dec 2025 23:49:50 +0000 Subject: [PATCH] ADD paths module To automate the fetching of the state file in a safe, atomic way. --- rewind/paths.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 rewind/paths.py diff --git a/rewind/paths.py b/rewind/paths.py new file mode 100644 index 0000000..e53086a --- /dev/null +++ b/rewind/paths.py @@ -0,0 +1,20 @@ +from pathlib import Path +import os, json + +APP_NAME = "rewind" + +def state_dir() -> Path: + base = os.path.expanduser("~/.local/share") + path = Path(base) / APP_NAME + path.mkdir(parents=True, exist_ok=True) + return 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(): + return {"files": []} + with path.open() as f: + return json.load(f) \ No newline at end of file