mirror of
https://github.com/restic/restic.git
synced 2025-05-17 19:28:21 +00:00
Simplify mount logic
This commit is contained in:
parent
931f5cdd33
commit
6485a6cdc0
@ -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)
|
|
||||||
})
|
|
||||||
|
|
||||||
cmd.ready <- struct{}{}
|
|
||||||
|
|
||||||
errServe := make(chan error)
|
|
||||||
go func() {
|
|
||||||
err = fs.Serve(c, &root)
|
|
||||||
if err != nil {
|
|
||||||
errServe <- err
|
|
||||||
}
|
|
||||||
|
|
||||||
<-c.Ready
|
|
||||||
errServe <- c.MountError
|
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
|
||||||
case err := <-errServe:
|
|
||||||
return err
|
|
||||||
case <-cmd.done:
|
|
||||||
err := systemFuse.Unmount(mountpoint)
|
err := systemFuse.Unmount(mountpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.global.Printf("Error umounting: %s\n", err)
|
cmd.global.Warnf("unable to umount (maybe already umounted?): %v\n", err)
|
||||||
}
|
}
|
||||||
return c.Close()
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
close(cmd.ready)
|
||||||
|
|
||||||
|
err = fs.Serve(c, &root)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<-c.Ready
|
||||||
|
return c.MountError
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user