Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we always put app bundle updates in the bin directory #977

Merged
merged 1 commit into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/autoupdate/findnew.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,28 @@ func FindBaseDir(path string) string {
return ""
}

// If this is an app bundle installation, we need to adjust the directory -- otherwise we end up with a library
// of updates at /usr/local/<identifier>/Kolide.app/Contents/MacOS/launcher-updates.
if strings.Contains(path, "Kolide.app") {
components := strings.SplitN(path, "Kolide.app", 2)
baseDir := filepath.Dir(components[0])

// If baseDir still contains an update directory (i.e. the original path was something like
// /usr/local/<identifier>/launcher-updates/<timestamp>/Kolide.app/Contents/MacOS/launcher),
// then strip the update directory out.
if strings.Contains(baseDir, updateDirSuffix) {
baseDirComponents := strings.SplitN(baseDir, updateDirSuffix, 2)
baseDir = filepath.Dir(baseDirComponents[0])
}

// We moved the Kolide.app installation out of the bin directory, but we want the bin directory
// here -- so put the "bin" suffix back on if needed.
if !strings.HasSuffix(baseDir, "bin") {
baseDir = filepath.Join(baseDir, "bin")
}
return baseDir
}

components := strings.SplitN(path, updateDirSuffix, 2)
return filepath.Dir(components[0])
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/autoupdate/findnew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ func TestFindBaseDir(t *testing.T) {
out string
}{
{in: "", out: ""},
{in: "/a/path/launcher", out: filepath.Clean("/a/path")},
{in: "/a/path/launcher-updates/1569339163/launcher", out: filepath.Clean("/a/path")},
{in: "/a/path/bin/launcher", out: filepath.Clean("/a/path/bin")},
{in: "/a/path/bin/launcher-updates/1569339163/launcher", out: filepath.Clean("/a/path/bin")},
{in: "/a/path/bin/launcher-updates/1569339163/Kolide.app/Contents/MacOS/launcher", out: filepath.Clean("/a/path/bin")},
{in: "/a/path/Kolide.app/Contents/MacOS/launcher", out: filepath.Clean("/a/path/bin")},
{in: "/a/path/Kolide.app/Contents/MacOS/launcher-updates/1569339163/Kolide.app/Contents/MacOS/launcher", out: filepath.Clean("/a/path/bin")},
{in: "/a/path/bin/Kolide.app/Contents/MacOS/launcher", out: filepath.Clean("/a/path/bin")},
{in: "/a/path/bin/Kolide.app/Contents/MacOS/launcher-updates/1569339163/Kolide.app/Contents/MacOS/launcher", out: filepath.Clean("/a/path/bin")},
}

for _, tt := range tests {
Expand Down