-
-
Notifications
You must be signed in to change notification settings - Fork 120
Evaluate symlinks when determining project directory #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
commands/root.go
Outdated
func getAbsPath(path string) (string, error) { | ||
|
||
var absPath string | ||
|
||
if filepath.IsAbs(path) { | ||
// Already absolute path | ||
absPath = path | ||
} else { | ||
// Convert path from relative to absolute | ||
newPath, err := filepath.Abs(path) | ||
if err != nil { | ||
return "", err | ||
} | ||
absPath = newPath | ||
} | ||
|
||
return absPath, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Abs
is already checking if path is absolute (https://github.com/golang/go/blob/5a040c5a3678857f03e77822956c916e8274b2c3/src/path/filepath/path.go#L243-L256).
So I would directly use is result instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. Redundant code. I'll remove
commands/root.go
Outdated
// Get Current Working Dir | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
return "", err | ||
} | ||
projDir = cwd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because filepath.Abs
is already taking care of using current working directory if required (see https://github.com/golang/go/blob/5a040c5a3678857f03e77822956c916e8274b2c3/src/path/filepath/path.go#L243-L256 for Unix and https://github.com/golang/go/blob/5a040c5a3678857f03e77822956c916e8274b2c3/src/path/filepath/path_windows.go#L140-L145 for Windows) we can just use the empty value to get current working directory, something like this:
var err error
if path, err = filepath.Abs(path); err != nil {
return "", err
}
return filepath.EvalSymlinks(path)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your insight. I'll make the change you suggested
This PR aims ro resolve #104:
EvalSymlinks
getAbsPath
) for clarity@fabpot Can you please review