Home Download Docs Code Community
     1	//go:build linux
     2	
     3	/*
     4	Copyright 2013 The Perkeep Authors
     5	
     6	Licensed under the Apache License, Version 2.0 (the "License");
     7	you may not use this file except in compliance with the License.
     8	You may obtain a copy of the License at
     9	
    10	     http://www.apache.org/licenses/LICENSE-2.0
    11	
    12	Unless required by applicable law or agreed to in writing, software
    13	distributed under the License is distributed on an "AS IS" BASIS,
    14	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15	See the License for the specific language governing permissions and
    16	limitations under the License.
    17	*/
    18	
    19	package fs
    20	
    21	import (
    22		"context"
    23		"errors"
    24		"os/exec"
    25		"runtime"
    26		"time"
    27	
    28		"bazil.org/fuse"
    29	)
    30	
    31	// Unmount attempts to unmount the provided FUSE mount point, forcibly
    32	// if necessary.
    33	func Unmount(point string) error {
    34		var cmd *exec.Cmd
    35		switch runtime.GOOS {
    36		case "darwin":
    37			cmd = exec.Command("/usr/sbin/diskutil", "umount", "force", point)
    38		case "linux":
    39			cmd = exec.Command("fusermount", "-u", point)
    40		default:
    41			return errors.New("unmount: unimplemented")
    42		}
    43	
    44		errc := make(chan error, 1)
    45		go func() {
    46			if err := exec.Command("umount", point).Run(); err == nil {
    47				errc <- err
    48			}
    49			// retry to unmount with the fallback cmd
    50			errc <- cmd.Run()
    51		}()
    52		select {
    53		case <-time.After(1 * time.Second):
    54			return errors.New("umount timeout")
    55		case err := <-errc:
    56			return err
    57		}
    58	}
    59	
    60	func handleEIOorEINTR(err error) error {
    61		if err == nil {
    62			return nil
    63		}
    64		if errors.Is(err, context.Canceled) {
    65			return fuse.EINTR
    66		} else {
    67			return fuse.EIO
    68		}
    69	}
Website layout inspired by memcached.
Content by the authors.