From 0afcd33a99dac0b3dfcf9f29af18fbcd2f583207 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Fri, 7 Apr 2023 13:32:26 +0200 Subject: [PATCH] Store settings in $HOME --- web/db.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/db.py b/web/db.py index 76318fe..60df669 100644 --- a/web/db.py +++ b/web/db.py @@ -4,7 +4,7 @@ import pathlib import time def lock(name): - lockfile = pathlib.Path(f'{name}.lock') + lockfile = pathlib.Path.home() / f'{name}.lock' for i in range(5): try: lockfile.symlink_to('/dev/null') @@ -14,7 +14,7 @@ def lock(name): raise TimeoutError(f'could not lock {name}') def unlock(name): - lockfile = pathlib.Path(f'{name}.lock') + lockfile = pathlib.Path.home() / f'{name}.lock' lockfile.unlink(missing_ok=True) @contextlib.contextmanager @@ -26,12 +26,12 @@ def locked(name): unlock(name) def read(name): - with open(f'{name}.json', 'a+', encoding='utf-8') as f: + with open(pathlib.Path.home() / f'{name}.json', 'a+', encoding='utf-8') as f: f.seek(0) return json.loads(f.read() or '{}') def write(name, data): - with open(f'{name}.json', 'w', encoding='utf-8') as f: + with open(pathlib.Path.home() / f'{name}.json', 'w', encoding='utf-8') as f: json.dump(data, f, indent=2) f.close()