Skip to content

Commit

Permalink
Merge pull request #2963 from ActiveState/mitchell/dx-767
Browse files Browse the repository at this point in the history
`state update` should clean up after itself.
  • Loading branch information
mitchell-as authored Dec 20, 2023
2 parents b49e8c3 + 55bf4a9 commit fc6d0d1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 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,20 @@ 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".
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
Expand Down

0 comments on commit fc6d0d1

Please sign in to comment.