Skip to content

Commit c95b6d5

Browse files
author
Samuel Vandamme
committed
Added latest version 2.7.6
1 parent a19dac0 commit c95b6d5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/coscale/command/command.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ Use "coscale-cli [object] <help>" for more information about a command.
199199

200200
// GetConfigPath is used to return the absolut path of the api configuration file
201201
func GetConfigPath() (string, error) {
202+
var carriageReturn string
202203
configFile := "/api.conf"
203204
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
204205
if err != nil {
@@ -211,15 +212,29 @@ func GetConfigPath() (string, error) {
211212
var cmdName string
212213
if runtime.GOOS == "windows" {
213214
cmdName = "where"
215+
carriageReturn = "\r\n"
214216
} else {
215217
cmdName = "which"
218+
carriageReturn = "\n"
216219
}
217220
response, err := GetCommandOutput(cmdName, 2*time.Second, os.Args[0])
218-
path := bytes.Split(response, []byte("\n"))[0]
221+
path := string(bytes.Split(response, []byte(carriageReturn))[0])
219222
if err != nil {
220223
return "", err
221224
}
222-
return filepath.Dir(string(path)) + configFile, nil
225+
// check if is a symlink
226+
file, err := os.Lstat(path)
227+
if err != nil {
228+
return "", err
229+
}
230+
if file.Mode()&os.ModeSymlink == os.ModeSymlink {
231+
// This is a symlink
232+
path, err = filepath.EvalSymlinks(path)
233+
if err != nil {
234+
return "", err
235+
}
236+
}
237+
return filepath.Dir(path) + configFile, nil
223238
}
224239

225240
// GetCommandOutput returns stdout of command as a string

0 commit comments

Comments
 (0)