-
Notifications
You must be signed in to change notification settings - Fork 0
/
mount.go
39 lines (35 loc) · 1.02 KB
/
mount.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
package core
import (
"fmt"
"github.com/pkg/errors"
"log"
"os/exec"
"runtime"
"strings"
)
func mount(mountOptions string, mountPoint string, servePort string) error {
if mountOptions == "" {
switch runtime.GOOS {
case "windows":
mountOptions = fmt.Sprintf("port=%v,mountport=%v", servePort, servePort)
case "darwin":
fmt.Println("Running on macOS")
mountOptions = fmt.Sprintf("port=%v,mountport=%v", servePort, servePort)
default:
mountOptions = fmt.Sprintf("port=%v,mountport=%v,nfsvers=3,noacl,tcp", servePort, servePort)
}
}
return runCommand("mount", "-o", mountOptions, "-t", "nfs", "localhost:/", mountPoint)
}
func umount(mountPoint string) error {
return runCommand("umount", mountPoint)
}
func runCommand(name string, args ...string) error {
log.Printf("running '%v %v'", name, strings.Join(args, " "))
cmd := exec.Command(name, args...)
output, err := cmd.CombinedOutput()
if err != nil {
return errors.Wrapf(err, "%v command failed to execute\n%v", name, string(output))
}
return nil
}