From 05bcb7105f7386550811e04f8551f1c73a4a4224 Mon Sep 17 00:00:00 2001 From: Michal Gorecki Date: Fri, 8 Mar 2024 10:20:10 +0100 Subject: [PATCH] newt: Don't stop upgrade when some repos are in dirty state Now if force flag is not set, only repos in dirty state will not get upgraded. The rest of the repos will be upgraded. --- newt/install/install.go | 62 +++++++++++------------------------------ 1 file changed, 17 insertions(+), 45 deletions(-) diff --git a/newt/install/install.go b/newt/install/install.go index 8eebff098..708695ff6 100644 --- a/newt/install/install.go +++ b/newt/install/install.go @@ -342,7 +342,7 @@ func (inst *Installer) installPrompt(vm deprepo.VersionMap, op installOp, } util.StatusMessage(util.VERBOSITY_DEFAULT, - "Making the following changes to the project:\n") + "Trying to make the following changes to the project:\n") names := vm.SortedNames() for _, name := range names { @@ -488,46 +488,6 @@ func (inst *Installer) calcVersionMap(candidates []*repo.Repo) ( return vm, nil } -// Checks if any repos in the specified slice are in a dirty state. If any -// repos are dirty and `force` is *not* enabled, an error is returned. If any -// repos are dirty and `force` is enabled, a warning is displayed. -func verifyRepoDirtyState(repos []*repo.Repo, force bool) error { - // [repo] => dirty-state. - var m map[*repo.Repo]string - - // Collect all dirty repos and insert them into m. - for _, r := range repos { - dirtyState, err := r.DirtyState() - if err != nil { - return err - } - - if dirtyState != "" { - if m == nil { - m = make(map[*repo.Repo]string) - m[r] = dirtyState - } - } - } - - if len(m) > 0 { - s := "some repos are in a dirty state:\n" - for r, d := range m { - s += fmt.Sprintf(" %s: contains %s\n", r.Name(), d) - } - - if !force { - s += "Specify the `-f` (force) switch to attempt anyway" - return util.NewNewtError(s) - } else { - util.OneTimeWarning("%s", s) - } - } - - return nil - -} - func verifyNewtCompat(repos []*repo.Repo, vm deprepo.VersionMap) error { var errors []string @@ -554,10 +514,6 @@ func verifyNewtCompat(repos []*repo.Repo, vm deprepo.VersionMap) error { func (inst *Installer) Upgrade(candidates []*repo.Repo, force bool, ask bool) error { - if err := verifyRepoDirtyState(candidates, force); err != nil { - return err - } - vm, err := inst.calcVersionMap(candidates) if err != nil { return err @@ -591,6 +547,22 @@ func (inst *Installer) Upgrade(candidates []*repo.Repo, force bool, // Upgrade each repo in the version map. for _, r := range repos { destVer := vm[r.Name()] + dirtyState, err := r.DirtyState() + if err != nil { + return err + } + + if dirtyState != "" { + if !force { + util.StatusMessage(util.VERBOSITY_DEFAULT, + "%s is in dirty state, it won't be upgraded\n", + r.Name()) + continue + } else { + util.OneTimeWarning("forced update of repo in dirty state: %s", r.Name()) + } + } + if err := r.Upgrade(destVer); err != nil { return err }