Documentation
¶
Overview ¶
Package steady reads and replaces files that another process may be replacing at that moment. On Windows a file being renamed over refuses to open, and one held open refuses to be renamed over, both for a moment ("Access is denied"): read as none, a file of accounts is no accounts, and the next write leaves them out. A file being renamed over is also, for a moment (two milliseconds seen), not there at all, to another process or thread: Stat and ReadThere wait that out for a file that was there. Elsewhere a rename is atomic and these are os.Stat, os.ReadFile and os.Rename.
Index ¶
- Variables
- func ReadFile(p string) ([]byte, error)
- func ReadThere(p string) ([]byte, error)
- func ReadThereInto(p string, buf []byte) ([]byte, error)
- func RemoveStaleTemps(path string)
- func Rename(oldpath, newpath string) error
- func Stat(p string) (fs.FileInfo, error)
- func WriteFile(p string, b []byte, perm fs.FileMode) error
Constants ¶
This section is empty.
Variables ¶
var Sync = (*os.File).Sync
Sync is (*os.File).Sync; a test stands in for it to make a flush fail.
Functions ¶
func ReadThere ¶ added in v0.1.945
ReadThere is ReadFile of a file just found there (Stat): not there now is it being replaced, waited out.
func ReadThereInto ¶ added in v0.1.2456
ReadThereInto is ReadThere into buf's room, grown when the file needs more: for a caller that reads one file again and again only to compare it, which a new buffer each time made the bulk of what magpie allocated as it started (a 1.5 MB config.toml read 150 times over).
func RemoveStaleTemps ¶ added in v0.1.3052
func RemoveStaleTemps(path string)
RemoveStaleTemps removes the temp files that earlier writes of path left beside it when they died or failed part way, once a later write has gone through: the file then holds newer text than any of them (#4938 — a start-up that exits mid-write left hundreds beside magpie's own files, and every file descriptor a directory watcher holds on them with it). One younger than staleTemps stays, as another write may still be using it. Should a write stall longer than that (a laptop asleep mid-write) and lose its temp file here, its rename fails and leaves the file as it was, or, writing in place, it only loses the spare copy of its text.
func Stat ¶ added in v0.1.945
Stat is os.Stat of a file that was there: one being replaced is waited for, so it isn't taken for gone. A file not there costs the wait, so a caller asking again remembers it gone (filememo does).
func WriteFile ¶ added in v0.1.1166
WriteFile replaces p with b, mode perm, through a temp file beside it that is flushed to the disk before it is renamed over p. A rename reaches the disk on its own schedule and the data behind it later: a Windows machine that went down between the two left logins.json and plugin-auth.json at their full length with every byte zero (#1505). A write or flush that fails removes the temp file and leaves p as it was. A write that is served takes the stale temps earlier writes left beside p when they died (RemoveStaleTemps) along with it.
Types ¶
This section is empty.