Preserve cache data from deletion during uninstall

This commit is contained in:
Ettore Di Giacinto
2020-02-27 23:14:36 +01:00
parent 0e0c2f21a6
commit 8572aa5222
2 changed files with 22 additions and 11 deletions

View File

@@ -87,6 +87,7 @@ var installCmd = &cobra.Command{
NoDeps: nodeps,
Force: force,
OnlyDeps: onlydeps,
PreserveSystemEssentialData: true,
})
inst.Repositories(repos)

View File

@@ -21,6 +21,7 @@ import (
"os/exec"
"path/filepath"
"sort"
"strings"
"sync"
"github.com/ghodss/yaml"
@@ -41,6 +42,7 @@ type LuetInstallerOptions struct {
NoDeps bool
OnlyDeps bool
Force bool
PreserveSystemEssentialData bool
}
type LuetInstaller struct {
@@ -375,7 +377,15 @@ func (l *LuetInstaller) uninstall(p pkg.Package, s *System) error {
// Remove from target
for _, f := range files {
target := filepath.Join(s.Target, f)
Info("Removing", target)
Debug("Removing", target)
if l.Options.PreserveSystemEssentialData &&
strings.HasPrefix(f, config.LuetCfg.GetSystem().GetSystemPkgsCacheDirPath()) ||
strings.HasPrefix(f, config.LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath()) {
Warning("Preserve ", f, " which is required by luet ( you have to delete it manually if you really need to)")
continue
}
err := os.Remove(target)
if err != nil {
Warning("Failed removing file (not present in the system target ?)", target)