Skip to content

Commit

Permalink
correctly identify retryable errors when uninstalling on Windows (#3317
Browse files Browse the repository at this point in the history
…) (#3324)

(cherry picked from commit 9727255)

Co-authored-by: Anderson Queiroz <[email protected]>
  • Loading branch information
mergify[bot] and AndersonQ authored Aug 29, 2023
1 parent bb495ea commit 49e6cb9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: bug-fix

# Change summary; a 80ish characters long description of the change.
summary: Correctly identify retryable errors when attempting to uninstall on Windows

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; a word indicating the component this changeset affects.
component: Uninstaller

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: https://github.com/owner/repo/1234

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
#issue: https://github.com/owner/repo/1234
4 changes: 2 additions & 2 deletions internal/pkg/agent/install/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func removePath(path string) error {
return nil
}

if isBlockingOnExe(err) {
// try to remove the blocking exe
if isAccessDeniedError(err) {
// might be blocking on exe, then try to remove the blocking exe
err = removeBlockingExe(err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/install/uninstall_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package install

func isBlockingOnExe(_ error) bool {
func isAccessDeniedError(_ error) bool {
return false
}

Expand Down
33 changes: 22 additions & 11 deletions internal/pkg/agent/install/uninstall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,31 @@ import (
"golang.org/x/sys/windows"
)

func isBlockingOnExe(err error) bool {
func isAccessDeniedError(err error) bool {
if err == nil {
return false
}
path, errno := getPathFromError(err)
if path == "" {
return false

var errno syscall.Errno
if errors.As(err, &errno) {
return errno == syscall.ERROR_ACCESS_DENIED
}
return errno == syscall.ERROR_ACCESS_DENIED

return false
}

func isRetryableError(err error) bool {
if err == nil {
return false
}
path, errno := getPathFromError(err)
if path == "" {
return false

var errno syscall.Errno
if errors.As(err, &errno) {
return errno == syscall.ERROR_ACCESS_DENIED ||
errno == windows.ERROR_SHARING_VIOLATION
}
return errno == syscall.ERROR_ACCESS_DENIED || errno == windows.ERROR_SHARING_VIOLATION

return false
}

func removeBlockingExe(blockingErr error) error {
Expand Down Expand Up @@ -72,14 +77,20 @@ func removeBlockingExe(blockingErr error) error {
return nil
}

func getPathFromError(blockingErr error) (string, syscall.Errno) {
func getPathFromError(err error) (string, syscall.Errno) {
var perr *fs.PathError
if errors.As(blockingErr, &perr) {
if errors.As(err, &perr) {
var errno syscall.Errno
if errors.As(perr.Err, &errno) {
return perr.Path, errno
}
}

var errno syscall.Errno
if errors.As(err, &errno) {
return "", errno
}

return "", 0
}

Expand Down

0 comments on commit 49e6cb9

Please sign in to comment.