diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-07 00:17:27 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-07 00:17:27 +0300 |
| commit | ab6e1341dc5eb06b6573571f8c17e19d0c393418 (patch) | |
| tree | f9aa00bf0cf3ab302ecb2d152f7e781793112ba5 /internal/resource/pkg/dnf.go | |
| parent | 62ff4e782bc057d277a7c41fa35a665e2aeca045 (diff) | |
can manage dnf packages
Diffstat (limited to 'internal/resource/pkg/dnf.go')
| -rw-r--r-- | internal/resource/pkg/dnf.go | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/internal/resource/pkg/dnf.go b/internal/resource/pkg/dnf.go index ad03da2..e970b10 100644 --- a/internal/resource/pkg/dnf.go +++ b/internal/resource/pkg/dnf.go @@ -2,23 +2,21 @@ package pkg import ( "fmt" - "log" "codeberg.org/snonux/gonf/internal/exec" ) -func applyDNF(name string, ensure Ensure) error { +func applyDNF(p *Package) error { var args []string - switch ensure { - case PkgPresent: - args = []string{"install", "-y", name} - case PkgAbsent: - args = []string{"remove", "-y", name} - case PkgLatest: - args = []string{"install", "-y", name} - default: - log.Fatalf("unsupported ensure state: %v", ensure) + if p.absent { + args = []string{"remove", "-y", p.name} + } else if p.latest { + // update ensures the package is installed and updated to the latest version. + args = []string{"update", "-y", p.name} + } else { + // install ensures the package is installed, but does not update it if already present. + args = []string{"install", "-y", p.name} } stdout, stderr, exitCode, err := exec.Run("dnf", args...) |
