diff --git a/internal/updater/updater.go b/internal/updater/updater.go index 4d9ad9726d..a130a1edd1 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,20 @@ 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". + updateDir := filepath.Dir(filepath.Dir(installerPath)) + logging.Debug("Cleaning up temporary update directory: %s", updateDir) + 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 { + // Do not report to rollbar, but log the error for our integration tests to catch. + logging.Error("Did not remove temporary update directory. "+ + "installerPath: %s\nupdateDir: %s\nExpected a 'state-update' prefix for the latter", installerPath, updateDir) + } + u.analyticsEvent(anaConst.ActUpdateInstall, anaConst.UpdateLabelSuccess, "") return nil