1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
package request
import (
"errors"
"os"
"path/filepath"
"strings"
)
func normalizePasswordStorePath(storePath string) (string, error) {
if storePath == "" {
return "", errors.New("The store path cannot be empty")
}
if strings.HasPrefix(storePath, "~/") {
storePath = filepath.Join("$HOME", storePath[2:])
}
storePath = os.ExpandEnv(storePath)
directStorePath, err := filepath.EvalSymlinks(storePath)
if err != nil {
return "", err
}
storePath = directStorePath
stat, err := os.Stat(storePath)
if err != nil {
return "", err
}
if !stat.IsDir() {
return "", errors.New("The specified path exists, but is not a directory")
}
return storePath, nil
}
|