// Mount mounts an IpfsNode instance at a particular path. It // serves until the process receives exit signals (to Unmount). func Mount(ipfs *core.IpfsNode, fpath string) error { sigc := make(chan os.Signal, 1) signal.Notify(sigc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) go func() { <-sigc for { err := Unmount(fpath) if err == nil { return } time.Sleep(time.Millisecond * 10) } }() c, err := fuse.Mount(fpath) if err != nil { return err } defer c.Close() err = fs.Serve(c, FileSystem{Ipfs: ipfs}) if err != nil { return err } // check if the mount process has an error to report <-c.Ready if err := c.MountError; err != nil { return err } return nil }
func main() { flag.Usage = Usage flag.Parse() if flag.NArg() != 1 { Usage() os.Exit(2) } mountpoint := flag.Arg(0) c, err := fuse.Mount(mountpoint) if err != nil { log.Fatal(err) } defer c.Close() err = fs.Serve(c, FS{}) if err != nil { log.Fatal(err) } // check if the mount process has an error to report <-c.Ready if err := c.MountError; err != nil { log.Fatal(err) } }
// Mounted mounts the fuse.Server at a temporary directory. // // It also waits until the filesystem is known to be visible (OS X // workaround). // // After successful return, caller must clean up by calling Close. func Mounted(srv *fs.Server) (*Mount, error) { dir, err := ioutil.TempDir("", "fusetest") if err != nil { return nil, err } c, err := fuse.Mount(dir) if err != nil { return nil, err } done := make(chan struct{}) serveErr := make(chan error, 1) mnt := &Mount{ Dir: dir, Conn: c, Error: serveErr, done: done, } go func() { defer close(done) serveErr <- srv.Serve(c) }() select { case <-mnt.Conn.Ready: if mnt.Conn.MountError != nil { return nil, err } return mnt, err case err = <-mnt.Error: // Serve quit early if err != nil { return nil, err } return nil, errors.New("Serve exited early") } }