10000 Evaluate symlinks when determining project directory by kinekt4 · Pull Request #115 · symfony-cli/symfony-cli · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 2 commits into from
Mar 12, 2022

Conversation

kinekt4
Copy link
Contributor
@kinekt4 kinekt4 commented Mar 10, 2022

This PR aims ro resolve #104:

  • I ensured that the function that retrieves the project directory runs the path through EvalSymlinks
  • I also refactored getting the absolute dir into it's own function (getAbsPath) for clarity

@fabpot Can you please review

commands/root.go Outdated
Comment on lines 230 to 246
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
Copy link
Member

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.

Copy link
Contributor Author

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
Comment on lines 213 to 218
// Get Current Working Dir
cwd, err := os.Getwd()
if err != nil {
return "", err
}
projDir = cwd
Copy link
Member

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)

Copy link
Contributor Author

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

@fabpot fabpot merged commit c1fef56 into symfony-cli:main Mar 12, 2022
@kinekt4 kinekt4 deleted the dir-path-resolution branch March 15, 2022 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Symfony server directory resolution issue
3 participants
0