Skip to content

Commit

Permalink
Merge pull request #3414 from ActiveState/mitchell/dx-2870
Browse files Browse the repository at this point in the history
Only remove the installation.InstallDirMarker after binaries were successfully removed.
  • Loading branch information
mitchell-as authored Jul 24, 2024
2 parents c48dd8b + c2004ed commit 792d654
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
24 changes: 13 additions & 11 deletions internal/assets/contents/scripts/removePaths.bat
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ echo "Waiting for process %exe% with PID %pid% to end..." >> %logfile%
echo "Process %exe% has ended" >> %logfile%
set success=true
for %%i in (%paths%) do (
echo "Attempting to remove path %%i" >> %logfile%
if exist "%%i\" (
rmdir /s /q %%i 2>>&1 >> %logfile%
) else if exist "%%i" (
del /f /q %%i 2>>&1 >> %logfile%
)
if exist "%%i" (
echo "Could not remove path: %%i" >> %logfile%
set success=false
) else (
echo "Successfully removed path %%i" >> %logfile%
if "%success%"=="true" (
echo "Attempting to remove path %%i" >> %logfile%
if exist "%%i\" (
rmdir /s /q %%i 2>>&1 >> %logfile%
) else if exist "%%i" (
del /f /q %%i 2>>&1 >> %logfile%
)
if exist "%%i" (
echo "Could not remove path: %%i" >> %logfile%
set success=false
) else (
echo "Successfully removed path %%i" >> %logfile%
)
)
)

Expand Down
5 changes: 2 additions & 3 deletions internal/runners/clean/run_lin_mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,13 @@ func cleanInstallDir(dir string, cfg *config.Instance) error {
}

var asFiles = []string{
installation.InstallDirMarker,
constants.StateInstallerCmd + osutils.ExeExtension,
}

// Remove all of the state tool executables and finally the
// bin directory
// Remove all of the state tool executables, bin directory, and finally the install marker.
asFiles = append(asFiles, execs...)
asFiles = append(asFiles, installation.BinDirName)
asFiles = append(asFiles, installation.InstallDirMarker)

for _, file := range asFiles {
f := filepath.Join(dir, file)
Expand Down
9 changes: 7 additions & 2 deletions internal/runners/clean/run_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,19 @@ func removeInstall(logFile string, params *UninstallParams, cfg *config.Instance
return locale.WrapError(err, "err_state_exec")
}

// Schedule removal of the entire install directory.
// Schedule ordered removal of the entire install directory.
// This is because Windows often thinks the installation.InstallDirMarker and
// constants.StateInstallerCmd files are still in use.
installDir, err := installation.InstallPathFromExecPath()
if err != nil {
return errs.Wrap(err, "Could not get installation path")
}
paths := []string{stateExec, installDir}
paths := []string{
stateExec,
filepath.Join(installDir, installation.BinDirName),
filepath.Join(installDir, installation.InstallDirMarker), // should be after bin
installDir,
}
if params.All {
paths = append(paths, cfg.ConfigPath()) // also remove the config directory
}
Expand Down

0 comments on commit 792d654

Please sign in to comment.