Debian Codegraph @

browserpass-native/request/common.go

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