File: common.go

package info (click to toggle)
browserpass 3.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 4,836 kB
  • sloc: javascript: 80,027; makefile: 544
file content (34 lines) | stat: -rw-r--r-- 679 bytes parent folder | download
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
}