-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProbe.go
More file actions
41 lines (35 loc) · 977 Bytes
/
Probe.go
File metadata and controls
41 lines (35 loc) · 977 Bytes
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
package boxes
import (
"errors"
"os"
"path/filepath"
)
type ProbeResult struct {
AppDataDir string
ProfilesDir string
}
func (pr *ProbeResult) GetRelDir(path string) string {
return filepath.Join(pr.AppDataDir, path)
}
func (pr *ProbeResult) GetProfileDir(pid ProfileID) string {
return filepath.Join(pr.ProfilesDir, string(pid))
}
func mkdirIfNotExists(path string, fileMode os.FileMode) (string, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
os.Mkdir(path, fileMode)
return path, nil
}
return "", errors.New("folder exists")
}
func Probe() ProbeResult {
probeResult := ProbeResult{}
homeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
probeResult.AppDataDir = filepath.Join(homeDir, ".FirefoxBoxes")
mkdirIfNotExists(probeResult.AppDataDir, os.FileMode(DIR_MODE))
probeResult.ProfilesDir = filepath.Join(probeResult.AppDataDir, "Boxes")
mkdirIfNotExists(probeResult.ProfilesDir, os.FileMode(DIR_MODE))
return probeResult
}