Touched up callMount.
parent
a9693474e8
commit
19934c68be
|
@ -51,16 +51,25 @@ func openOSXFUSEDev() (dev *os.File, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func callMount(dir string, conf *mountConfig, f *os.File, ready chan<- struct{}, errp *error) error {
|
func callMount(
|
||||||
bin := "/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs"
|
dir string,
|
||||||
|
cfg *mountConfig,
|
||||||
|
dev *os.File,
|
||||||
|
ready chan<- error) (err error) {
|
||||||
|
const bin = "/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs"
|
||||||
|
|
||||||
|
// The mount helper doesn't understand any escaping.
|
||||||
for k, v := range conf.options {
|
for k, v := range conf.options {
|
||||||
if strings.Contains(k, ",") || strings.Contains(v, ",") {
|
if strings.Contains(k, ",") || strings.Contains(v, ",") {
|
||||||
// Silly limitation but the mount helper does not
|
return fmt.Errorf(
|
||||||
// understand any escaping. See TestMountOptionCommaError.
|
"mount options cannot contain commas on darwin: %q=%q",
|
||||||
return fmt.Errorf("mount options cannot contain commas on darwin: %q=%q", k, v)
|
k,
|
||||||
|
v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call the mount helper, passing in the device file and saving output into a
|
||||||
|
// buffer.
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
bin,
|
bin,
|
||||||
"-o", conf.getOptions(),
|
"-o", conf.getOptions(),
|
||||||
|
@ -74,33 +83,36 @@ func callMount(dir string, conf *mountConfig, f *os.File, ready chan<- struct{},
|
||||||
"3",
|
"3",
|
||||||
dir,
|
dir,
|
||||||
)
|
)
|
||||||
cmd.ExtraFiles = []*os.File{f}
|
cmd.ExtraFiles = []*os.File{dev}
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
cmd.Env = append(cmd.Env, "MOUNT_FUSEFS_CALL_BY_LIB=")
|
cmd.Env = append(cmd.Env, "MOUNT_FUSEFS_CALL_BY_LIB=")
|
||||||
// TODO this is used for fs typenames etc, let app influence it
|
// TODO this is used for fs typenames etc, let app influence it
|
||||||
cmd.Env = append(cmd.Env, "MOUNT_FUSEFS_DAEMON_PATH="+bin)
|
cmd.Env = append(cmd.Env, "MOUNT_FUSEFS_DAEMON_PATH="+bin)
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
cmd.Stdout = &buf
|
cmd.Stdout = &buf
|
||||||
cmd.Stderr = &buf
|
cmd.Stderr = &buf
|
||||||
|
|
||||||
err := cmd.Start()
|
err = cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In the background, wait for the command to complete.
|
||||||
go func() {
|
go func() {
|
||||||
err := cmd.Wait()
|
err := cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if buf.Len() > 0 {
|
if buf.Len() > 0 {
|
||||||
output := buf.Bytes()
|
output := buf.Bytes()
|
||||||
output = bytes.TrimRight(output, "\n")
|
output = bytes.TrimRight(output, "\n")
|
||||||
msg := err.Error() + ": " + string(output)
|
err = fmt.Errorf("%v: %s", err, output)
|
||||||
err = errors.New(msg)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*errp = err
|
|
||||||
close(ready)
|
ready <- err
|
||||||
}()
|
}()
|
||||||
return err
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin the process of mounting at the given directory, returning a connection
|
// Begin the process of mounting at the given directory, returning a connection
|
||||||
|
|
Loading…
Reference in New Issue