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. The age decides whether a list is fetched
only when Manager does not run as a pip package; a pip install fetches
at startup and reads the cache afterwards whatever its age.
- 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, and
cm-cli update-cache reports that cache as failed. 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 seven writes of a cache file: two in manager_util and
one each in the glob and legacy core, the glob and legacy server, and
cm-cli update-cache
- 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, the fetch that caches and the age
- Add a CHANGELOG entry
The same change for main is #3432.