Skip to content

Commit

Permalink
Merge branch version/0-43-0-RC1 to adopt changes from PR #2920
Browse files Browse the repository at this point in the history
  • Loading branch information
as-builds committed Dec 5, 2023
2 parents f78694d + d07be32 commit a0ad8b1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 22 deletions.
6 changes: 6 additions & 0 deletions cmd/state-installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func (i *Installer) Install() (rerr error) {

// Copy all the files except for the current executable
if err := fileutils.CopyAndRenameFiles(i.payloadPath, i.path, filepath.Base(osutils.Executable())); err != nil {
if osutils.IsAccessDeniedError(err) {
// If we got to this point, we could not copy and rename over existing files.
// This is a permission issue. (We have an installer test for copying and renaming over a file
// in use, which does not raise an error.)
return locale.WrapInputError(err, "err_update_access_denied", "", errs.JoinMessage(err))
}
return errs.Wrap(err, "Failed to copy installation files to dir %s. Error received: %s", i.path, errs.JoinMessage(err))
}

Expand Down
53 changes: 53 additions & 0 deletions cmd/state-installer/test/integration/installer_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,59 @@ func (suite *InstallerIntegrationTestSuite) TestInstallerOverwriteServiceApp() {
cp.ExpectExit() // the return code can vary depending on shell (e.g. zsh vs. bash); just assert the installer shell exited
}

func (suite *InstallerIntegrationTestSuite) TestInstallWhileInUse() {
suite.OnlyRunForTags(tagsuite.Installer)
if runtime.GOOS != "windows" {
suite.T().Skip("Only windows can have issues with copying over files in use")
}

ts := e2e.New(suite.T(), false)
defer ts.Close()

dir, err := ioutil.TempDir("", "system*")
suite.NoError(err)

cp := ts.SpawnCmdWithOpts(
suite.installerExe,
e2e.OptArgs(installationDir(ts)),
e2e.OptAppendEnv(constants.DisableUpdates+"=true"),
e2e.OptAppendEnv(fmt.Sprintf("%s=%s", constants.OverwriteDefaultSystemPathEnvVarName, dir)),
)
cp.Expect("successfully installed", e2e.RuntimeSourcingTimeoutOpt)
cp.ExpectInput()
cp.SendLine("state checkout ActiveState/Perl-5.32")
cp.Expect("Checked out")
cp.SendLine("state shell Perl-5.32")
cp.Expect("Activated") // state.exe remains active

// On Windows we cannot delete files/executables in use. Instead, the installer copies new
// executables into the target directory with the ".new" suffix and renames them to the target
// executables. Verify that this works without error.
cp2 := ts.SpawnCmdWithOpts(
suite.installerExe,
e2e.OptArgs(installationDir(ts), "-f"),
e2e.OptAppendEnv(constants.DisableUpdates+"=true"),
e2e.OptAppendEnv(fmt.Sprintf("%s=%s", constants.OverwriteDefaultSystemPathEnvVarName, dir)),
)
cp2.Expect("successfully installed", e2e.RuntimeSourcingTimeoutOpt)
cp2.ExpectInput()
cp2.SendLine("exit")
cp2.ExpectExit() // the return code can vary depending on shell (e.g. zsh vs. bash); just assert the installer shell exited

oldStateExeFound := false
for _, file := range fileutils.ListDirSimple(filepath.Join(installationDir(ts), "bin"), false) {
if strings.Contains(file, "state.exe") && strings.HasSuffix(file, ".old") {
oldStateExeFound = true
break
}
}
suite.Assert().True(oldStateExeFound, "the state.exe currently in use was not copied to a '.old' file")

cp.SendLine("exit") // state shell
cp.SendLine("exit") // installer shell
cp.ExpectExit() // the return code can vary depending on shell (e.g. zsh vs. bash); just assert the installer shell exited
}

func (suite *InstallerIntegrationTestSuite) AssertConfig(ts *e2e.Session) {
if runtime.GOOS != "windows" {
// Test bashrc
Expand Down
30 changes: 8 additions & 22 deletions internal/locale/locales/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -762,27 +762,6 @@ installer_err_runtime_executable_not_exec:
other: Executable '[NOTICE]{{.V1}}[/RESET]' does not have execute permissions for runtime '[NOTICE]{{.V0}}[/RESET]'
installer_err_fail_obtain_prefixes:
other: Unable to obtain relocation prefixes for runtime '[NOTICE]{{.V0}}[/RESET]'
installer_err_runtime_already_exists:
other: A runtime is already installed at '[NOTICE]{{.V0}}[/RESET]'
installer_err_runtime_move_files_access_denied:
other: |
Unable to move runtime files. Please ensure that you have write permissions for the directory '[NOTICE]{{.V0}}[/RESET]'
If you believe this is happening due to antivirus software please report your issue on our forums:
[ACTIONABLE]{{.V1}}[/RESET]
installer_err_runtime_move_files_failed:
other: Unable to move runtime files from '[NOTICE]{{.V0}}[/RESET]' to '[NOTICE]{{.V1}}[/RESET]'
installer_err_runtime_rm_installdir:
other: Unable to remove '[NOTICE]{{.V0}}[/RESET]' after unpacking runtime
installer_err_runtime_no_commitid:
other: A CommitID is required to install this runtime environment
fetch_err_runtime_no_commitid:
other: Could not get a CommitID for this project
installer_err_runtime_preplatform:
other: The version of the installer used in the project you specified is not compatible with the State Tool. Please make a new project.
installer_err_engine_unknown:
other: Build engine is unknown.
build_status_unknown:
other: "Build status could not be retrieved, please view the project at: [NOTICE]{{.V0}}[/RESET] for more information"
build_status_in_progress:
other: "Your changes are currently being built remotely on the ActiveState Platform. Please visit [NOTICE]{{.V0}}[/RESET] to see the progress."
build_status_unknown_error:
Expand Down Expand Up @@ -1938,7 +1917,14 @@ err_insufficient_permissions:
other: |
Could not stop running State Tool process due to insufficient permissions.
State Tool works best if you run it as a user, rather than an admin. You might be encountering this issue because you have originally installed or ran the State Tool as admin. If this is the case it is suggested that you uninstall the State Tool as admin, and install it again as a user.
State Tool works best if you run it as a user, rather than an administrator. You might be encountering this issue because you have originally installed or ran the State Tool as an administrator. If this is the case it is suggested that you uninstall the State Tool as an administrator, and install it again as a user.
err_update_access_denied:
other: |
Could not update the State Tool due to insufficient permissions in the installation folder.
State Tool works best if you run it as a user, rather than an administrator. You might be encountering this issue because you have originally installed or ran the State Tool as an administrator. If this is the case it is suggested that you uninstall the State Tool as an administrator, and install it again as a user.
Error received: {{.V0}}
err_search_no_package:
other: |
No packages in our catalog match [NOTICE]"{{.V0}}"[/RESET].
Expand Down

0 comments on commit a0ad8b1

Please sign in to comment.