Documentation
¶
Overview ¶
Package stalewb finds copies of wb on PATH that are older than the one the user just installed or is running. A package manager, `go install` and a hand-copied binary each own a different directory, so an update through one leaves the others behind, and any shell whose PATH is ordered differently runs the stale one. The package only reports: it never deletes or overwrites a copy.
Index ¶
Constants ¶
const ProbeTimeout = 3 * time.Second
ProbeTimeout bounds one `version --json` probe.
const SkipEnv = "WB_SKIP_STALE_SCAN"
SkipEnv is set on every probe child. A probed wb that itself scans PATH would spawn the same probes again and never stop.
Variables ¶
This section is empty.
Functions ¶
func ParseVersion ¶
ParseVersion reads the `version` key of a `version --json` document.
Types ¶
type Binary ¶
type Binary struct {
// Path is the PATH entry, the file `rm` removes.
Path string `json:"path"`
// RealPath is Path with symlinks resolved; it differs from Path for a
// launcher symlink.
RealPath string `json:"real_path,omitempty"`
Version string `json:"version"`
}
Binary is one stale wb on PATH.
type Candidate ¶
type Candidate struct{ Path, Real string }
Candidate is a wb executable found on PATH.
type Scanner ¶
type Scanner struct {
// PathEnv is the PATH value to search.
PathEnv string
// Probe returns the version the executable at path reports.
Probe func(ctx context.Context, path string) (string, error)
// Skip names an executable, by real path, that is not to be probed: the
// running binary.
Skip string
// Executable decides from a file's info whether it can be run; nil uses
// the platform rule (an execute bit, or any regular file on Windows).
Executable func(os.FileInfo) bool
}
Scanner finds and probes wb executables. Probe is the seam: it returns the version a candidate reports, and production runs the candidate while tests return canned versions.
func New ¶
func New() Scanner
New returns the scanner production uses: the process PATH, a probe that runs `version --json`, and the running executable skipped.
func (Scanner) Find ¶
Find lists the wb executables on PATH in PATH order, once per real file. A candidate is an absolute PATH entry named wb whose target resolves to a regular file with an execute bit; a directory, a device, a dangling symlink or a non-executable file is never probed.