steady

package
v0.1.4232 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
var Sync = (*os.File).Sync

Sync is (*os.File).Sync; a test stands in for it to make a flush fail.

Functions

func ReadFile

func ReadFile(p string) ([]byte, error)

ReadFile is os.ReadFile, waiting out a file being replaced.

func ReadThere added in v0.1.945

func ReadThere(p string) ([]byte, error)

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

func ReadThereInto(p string, buf []byte) ([]byte, error)

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 Rename

func Rename(oldpath, newpath string) error

Rename is os.Rename, waiting out a reader holding newpath open.

func Stat added in v0.1.945

func Stat(p string) (fs.FileInfo, error)

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

func WriteFile(p string, b []byte, perm fs.FileMode) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL