Simplify mount logic

This commit is contained in:
Alexander Neumann 2016-09-15 19:59:07 +02:00
parent 931f5cdd33
commit 6485a6cdc0
1 changed files with 13 additions and 25 deletions

View File

@ -20,7 +20,6 @@ type CmdMount struct {
global *GlobalOptions global *GlobalOptions
ready chan struct{} ready chan struct{}
done chan struct{}
} }
func init() { func init() {
@ -29,8 +28,7 @@ func init() {
"The mount command mounts a repository read-only to a given directory", "The mount command mounts a repository read-only to a given directory",
&CmdMount{ &CmdMount{
global: &globalOpts, global: &globalOpts,
ready: make(chan struct{}, 1), ready: make(chan struct{}),
done: make(chan struct{}),
}) })
if err != nil { if err != nil {
panic(err) panic(err)
@ -80,30 +78,20 @@ func (cmd CmdMount) Execute(args []string) error {
cmd.global.Printf("Don't forget to umount after quitting!\n") cmd.global.Printf("Don't forget to umount after quitting!\n")
AddCleanupHandler(func() error { AddCleanupHandler(func() error {
return systemFuse.Unmount(mountpoint) err := systemFuse.Unmount(mountpoint)
if err != nil {
cmd.global.Warnf("unable to umount (maybe already umounted?): %v\n", err)
}
return nil
}) })
cmd.ready <- struct{}{} close(cmd.ready)
errServe := make(chan error)
go func() {
err = fs.Serve(c, &root) err = fs.Serve(c, &root)
if err != nil { if err != nil {
errServe <- err return err
} }
<-c.Ready <-c.Ready
errServe <- c.MountError return c.MountError
}()
select {
case err := <-errServe:
return err
case <-cmd.done:
err := systemFuse.Unmount(mountpoint)
if err != nil {
cmd.global.Printf("Error umounting: %s\n", err)
}
return c.Close()
}
} }