Skip to content

Commit

Permalink
state update should clean up after itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-as committed Dec 19, 2023
1 parent b49e8c3 commit 5eaa8fc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/gofrs/flock"

Expand All @@ -22,6 +23,7 @@ import (
"github.com/ActiveState/cli/internal/installation/storage"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/internal/multilog"
"github.com/ActiveState/cli/internal/osutils"
"github.com/ActiveState/cli/internal/rtutils/ptr"
)
Expand Down Expand Up @@ -230,6 +232,19 @@ func (u *UpdateInstaller) InstallBlocking(installTargetPath string, args ...stri
return errs.Wrap(err, "Could not run installer")
}

// installerPath looks like "<tempDir>/state-update\d{10}/state-install/state-installer".
logging.Debug("Cleaning up temporary update directory: %s", updateDir)
updateDir := filepath.Dir(filepath.Dir(installerPath))
if strings.HasPrefix(filepath.Base(updateDir), "state-update") {
err = os.RemoveAll(updateDir)
if err != nil {
multilog.Error("Unable to remove update directory '%s': %v", updateDir, err)
}
} else {
multilog.Error("Update directory structure has changed without updating it here, too. "+
"installerPath: %s\nupdateDir: %s\nExpected a 'state-update' prefix for the latter", installerPath, updateDir)
}

u.analyticsEvent(anaConst.ActUpdateInstall, anaConst.UpdateLabelSuccess, "")

return nil
Expand Down

0 comments on commit 5eaa8fc

Please sign in to comment.