From c48e561e20619440243b9675a7a2076474bcfca8 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Fri, 24 Jul 2015 16:20:11 +1000 Subject: [PATCH] Copied unmount files from fuseshim. --- unmount.go | 23 +++-------------------- unmount_linux.go | 21 +++++++++++++++++++++ unmount_std.go | 17 +++++++++++++++++ 3 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 unmount_linux.go create mode 100644 unmount_std.go 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 +}