mirror of https://github.com/perkeep/perkeep.git
fs: unmount on linux
Unmount the mount point on quit key on Linux. Adding fallbacks in case of umount failure. Change-Id: Ibd52ff1886d396bb424ac8d8ba9f9d8cb94a36f9
This commit is contained in:
parent
b4a5a36457
commit
251df7dc53
|
@ -18,7 +18,6 @@ package fs
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"time"
|
||||
|
@ -27,18 +26,28 @@ import (
|
|||
// Unmount attempts to unmount the provided FUSE mount point, forcibly
|
||||
// if necessary.
|
||||
func Unmount(point string) error {
|
||||
if runtime.GOOS == "darwin" {
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
errc <- exec.Command("diskutil", "umount", "force", point).Run()
|
||||
}()
|
||||
select {
|
||||
case <-time.After(1 * time.Second):
|
||||
return errors.New("unmount timeout")
|
||||
case err := <-errc:
|
||||
log.Printf("diskutil unmount = %v", err)
|
||||
return err
|
||||
}
|
||||
var cmd *exec.Cmd
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
cmd = exec.Command("diskutil", "umount", "force", point)
|
||||
case "linux":
|
||||
cmd = exec.Command("fusermount", "-u", point)
|
||||
default:
|
||||
return errors.New("unmount: unimplemented")
|
||||
}
|
||||
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
if err := exec.Command("umount", point).Run(); err == nil {
|
||||
errc <- err
|
||||
}
|
||||
// retry to unmount with the fallback cmd
|
||||
errc <- cmd.Run()
|
||||
}()
|
||||
select {
|
||||
case <-time.After(1 * time.Second):
|
||||
return errors.New("umount timeout")
|
||||
case err := <-errc:
|
||||
return err
|
||||
}
|
||||
return errors.New("unmount: unimplemented")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue