2021-07-24 15:27:48 +02:00
|
|
|
//go:build !linux
|
|
|
|
// +build !linux
|
|
|
|
|
|
|
|
package mountlib
|
|
|
|
|
|
|
|
import (
|
2021-11-04 11:12:57 +01:00
|
|
|
"fmt"
|
2021-07-24 15:27:48 +02:00
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CheckMountEmpty checks if mountpoint folder is empty.
|
|
|
|
// On non-Linux unixes we list directory to ensure that.
|
|
|
|
func CheckMountEmpty(mountpoint string) error {
|
|
|
|
fp, err := os.Open(mountpoint)
|
|
|
|
if err != nil {
|
2021-11-04 11:12:57 +01:00
|
|
|
return fmt.Errorf("Can not open: %s: %w", mountpoint, err)
|
2021-07-24 15:27:48 +02:00
|
|
|
}
|
|
|
|
defer fs.CheckClose(fp, &err)
|
|
|
|
|
|
|
|
_, err = fp.Readdirnames(1)
|
|
|
|
if err == io.EOF {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const msg = "Directory is not empty, use --allow-non-empty to mount anyway: %s"
|
|
|
|
if err == nil {
|
2021-11-04 11:12:57 +01:00
|
|
|
return fmt.Errorf(msg, mountpoint)
|
2021-07-24 15:27:48 +02:00
|
|
|
}
|
2021-11-04 11:12:57 +01:00
|
|
|
return fmt.Errorf(msg+": %w", mountpoint, err)
|
2021-07-24 15:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CheckMountReady should check if mountpoint is mounted by rclone.
|
|
|
|
// The check is implemented only for Linux so this does nothing.
|
|
|
|
func CheckMountReady(mountpoint string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// WaitMountReady should wait until mountpoint is mounted by rclone.
|
|
|
|
// The check is implemented only for Linux so we just sleep a little.
|
|
|
|
func WaitMountReady(mountpoint string, timeout time.Duration) error {
|
|
|
|
time.Sleep(timeout)
|
|
|
|
return nil
|
|
|
|
}
|