From 8572aa5222d24b5bc3b984a17da52d8439a3cda7 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Thu, 27 Feb 2020 23:14:36 +0100 Subject: [PATCH] Preserve cache data from deletion during uninstall --- cmd/install.go | 11 ++++++----- pkg/installer/installer.go | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index 017aaf1f..c54f5265 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -82,11 +82,12 @@ var installCmd = &cobra.Command{ Debug("Solver", LuetCfg.GetSolverOptions().CompactString()) inst := installer.NewLuetInstaller(installer.LuetInstallerOptions{ - Concurrency: LuetCfg.GetGeneral().Concurrency, - SolverOptions: *LuetCfg.GetSolverOptions(), - NoDeps: nodeps, - Force: force, - OnlyDeps: onlydeps, + Concurrency: LuetCfg.GetGeneral().Concurrency, + SolverOptions: *LuetCfg.GetSolverOptions(), + NoDeps: nodeps, + Force: force, + OnlyDeps: onlydeps, + PreserveSystemEssentialData: true, }) inst.Repositories(repos) diff --git a/pkg/installer/installer.go b/pkg/installer/installer.go index f0498f98..e4c927d5 100644 --- a/pkg/installer/installer.go +++ b/pkg/installer/installer.go @@ -21,6 +21,7 @@ import ( "os/exec" "path/filepath" "sort" + "strings" "sync" "github.com/ghodss/yaml" @@ -36,11 +37,12 @@ import ( ) type LuetInstallerOptions struct { - SolverOptions config.LuetSolverOptions - Concurrency int - NoDeps bool - OnlyDeps bool - Force bool + SolverOptions config.LuetSolverOptions + Concurrency int + 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)