diff --git a/unmount.go b/unmount.go index 7acec46..0cc989d 100644 --- a/unmount.go +++ b/unmount.go @@ -1,23 +1,6 @@ -// Copyright 2015 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +package fuseshim -package fuse - -import "github.com/jacobsa/fuse/internal/fuseshim" - -// Attempt to unmount the file system whose mount point is the supplied -// directory. +// Unmount tries to unmount the filesystem mounted at dir. func Unmount(dir string) error { - return fuseshim.Unmount(dir) + return unmount(dir) } diff --git a/unmount_linux.go b/unmount_linux.go new file mode 100644 index 0000000..6a165cc --- /dev/null +++ b/unmount_linux.go @@ -0,0 +1,21 @@ +package fuseshim + +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 +} diff --git a/unmount_std.go b/unmount_std.go new file mode 100644 index 0000000..3c38dd2 --- /dev/null +++ b/unmount_std.go @@ -0,0 +1,17 @@ +// +build !linux + +package fuseshim + +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 +}