mountlib: make sure we don't call umount more than once #4804

Before this change when using CTRL-C with rclone cmount the
mount would be unmounted twice.
This commit is contained in:
Nick Craig-Wood 2020-11-27 10:50:10 +00:00
parent 3b24a4cada
commit 1cfce703b2

View file

@ -8,6 +8,7 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"sync"
"syscall" "syscall"
"time" "time"
@ -460,10 +461,14 @@ func Mount(VFS *vfs.VFS, mountpoint string, mount MountFn, opt *Options) error {
} }
// Unmount on exit // Unmount on exit
fnHandle := atexit.Register(func() { var finaliseOnce sync.Once
_ = sysdnotify.Stopping() finalise := func() {
_ = unmount() finaliseOnce.Do(func() {
}) _ = sysdnotify.Stopping()
_ = unmount()
})
}
fnHandle := atexit.Register(finalise)
defer atexit.Unregister(fnHandle) defer atexit.Unregister(fnHandle)
// Notify systemd // Notify systemd
@ -492,8 +497,7 @@ waitloop:
} }
} }
_ = sysdnotify.Stopping() finalise()
_ = unmount()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to umount FUSE fs") return errors.Wrap(err, "failed to umount FUSE fs")