Commit Graph

20 Commits

Author SHA1 Message Date
CalamitousFelicitousness 68c64fb4bc fix(json_helpers): write atomically by default and warn on empty reads
Every caller writes a whole JSON document, and a plain open/write can
leave a torn or empty file when the process dies or another writer
overlaps, which readfile then returns as {}. Writes now go through the
temp file and replace unless atomic=False or the mode is append. A read
waits out an open that Windows refuses while a replace of the same name
is in flight, and an empty file is reported when the read is not
silent, since a zero-byte config.json otherwise resets settings without
a trace.
2026-09-13 19:20:10 +01:00
CalamitousFelicitousness b39639ce2e fix(json_helpers): serialize file access per path within the process
The fasteners lock is inter-process only. On Linux fcntl record locks
belong to the process, so two threads writing the same file were never
serialized and could tear it; on Windows they were, until the lock
switched itself off. Every writer of these files runs inside one
multi-threaded process, so that is the case that matters.

readfile(lock=True) and writefile now take a re-entrant lock per
normalized path, held from the snapshot through the replace so writes
to one path land in call order. Other processes are covered by the
atomic replace. A .lock file left next to a JSON file by the old lock
is removed the first time that path is used.
2026-09-13 19:20:10 +01:00
CalamitousFelicitousness cdc76c25c6 fix(json_helpers): make atomic saves work on windows, keep lock file
writefile(atomic=True) renamed the temp file while it was still open,
which Windows refuses, so every atomic save failed there and left a temp
file behind. The temp file is now created with mkstemp, closed before
os.replace and removed when the save fails; the replace retries briefly
when another handle holds the target, which Windows reports as a
permission error.

Both helpers removed the .lock file after releasing it. That removal
raced other holders on both platforms, and any failure switched locking
off for the whole process without a log line. The lock file now stays in
place; a failed release or a lock timeout is logged instead.

writefile deep-copied and validated the live object in Python, so a
concurrent insert into a shared dict raised "dictionary changed size
during iteration" and dropped the save. dict.copy and list.copy run
under the GIL, so the deep copy and the per-key validation now walk that
snapshot; nested containers remain the caller's responsibility.

test/test-json-helpers.py covers all three on Linux and Windows.
2026-09-13 18:41:33 +01:00
Vladimir Mandic 7c228892cf model metadata handle invalid keys
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-06-29 11:23:29 +02:00
awsr 3a13d6049d Update filename / path typing 2026-04-26 20:21:00 -07:00
awsr 45bdda9fb7 Simplify code and run formatting 2026-04-21 04:24:29 -07:00
awsr 35aab83ee0 Improve compatibility and add relevant typing 2026-04-20 14:45:34 -07:00
vladmandic 9ad68c2ff4 eliminate possible race conditions during startup
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-01 13:46:05 +01:00
Vladimir Mandic a3074baf8b unified logger 2026-02-19 09:46:42 +01:00
vladmandic a7c32caae3 relocate all jsons to data
Signed-off-by: vladmandic <mandic00@live.com>
2026-01-24 13:54:40 +01:00
awsr ec86e52ded Correct type enforcement 2026-01-13 02:11:58 -08:00
awsr 2394a7fac1 Ignore false positives with static typing 2026-01-13 02:10:38 -08:00
awsr 7c01fd71de Don't warn about file if not reading from a file
Leave that up to the other log messages
2025-12-28 03:10:22 -08:00
awsr 89fd729d74 Restore accidental deletion 2025-12-28 03:02:39 -08:00
awsr 66f55a7d7c Better data handling 2025-12-28 02:59:51 -08:00
awsr 70081e0d74 Fix default value 2025-12-28 02:38:17 -08:00
awsr 691ace3543 Add warning messages 2025-12-28 02:25:43 -08:00
awsr dcb7164d30 Update readfile type safety 2025-12-17 16:43:54 -08:00
awsr c22ca8d76e Create and opt in to dict type safety from JSON
Opt in via the keyword-only argument `dict_only`
2025-12-17 13:18:13 -08:00
Vladimir Mandic 4e449ca9b2 refactor monolithic shared.py and separate legacy options with logging
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-07-12 13:35:41 -04:00