stalewb

package
v0.220.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 11 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 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

View Source
const ProbeTimeout = 3 * time.Second

ProbeTimeout bounds one `version --json` probe.

View Source
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

func ParseVersion(output []byte) (string, error)

ParseVersion reads the `version` key of a `version --json` document.

func ProbeWith

func ProbeWith(run runner.Runner) func(context.Context, string) (string, error)

ProbeWith returns a probe that runs `path version --json` through run with a bounded timeout and the probe marker in the child's environment, and returns the version it reports. Only Find hands it a regular executable file named wb.

func Warning

func Warning(current string, stale []Binary) string

Warning renders the stale copies and the exact fix for each. It never removes anything. An empty list renders "".

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.

func Scan

func Scan(ctx context.Context, current string) []Binary

Scan returns the wb copies on PATH older than current. A process that is itself a probe child (SkipEnv set) scans nothing, so probes never recurse.

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

func (scanner Scanner) Find() []Candidate

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.

func (Scanner) Stale

func (scanner Scanner) Stale(ctx context.Context, current string) []Binary

Stale probes every wb on PATH and returns those that report a version older than current. A candidate whose version cannot be read, or that is not a semantic version, is not reported: it is not shown to be older.

Jump to

Keyboard shortcuts

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