Skip to content

Commit

Permalink
update relPath again
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAbides committed Dec 9, 2023
1 parent a6a2e8c commit f1f6493
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions internal/bindown/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ func createWrapper(name, target, bindownExec, cacheDir, configFile string, missi
if err != nil {
return "", err
}
wrapperDir, err = filepath.Abs(wrapperDir)
if err != nil {
return "", err
}
if bindownExec == "" {
bindownExec = "bindown"
} else {
Expand Down Expand Up @@ -149,10 +145,6 @@ func createWrapper(name, target, bindownExec, cacheDir, configFile string, missi
if err != nil {
return "", err
}
cacheDir, err = filepath.Abs(cacheDir)
if err != nil {
return "", err
}
cacheDir, err = relPath(wrapperDir, cacheDir)
if err != nil {
return "", err
Expand Down Expand Up @@ -218,23 +210,31 @@ func relPath(base, target string) (string, error) {
if err == nil {
return filepath.ToSlash(rel), nil
}
absBase, err := filepath.Abs(base)

// convert to abs and try again
base, err = filepath.Abs(base)
if err != nil {
return "", err
}
absBase, err = filepath.EvalSymlinks(absBase)
target, err = filepath.Abs(target)
if err != nil {
return "", err
}
absTarget, err := filepath.Abs(target)
rel, err = filepath.Rel(base, target)
if err == nil {
return filepath.ToSlash(rel), nil
}

// resolve symlinks and try again
base, err = filepath.EvalSymlinks(base)
if err != nil {
return "", err
}
absTarget, err = filepath.EvalSymlinks(absTarget)
target, err = filepath.EvalSymlinks(target)
if err != nil {
return "", err
}
rel, err = filepath.Rel(absBase, absTarget)
rel, err = filepath.Rel(base, target)
if err != nil {
return "", err
}
Expand Down

0 comments on commit f1f6493

Please sign in to comment.