clean up previously mounted folder
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/chrislusf/seaweedfs/weed/mount"
|
||||
"github.com/chrislusf/seaweedfs/weed/mount/unmount"
|
||||
"github.com/hanwen/go-fuse/v2/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -43,6 +44,12 @@ func RunMount2(option *Mount2Options, umask os.FileMode) bool {
|
||||
|
||||
opts := &fs.Options{}
|
||||
opts.Debug = true
|
||||
|
||||
unmount.Unmount(*option.dir)
|
||||
grace.OnInterrupt(func() {
|
||||
unmount.Unmount(*option.dir)
|
||||
})
|
||||
|
||||
server, err := fs.Mount(*option.dir, &mount.WeedFS{}, opts)
|
||||
if err != nil {
|
||||
glog.Fatalf("Mount fail: %v", err)
|
||||
|
||||
6
weed/mount/unmount/unmount.go
Normal file
6
weed/mount/unmount/unmount.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package unmount
|
||||
|
||||
// Unmount tries to unmount the filesystem mounted at dir.
|
||||
func Unmount(dir string) error {
|
||||
return unmount(dir)
|
||||
}
|
||||
21
weed/mount/unmount/unmount_linux.go
Normal file
21
weed/mount/unmount/unmount_linux.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package unmount
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func unmount(dir string) error {
|
||||
cmd := exec.Command("fusermount", "-u", dir)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
if len(output) > 0 {
|
||||
output = bytes.TrimRight(output, "\n")
|
||||
msg := err.Error() + ": " + string(output)
|
||||
err = errors.New(msg)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
18
weed/mount/unmount/unmount_std.go
Normal file
18
weed/mount/unmount/unmount_std.go
Normal file
@@ -0,0 +1,18 @@
|
||||
//go:build !linux
|
||||
// +build !linux
|
||||
|
||||
package unmount
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func unmount(dir string) error {
|
||||
err := syscall.Unmount(dir, 0)
|
||||
if err != nil {
|
||||
err = &os.PathError{Op: "unmount", Path: dir, Err: err}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user