Expand description
File helpers the tools share: an atomic write, capped text reads, JSON
files, and the FileChange a tool that writes publishes. The reads and
the path rules here are this machine’s (Local); a tool reads through
its Workspace.
Structs§
- Prefix
- The start of a file read by
read_prefix.
Functions§
- file_
change - What turning
beforeintoafterdid to the file atpath(None: there was no file before, or there is none after): its lines added and removed, counted by a line diff, that diff as hunks with 3 lines of context, the text before, and theFileStateof each text: the fact a tool that writes files publishes (FilesChanged). - io_
error - A model-visible error for an I/O failure on
path. - place
pathresolved againstbase, as a file tool opens it; withconfine, refused before any I/O when it lies outsidebase(None: the working directory). The rule the file tools follow, for code that must decide as they would, such as a preview of a write.- read_
json - The JSON file at
pathas aT, orNonewhen it is missing or is not one. - read_
prefix - Reads at most
capbytes of the regular file atpathon this machine as aPrefix. - read_
text - Reads
pathas text after checking, without opening it, that it is a regular file of at mostMAX_FILE_BYTES: opening a FIFO or a device can block forever.Local’sread_text. - resolve
pathas the file tools open it: made absolute againstbase(None: this process’s working directory), with every symbolic link of its longest existing part followed (the file’s own too, when it exists) and..folded. Two spellings of one file resolve alike, so this is how the facts the tools publish (FilesRead,FileChange::path) and their footprints name files. A path that cannot be made absolute (no working directory) stays relative.- write_
atomic - Replaces the file at
pathwithcontentsin one step, creating its directory: a temporary file beside it is written, synced and renamed over it, so a crash or a full disk never leaves it half written. A symlink’s target is replaced and the link kept, and a dangling link’s target is created; an existing file keeps its permissions. A read-only file is refused, as is anything but a regular file, because opening a FIFO or a device for writing can block forever. - write_
json - Replaces the file at
pathwithvalueas pretty JSON, bywrite_atomic.