Expand description
Saving a JSON file this build reads without losing what it could not read.
A file under the person’s configuration is read into a typed value, changed, and written back whole. When the typed read gives up on a piece (an entry a newer AgentMux wrote with a kind this build has never heard of, a topic it does not know) and the caller then saves the rest, the piece is gone from disk: a downgrade, or one build that is a version behind, quietly deletes what the newer one kept. These helpers keep that piece: an entry that does not read is written back exactly as it was, and a file that does not read at all is copied aside before it is replaced, never simply overwritten.
Functions§
- carry_
unknown_ keys - Copies into the object
newevery key of the objectoldthatnewlacks and that is not one ofknown(the keys this build owns: one of them missing fromnewwas removed on purpose). What is left is what a newer AgentMux wrote. - carry_
unknown_ keys_ in_ list carry_unknown_keysfor each object of the listnew, from the object of the listoldthat has the sameid_key.- has_
record - Whether the file holds a record under
key, readable by this build or not. - read_
entries - A file that is a JSON object of records, each read on its own: the records that read, and none of the ones that do not. A missing or unreadable file is empty.
- read_
old - The bytes of
pathas JSON, when it is JSON; the file as it was before this save, so the keys a typed value dropped can be carried over from it. - set_
aside_ if_ unreadable - When
pathholds bytes that are not aT, copies them to<path>.unreadableso the next save of the file does not destroy them. Nothing when the file is absent or reads fine. Best effort: a copy that fails is logged, not an error of the save. - write_
entries - Writes
entriesas the file’s records, plus every record already in the file that this build cannot read (they are not inentriesbecause they never loaded, so the caller did not choose to drop them), exactly as they are. A file that is not an object of records is copied aside first. Written to a temp file and renamed. - write_
entries_ removing write_entriesfor a save that deletes records on purpose: each key ofremovedis dropped from the file even when this build cannot read its record (an uninstall must revoke what it names, not leave it for a later build to find).