Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/xanzy/go-gitlab v0.115.0
golang.org/x/crypto v0.32.0
golang.org/x/oauth2 v0.25.0
golang.org/x/sys v0.29.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -24,6 +25,5 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/time v0.9.0 // indirect
)
3 changes: 1 addition & 2 deletions internal/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internal

import (
"os"
"path/filepath"
)

// GetExecutablePath returns the path of the executable file with all symlinks resolved.
Expand All @@ -12,7 +11,7 @@ func GetExecutablePath() (string, error) {
return "", err
}

exe, err = filepath.EvalSymlinks(exe)
exe, err = ResolvePath(exe)
if err != nil {
return "", err
}
Expand Down
17 changes: 17 additions & 0 deletions internal/resolve_path_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build !windows

package internal

import (
"path/filepath"
)

// ResolvePath returns the path of a given filename with all symlinks resolved.
func ResolvePath(filename string) (string, error) {
finalPath, err := filepath.EvalSymlinks(filename)
if err != nil {
return "", err
}

return finalPath, nil
}
32 changes: 32 additions & 0 deletions internal/resolve_path_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build windows

package internal

import (
"golang.org/x/sys/windows"
"os"
"strings"
"syscall"
)

// ResolvePath returns the path of a given filename with all symlinks resolved.
func ResolvePath(filename string) (string, error) {
f, err := os.Open(filename)
if err != nil {
return "", err
}
defer f.Close()

handle := windows.Handle(f.Fd())
buf := make([]uint16, syscall.MAX_PATH)
_, err = windows.GetFinalPathNameByHandle(handle, &buf[0], uint32(len(buf)), 0)
if err != nil {
return "", err
}
final := syscall.UTF16ToString(buf)

// Strip possible "\\?\" prefix
final = strings.TrimPrefix(final, `\\?\`)

return final, nil
}
2 changes: 1 addition & 1 deletion update.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (up *Updater) UpdateCommand(ctx context.Context, cmdPath string, current st
return nil, fmt.Errorf("failed to stat '%s'. file may not exist: %s", cmdPath, err)
}
if stat.Mode()&os.ModeSymlink != 0 {
p, err := filepath.EvalSymlinks(cmdPath)
p, err := internal.ResolvePath(cmdPath)
if err != nil {
return nil, fmt.Errorf("failed to resolve symlink '%s' for executable: %s", cmdPath, err)
}
Expand Down