Help us shape the future of Go! Take the 2026 Go Developer Survey

pkgmanager

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pkgmanager tells whether a binary was installed by a package manager, so a self-updater can defer to that manager rather than replace a file it tracks (gtb#129).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Detector

type Detector struct {
	// contains filtered or unexported fields
}

Detector finds the package manager, if any, that owns a binary.

func New

func New(opts ...Option) *Detector

New returns a Detector over the real filesystem and package databases.

func (*Detector) Detect

func (d *Detector) Detect(ctx context.Context, exe string) (Install, bool)

Detect reports the package manager that installed the binary at exe. A Homebrew install is recognised from its path alone; dpkg and rpm are asked, and only for a path under a system prefix. A failed query is not ownership.

type Install

type Install struct {
	Manager Manager
	Package string
	// Path is the binary's path with symlinks resolved.
	Path string
}

Install is a binary a package manager owns.

func (Install) UpgradeCommand

func (i Install) UpgradeCommand() string

UpgradeCommand is the package manager's own command for upgrading the package.

type Manager

type Manager string

Manager names a package manager that can own an installed binary.

const (
	// HomebrewFormula is a binary under a Homebrew Cellar.
	HomebrewFormula Manager = "Homebrew formula"
	// HomebrewCask is a binary under a Homebrew Caskroom.
	HomebrewCask Manager = "Homebrew cask"
	// Dpkg is a file dpkg records as installed by a .deb package.
	Dpkg Manager = "dpkg"
	// RPM is a file the RPM database records as installed by a package.
	RPM Manager = "rpm"
)

type Option

type Option func(*Detector)

Option configures a Detector.

func WithCommand

func WithCommand(fn func(context.Context, string, ...string) *exec.Cmd) Option

WithCommand replaces exec.CommandContext, which runs the ownership query.

func WithLookPath

func WithLookPath(fn func(string) (string, error)) Option

WithLookPath replaces exec.LookPath, which finds dpkg-query and rpm.

Jump to

Keyboard shortcuts

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