forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmounter_osx.go
86 lines (71 loc) · 2.51 KB
/
mounter_osx.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
// +build darwin
package libfuse
import (
"errors"
"bazil.org/fuse"
"github.com/keybase/client/go/install/libnativeinstaller"
)
var kbfusePath = fuse.OSXFUSEPaths{
DevicePrefix: "/dev/kbfuse",
Load: "/Library/Filesystems/kbfuse.fs/Contents/Resources/load_kbfuse",
Mount: "/Library/Filesystems/kbfuse.fs/Contents/Resources/mount_kbfuse",
DaemonVar: "MOUNT_KBFUSE_DAEMON_PATH",
}
func getPlatformSpecificMountOptions(dir string, platformParams PlatformParams) ([]fuse.MountOption, error) {
options := []fuse.MountOption{}
var locationOption fuse.MountOption
if platformParams.UseSystemFuse {
// Only allow osxfuse 3.x.
locationOption = fuse.OSXFUSELocations(fuse.OSXFUSELocationV3)
} else {
// Only allow kbfuse.
locationOption = fuse.OSXFUSELocations(kbfusePath)
}
options = append(options, locationOption)
// Volume name option is only used on OSX (ignored on other platforms).
volName, err := volumeName(dir)
if err != nil {
return nil, err
}
options = append(options, fuse.VolumeName(volName))
options = append(options, fuse.ExclCreate())
if platformParams.UseLocal {
options = append(options, fuse.LocalVolume())
}
return options, nil
}
// GetPlatformSpecificMountOptionsForTest makes cross-platform tests work
func GetPlatformSpecificMountOptionsForTest() []fuse.MountOption {
// For now, test with either kbfuse or OSXFUSE for now.
// TODO: Consider mandate testing with kbfuse?
return []fuse.MountOption{
fuse.OSXFUSELocations(kbfusePath, fuse.OSXFUSELocationV3),
fuse.ExclCreate(),
// We are diabling the 'local' mount option in tests for now since it
// causes out tests to leave a bunch of entries behind in Finder's sidebar.
// TODO: fix this.
// fuse.LocalVolume(),
}
}
func translatePlatformSpecificError(err error, platformParams PlatformParams) error {
if err == fuse.ErrOSXFUSENotFound {
if platformParams.UseSystemFuse {
return errors.New(
"cannot locate OSXFUSE 3.x")
}
return errors.New(
"cannot locate kbfuse; either install the Keybase " +
"app, or install OSXFUSE 3.x " +
"and pass in --use-system-fuse")
}
return err
}
func (m *mounter) reinstallMountDirIfPossible() {
err := libnativeinstaller.UninstallMountDir(m.runMode, m.log)
m.log.Debug("UninstallMountDir: err=%v", err)
err = libnativeinstaller.InstallMountDir(m.runMode, m.log)
m.log.Debug("InstallMountDir: err=%v", err)
}