From 5eaa8fccd05e895e8054c7c5a11cfb9d24ab5044 Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 19 Dec 2023 17:33:48 -0500 Subject: [PATCH] `state update` should clean up after itself. --- internal/updater/updater.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/updater/updater.go b/internal/updater/updater.go index 4d9ad9726d..de59a035d5 100644 --- a/internal/updater/updater.go +++ b/internal/updater/updater.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/gofrs/flock" @@ -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" ) @@ -230,6 +232,19 @@ func (u *UpdateInstaller) InstallBlocking(installTargetPath string, args ...stri return errs.Wrap(err, "Could not run installer") } + // installerPath looks like "/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