mount: notice daemon dying much quicker

Before this change we waited until until the timeout to check the
daemon was alive.

Now we check it every 100ms like we do the mount status.

This also fixes compiling on all platforms which was broken by the
previous change

9bfbf2a4a mount: fix macOS not noticing errors with --daemon

See: https://forum.rclone.org/t/rclone-mount-daemon-exits-successfully-even-when-mount-fails/43146
This commit is contained in:
Nick Craig-Wood
2023-11-29 15:11:11 +00:00
parent 97d7945cef
commit caf5dd9d5e
5 changed files with 66 additions and 45 deletions

View File

@ -7,15 +7,10 @@ import (
"fmt"
"path/filepath"
"strings"
"time"
"github.com/moby/sys/mountinfo"
)
const (
pollInterval = 100 * time.Millisecond
)
// CheckMountEmpty checks if folder is not already a mountpoint.
// On Linux we use the OS-specific /proc/self/mountinfo API so the check won't access the path.
// Directories marked as "mounted" by autofs are considered not mounted.
@ -80,19 +75,5 @@ func CheckMountReady(mountpoint string) error {
return fmt.Errorf(msg, mountpointAbs)
}
// WaitMountReady waits until mountpoint is mounted by rclone.
func WaitMountReady(mountpoint string, timeout time.Duration) (err error) {
endTime := time.Now().Add(timeout)
for {
err = CheckMountReady(mountpoint)
delay := time.Until(endTime)
if err == nil || delay <= 0 {
break
}
if delay > pollInterval {
delay = pollInterval
}
time.Sleep(delay)
}
return
}
// CanCheckMountReady is set if CheckMountReady is functional
var CanCheckMountReady = true