mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
- 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
28 lines
847 B
Go
28 lines
847 B
Go
package snack
|
|
|
|
import "sync"
|
|
|
|
// Locker is an embeddable type that provides per-provider mutex locking.
|
|
// Each package manager backend should embed this in its struct to serialize
|
|
// mutating operations (Install, Remove, Purge, Upgrade, Update).
|
|
//
|
|
// Read-only operations (List, Search, Info, IsInstalled, Version) generally
|
|
// don't need the lock, but backends may choose to lock them if the underlying
|
|
// tool doesn't support concurrent reads.
|
|
//
|
|
// Different providers use independent locks, so an apt Install and a snap
|
|
// Install can run concurrently, but two apt Installs will serialize.
|
|
type Locker struct {
|
|
mu sync.Mutex
|
|
}
|
|
|
|
// Lock acquires the provider lock. Call before mutating operations.
|
|
func (l *Locker) Lock() {
|
|
l.mu.Lock()
|
|
}
|
|
|
|
// Unlock releases the provider lock. Defer after Lock.
|
|
func (l *Locker) Unlock() {
|
|
l.mu.Unlock()
|
|
}
|