mirror of
https://github.com/Graylog2/graylog-project-cli.git
synced 2026-03-13 08:02:57 +08:00
Make sure utils.GetCwd() does not return a symlink
Always resolve the symlinks before returning the current working directory name. Functions like filepath.Walk do not handle symlinks well. Found out the hard way by @kroepke - Thanks!
This commit is contained in:
@@ -17,7 +17,14 @@ func GetCwd() string {
|
||||
logger.Fatal("Unable to get current directory: %v", err)
|
||||
}
|
||||
|
||||
return currentDir
|
||||
// Make sure to resolve any symlinks and get the real directory.
|
||||
// Functions like filepath.Walk do not handle symlinks well...
|
||||
dir, err := filepath.EvalSymlinks(currentDir)
|
||||
if err != nil {
|
||||
logger.Fatal("Unable to eval symlink for %v: %v", currentDir, err)
|
||||
}
|
||||
|
||||
return dir
|
||||
}
|
||||
|
||||
func Chdir(path string) {
|
||||
@@ -31,10 +38,7 @@ func GetRelativePath(path string) string {
|
||||
return path
|
||||
}
|
||||
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
logger.Fatal("Unable to get current working directory")
|
||||
}
|
||||
cwd := GetCwd()
|
||||
relPath, err := filepath.Rel(cwd, path)
|
||||
if err != nil {
|
||||
logger.Fatal("Unable to get relative path for %v", path)
|
||||
|
||||
Reference in New Issue
Block a user