-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
46 lines (37 loc) · 802 Bytes
/
util.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
package agilis
import (
"fmt"
"os"
)
const filePerms = 0777
// FolderPath returns the folder path of a database
func (db Database) FolderPath() (p string, err error) {
dir, err := os.UserHomeDir()
if err != nil {
return
}
p = fmt.Sprintf("%s/agilis/%s/", dir, db.Name)
return
}
// DefaultPath returns the path of a database (not minified)
func (db Database) DefaultPath() (p string, err error) {
dir, err := db.FolderPath()
if err != nil {
return
}
p = dir + db.Name
return
}
// MinifiedPath returns the path of a database (minified version)
func (db Database) MinifiedPath() (p string, err error) {
dir, err := db.DefaultPath()
if err != nil {
return
}
p = dir + "__m"
return
}
func fileExists(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err)
}