mirror of https://github.com/cheat/cheat.git
fix: resolves #474
Resolves #474, whereby `cheat` failed to resolve symlinks. The root cause was that `path/filepath#Walk` simply does not resolve symlinks: https://golang.org/pkg/path/filepath/#Walk
This commit is contained in:
parent
c47b7f81aa
commit
f7c093bec0
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
cp "github.com/cheat/cheat/internal/cheatpath"
|
cp "github.com/cheat/cheat/internal/cheatpath"
|
||||||
|
|
||||||
|
@ -38,14 +39,25 @@ func New(opts map[string]interface{}, confPath string) (Config, error) {
|
||||||
return Config{}, fmt.Errorf("could not unmarshal yaml: %v", err)
|
return Config{}, fmt.Errorf("could not unmarshal yaml: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// expand ~ in config paths
|
// process cheatpaths
|
||||||
for i, cheatpath := range conf.Cheatpaths {
|
for i, cheatpath := range conf.Cheatpaths {
|
||||||
|
|
||||||
|
// expand ~ in config paths
|
||||||
expanded, err := homedir.Expand(cheatpath.Path)
|
expanded, err := homedir.Expand(cheatpath.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Config{}, fmt.Errorf("failed to expand ~: %v", err)
|
return Config{}, fmt.Errorf("failed to expand ~: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// follow symlinks
|
||||||
|
expanded, err = filepath.EvalSymlinks(expanded)
|
||||||
|
if err != nil {
|
||||||
|
return Config{}, fmt.Errorf(
|
||||||
|
"failed to resolve symlink: %s, %v",
|
||||||
|
expanded,
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
conf.Cheatpaths[i].Path = expanded
|
conf.Cheatpaths[i].Path = expanded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue