Skip to content

Commit

Permalink
[Ingest Manager] Windows agent doesn't uninstall with a lowercase `c:…
Browse files Browse the repository at this point in the history
…` drive in the path (elastic#23998)

[Ingest Manager] Windows agent doesn't uninstall with a lowercase `c:` drive in the path  (elastic#23998)
  • Loading branch information
michalpristas authored Feb 11, 2021
1 parent 7b6f338 commit d1e8b25
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- Fixed reenroll scenario {pull}23686[23686]
- Fixed Monitoring filebeat and metricbeat not connecting to Agent over GRPC {pull}23843[23843]
- Fixed make status readable in the log. {pull}23849[23849]
- Windows agent doesn't uninstall with a lowercase `c:` drive in the path {pull}23998[23998]

==== New features

Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/agent/install/installed.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func RunningInstalled() bool {
execDir = filepath.Dir(filepath.Dir(execDir))
execPath = filepath.Join(execDir, execName)
}
return expected == execPath
return ArePathsEqual(expected, execPath)
}

// checkService only checks the status of the service.
Expand Down
5 changes: 5 additions & 0 deletions x-pack/elastic-agent/pkg/agent/install/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ const (
exec /opt/Elastic/Agent/elastic-agent $@
`
)

// ArePathsEqual determines whether paths are equal taking case sensitivity of os into account.
func ArePathsEqual(expected, actual string) bool {
return expected == actual
}
5 changes: 5 additions & 0 deletions x-pack/elastic-agent/pkg/agent/install/paths_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ const (
exec /Library/Elastic/Agent/elastic-agent $@
`
)

// ArePathsEqual determines whether paths are equal taking case sensitivity of os into account.
func ArePathsEqual(expected, actual string) bool {
return expected == actual
}
33 changes: 33 additions & 0 deletions x-pack/elastic-agent/pkg/agent/install/paths_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package install

import (
"runtime"
"testing"

"github.com/stretchr/testify/assert"
)

func TestEqual(t *testing.T) {
isWindows := runtime.GOOS == "windows"
testCases := []struct {
Name string
Expected string
Actual string
ShouldMatch bool
}{
{"different paths", "/var/path/a", "/var/path/b", false},
{"strictly same paths", "/var/path/a", "/var/path/a", true},
{"strictly same win paths", `C:\Program Files\Elastic\Agent`, `C:\Program Files\Elastic\Agent`, true},
{"case insensitive win paths", `C:\Program Files\Elastic\Agent`, `c:\Program Files\Elastic\Agent`, isWindows},
}

for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
assert.Equal(t, tc.ShouldMatch, ArePathsEqual(tc.Expected, tc.Actual))
})
}
}
7 changes: 7 additions & 0 deletions x-pack/elastic-agent/pkg/agent/install/paths_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package install

import "strings"

const (
// BinaryName is the name of the installed binary.
BinaryName = "elastic-agent.exe"
Expand All @@ -25,3 +27,8 @@ const (
// ShellWrapper is the wrapper that is installed.
ShellWrapper = "" // no wrapper on Windows
)

// ArePathsEqual determines whether paths are equal taking case sensitivity of os into account.
func ArePathsEqual(expected, actual string) bool {
return strings.EqualFold(expected, actual)
}

0 comments on commit d1e8b25

Please sign in to comment.