Commit Graph
1 Commits
Author SHA1 Message Date
Perfect Johny bfd65e7173 Write cache files whole and age them by their last write (#3432)
The cache files of the channel lists and of the registry's node list
were written in place. A write that stopped part-way left a truncated
file, which get_data reads as an empty list.

is_file_created_within_one_day read os.path.getctime. On Windows that
is the creation time, which stays the same when the file is rewritten,
so a cache first created more than a day ago counted as expired however
recently it was written.

- Add write_cache_file, which writes a temporary file beside the cache
  and replaces the cache with it, keeping the mode of the existing
  file. Where the written file cannot be put in place, as on Windows
  while another reader has the cache open, the replace is tried three
  times, 0.1 s apart. A cache that stays open is left as it is, with a
  warning; the caller gets no error and goes on with its data. A
  failure while writing the temporary file leaves the cache as it is
  as well. Where the mode cannot be set, the cache is replaced all the
  same. A temporary file that cannot be removed, because a scanner
  holds it open, is left behind and does not fail the write
- Use it for the four writes of a cache file: two in manager_util, one
  in get_data_by_mode and one in default_cache_update
- Read the modification time for the age
- Add tests for a write that fails and one that runs out of space, the
  mode, a mode that cannot be set, a replace that is refused for a
  moment and one that stays refused, a temporary file that is held
  open, and the age
- Add a CHANGELOG entry

The same change for manager-v4 is #3532.
2026-11-15 14:30:12 +09:00