-
Notifications
You must be signed in to change notification settings - Fork 1
/
fs.go
56 lines (47 loc) · 1.21 KB
/
fs.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
package main
import (
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
func rootVolPath() string {
volumes, err := filepath.Glob("/Volumes/*")
if err != nil || volumes == nil {
log.Println("Unable to list /Volumes/*")
log.Fatal(err)
}
for _, volume := range volumes {
link_path, err := os.Readlink(volume)
if err == nil && link_path == "/" {
return volume
}
}
log.Fatal("Could not find root volume")
return ""
}
func volPath(target string) string {
var err error
target, err = filepath.Abs(target)
if err != nil {
log.Fatal(err)
}
target = filepath.Clean(target)
target_list := strings.Split(target, string(filepath.Separator))
if len(target_list) >= 2 &&
target_list[0] == "" &&
target_list[1] == "Volumes" {
return target
}
return filepath.Join(rootVolPath(), target)
}
func getTMDir(target string) (dirname string, err error) {
dirname_bytes, err := exec.Command("tmutil", "machinedirectory").CombinedOutput()
if err == nil {
dirname = filepath.Join(strings.TrimSpace(string(dirname_bytes)), "Latest")
target_list := strings.Split(target, string(filepath.Separator))
dirname = filepath.Join(dirname, strings.Join(target_list[2:], string(filepath.Separator)))
}
return
}