8000 When getting project directory, ensure it runs through EvalSymlink · symfony-cli/symfony-cli@adc81de · GitHub
[go: up one dir, main page]

Skip to content

Commit adc81de

Browse files
committed
When getting project directory, ensure it runs through EvalSymlink
1 parent d09ad2d commit adc81de

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

commands/root.go

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,50 @@ func initConfig() {
198198
}
199199

200200
func getProjectDir(dir string) (string, error) {
201+
202+
var projDir string
203+
201204
if dir != "" {
202-
if filepath.IsAbs(dir) {
203-
return dir, nil
205+
// Get Absolute Path
206+
absPath, err := getAbsPath(dir)
207+
if err != nil {
208+
return "", err
204209
}
205-
return filepath.Abs(dir)
210+
projDir = absPath
211+
212+
} else {
213+
// Get Current Working Dir
214+
cwd, err := os.Getwd()
215+
if err != nil {
216+
return "", err
217+
}
218+
projDir = cwd
219+
}
220+
// Let us evaluate the symlinks
221+
realPath, err := filepath.EvalSymlinks(projDir)
222+
if err != nil {
223+
return "", err
206224
}
207-
return os.Getwd()
225+
226+
return realPath, nil
227+
}
228+
229+
// Given any path, find its absolute path
230+
func getAbsPath(path string) (string, error) {
231+
232+
var absPath string
233+
234+
if filepath.IsAbs(path) {
235+
// Already absolute path
236+
absPath < 70C2 span class=pl-c1>= path
237+
} else {
238+
// Convert path from relative to absolute
239+
newPath, err := filepath.Abs(path)
240+
if err != nil {
241+
return "", err
242+
}
243+
absPath = newPath
244+
}
245+
246+
return absPath, nil
208247
}

0 commit comments

Comments
 (0)
0