Skip to content

Commit eaa5c45

Browse files
committed
dbeaver/dbeaver-devops#2017 add podman to user's PATH
1 parent 012a42f commit eaa5c45

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

app/app.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (a *App) tryInstallingViaInstaller(d Dependency) bool {
208208
return false
209209
}
210210
if installerInfo.defaultExecutableDir.IsPresent {
211-
if err := ensureDirInPath(installerInfo.defaultExecutableDir.Value); err != nil {
211+
if err := ensureDirInRuntimePath(installerInfo.defaultExecutableDir.Value); err != nil {
212212
slog.Warn("error while adding a newly installed (via installer) dependency to PATH", "error", err, "dependency", d)
213213
}
214214
}
@@ -261,16 +261,17 @@ func (a *App) tryInstallingFromArchive(d Dependency) bool {
261261
return false
262262
}
263263
unzipPath := a.findUnzipPath(archiveInfo.url)
264+
a.printer.Println("Extracting...")
264265
if err := unzipFile(archive, unzipPath); err != nil {
265266
slog.Warn("unable to unzip the archive", "dependency", d, "error", err, "archive path", archive, "unzip path", unzipPath)
266267
return false
267268
}
268269
// Updating PATH
269270
pathElements := make([]string, 0, len(archiveInfo.executableSubpath)+1)
270271
pathElements = append(pathElements, unzipPath)
271-
copy(pathElements[1:], archiveInfo.executableSubpath)
272+
pathElements = append(pathElements, archiveInfo.executableSubpath...)
272273
pathToDirWithDependency := filepath.Join(pathElements...)
273-
if err := ensureDirInPath(pathToDirWithDependency); err != nil {
274+
if err := ensureDirInUserPath(pathToDirWithDependency); err != nil {
274275
slog.Warn("unable to add dependency to PATH", "dependency", d, "error", err)
275276
a.printer.PrintErrf("unable to add %s (%s) to PATH; consider adding it manually"+lib.NewLine(), d, pathToDirWithDependency)
276277
}

app/utils.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"os"
1414
"os/exec"
1515
"path/filepath"
16+
"runtime"
1617
"slices"
1718
"strings"
1819
)
@@ -84,7 +85,29 @@ func unzipElement(file *zip.File, destDir string) error {
8485
return nil
8586
}
8687

87-
func ensureDirInPath(dir string) error {
88+
func ensureDirInUserPath(dir string) error {
89+
if runtime.GOOS != "windows" {
90+
return errors.New("setting PATH is not implemented for this OS")
91+
}
92+
cmd := exec.Command("powershell", "-Command", "[Environment]::GetEnvironmentVariable('Path','User')")
93+
output, err := cmd.Output()
94+
if err != nil {
95+
return lib.WrapError("unable to get user PATH from powershell", err)
96+
}
97+
userPath := strings.TrimSpace(string(output))
98+
pathMembers := strings.Split(userPath, string(os.PathListSeparator))
99+
if slices.Contains(pathMembers, dir) {
100+
return nil
101+
}
102+
newPath := dir + string(os.PathListSeparator) + userPath
103+
setCmd := exec.Command("powershell", "-Command", fmt.Sprintf("[Environment]::SetEnvironmentVariable('Path','%s','User')", newPath))
104+
if err := setCmd.Run(); err != nil {
105+
return lib.WrapError("unable to set user PATH from powershell", err)
106+
}
107+
return nil
108+
}
109+
110+
func ensureDirInRuntimePath(dir string) error {
88111
currentPath := os.Getenv("PATH")
89112
currentPathMembers := strings.Split(currentPath, string(os.PathListSeparator))
90113
if slices.Contains(currentPathMembers, dir) {

0 commit comments

Comments
 (0)