1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-09 19:32:24 +08:00

mount: move Mount func into mount obj

This commit is contained in:
Juan Batiz-Benet
2014-11-16 01:56:30 -08:00
parent 99f2378bac
commit 6ff472be61
3 changed files with 81 additions and 62 deletions

View File

@ -165,32 +165,12 @@ func Mount(ipfs *core.IpfsNode, fpath string) (mount.Mount, error) {
log.Infof("Mounting ipfs at %s...", fpath)
// setup the Mount abstraction.
m := mount.New(ipfs.Context(), fpath, unmount)
m := mount.New(ipfs.Context(), fpath)
// go serve the mount
mount.ServeMount(m, func(m mount.Mount) error {
c, err := fuse.Mount(m.MountPoint())
if err != nil {
return err
}
defer c.Close()
fsys := FileSystem{Ipfs: ipfs}
log.Infof("Mounted ipfs at %s.", fpath)
if err := fs.Serve(c, fsys); err != nil {
return err
}
// check if the mount process has an error to report
<-c.Ready
if err := c.MountError; err != nil {
m.Unmount()
return err
}
return nil
})
m.Mount(func(m mount.Mount) error {
return internalMount(ipfs, m)
}, internalUnmount)
select {
case <-m.Closed():
@ -205,9 +185,34 @@ func Mount(ipfs *core.IpfsNode, fpath string) (mount.Mount, error) {
return m, nil
}
// Unmount attempts to unmount the provided FUSE mount point, forcibly
// mount attempts to mount the provided FUSE mount point
func internalMount(ipfs *core.IpfsNode, m mount.Mount) error {
c, err := fuse.Mount(m.MountPoint())
if err != nil {
return err
}
defer c.Close()
fsys := FileSystem{Ipfs: ipfs}
log.Infof("Mounted ipfs at %s.", m.MountPoint())
if err := fs.Serve(c, fsys); err != nil {
return err
}
// check if the mount process has an error to report
<-c.Ready
if err := c.MountError; err != nil {
m.Unmount()
return err
}
return nil
}
// unmount attempts to unmount the provided FUSE mount point, forcibly
// if necessary.
func unmount(point string) error {
func internalUnmount(m mount.Mount) error {
point := m.MountPoint()
log.Infof("Unmounting ipfs at %s...", point)
var cmd *exec.Cmd