forked from cryptag/cryptag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
58 lines (46 loc) · 1.5 KB
/
path.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Steve Phillips / elimisteve
// 2015.11.14
package cryptag
import (
"log"
"os"
"path"
"runtime"
homedir "github.com/mitchellh/go-homedir"
)
var (
home, errHome = homedir.Dir()
// TrustedBasePath is where private, non-shared data (e.g., crypto
// keys) can be safely stored.
TrustedBasePath = path.Join(home, ".cryptag")
// BackendPath is the path to the directory where backend config
// files are stored (e.g., "/home/myusername/.cryptag/backends").
// This can be overridden with the BACKEND_PATH
// environment variable (rarely useful; this exists so that all
// CrypTag backend configs could be on a USB drive).
BackendPath = path.Join(home, ".cryptag", "backends")
// DefaultLocalDataPath is the default directory where local
// backends will be told to store their data. This directory will
// contain 'rows' and 'tags' subdirectories.
DefaultLocalDataPath = path.Join(home, ".cryptag")
LocalDataPath = DefaultLocalDataPath
)
func init() {
if errHome != nil {
log.Printf("Error getting/setting home directory path: %v\n", errHome)
}
if p := os.Getenv("BACKEND_PATH"); p != "" {
BackendPath = p
}
// Change LocalDataPath if apparently on Android
if runtime.GOOS == "linux" && runtime.GOARCH == "arm" {
androidStorage := "/storage/sdcard0"
if _, err := os.Stat(androidStorage); os.IsNotExist(err) {
LocalDataPath = androidStorage + "/.cryptag"
}
}
// Change LocalDataPath if on Sandstorm (useful for servers)
if os.Getenv("SANDSTORM") == "1" {
LocalDataPath = "/var"
}
}