Files
snack/apt/apt.go
Tai Groot 0d6c5d9e17 feat: add per-provider mutex and Target-aware implementations
- Add snack.Locker embed for per-provider mutex serialization
- Update all providers (pacman, apk, apt, dpkg) to use []Target
  with version pinning support (pkg=version syntax)
- Add lock/unlock to all mutating operations (Install, Remove, Purge,
  Upgrade, Update)
- Add snack.TargetNames helper and formatTargets per provider
- apt: add FromRepo (-t) and Reinstall support
- dpkg: use Target.Source for .deb file paths in Install
2026-02-25 20:35:45 +00:00

87 lines
2.1 KiB
Go

// Package apt provides Go bindings for APT (Advanced Packaging Tool) on Debian/Ubuntu.
package apt
import (
"context"
"github.com/gogrlx/snack"
)
// Apt implements the snack.Manager interface using apt-get and apt-cache.
type Apt struct {
snack.Locker
}
// New returns a new Apt manager.
func New() *Apt {
return &Apt{}
}
// Name returns "apt".
func (a *Apt) Name() string { return "apt" }
// Install one or more packages.
func (a *Apt) Install(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) error {
a.Lock()
defer a.Unlock()
return install(ctx, pkgs, opts...)
}
// Remove one or more packages.
func (a *Apt) Remove(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) error {
a.Lock()
defer a.Unlock()
return remove(ctx, pkgs, opts...)
}
// Purge one or more packages including config files.
func (a *Apt) Purge(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) error {
a.Lock()
defer a.Unlock()
return purge(ctx, pkgs, opts...)
}
// Upgrade all installed packages.
func (a *Apt) Upgrade(ctx context.Context, opts ...snack.Option) error {
a.Lock()
defer a.Unlock()
return upgrade(ctx, opts...)
}
// Update refreshes the package index.
func (a *Apt) Update(ctx context.Context) error {
a.Lock()
defer a.Unlock()
return update(ctx)
}
// List returns all installed packages.
func (a *Apt) List(ctx context.Context) ([]snack.Package, error) {
return list(ctx)
}
// Search queries the package index.
func (a *Apt) Search(ctx context.Context, query string) ([]snack.Package, error) {
return search(ctx, query)
}
// Info returns details about a specific package.
func (a *Apt) Info(ctx context.Context, pkg string) (*snack.Package, error) {
return info(ctx, pkg)
}
// IsInstalled reports whether a package is currently installed.
func (a *Apt) IsInstalled(ctx context.Context, pkg string) (bool, error) {
return isInstalled(ctx, pkg)
}
// Version returns the installed version of a package.
func (a *Apt) Version(ctx context.Context, pkg string) (string, error) {
return version(ctx, pkg)
}
// Available reports whether apt-get is present on the system.
func (a *Apt) Available() bool {
return available()
}