forked from cloudfoundry/guardian
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmount_options_linux.go
58 lines (45 loc) · 977 Bytes
/
mount_options_linux.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
package rundmc
import (
"fmt"
"os"
"strings"
"github.com/docker/docker/pkg/mount"
)
func (g MountOptionsGetter) GetMountOptions(path string) ([]string, error) {
return g(path)
}
func GetMountOptions(path string) ([]string, error) {
if err := verifyExistingDirectory(path); err != nil {
return nil, err
}
mountInfo, err := getMountInfo(path)
if err != nil {
return nil, err
}
if mountInfo == nil {
return nil, fmt.Errorf("%s is not a mount point", path)
}
return strings.Split(mountInfo.Opts, ","), nil
}
func getMountInfo(path string) (*mount.Info, error) {
mountInfos, err := mount.GetMounts()
if err != nil {
return nil, err
}
for _, info := range mountInfos {
if info.Mountpoint == path {
return info, nil
}
}
return nil, nil
}
func verifyExistingDirectory(path string) error {
stat, err := os.Stat(path)
if err != nil {
return err
}
if !stat.IsDir() {
return fmt.Errorf("%s is not a directory", path)
}
return nil
}