"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
mount: fix check for empty mount point on Linux #3562
Nick Craig-Wood267a09001d09
diff --git a/cmd/mountlib/check_linux.go b/cmd/mountlib/check_linux.goindex 1f241af87..1c32a6d8a 100644--- a/cmd/mountlib/check_linux.go+++ b/cmd/mountlib/check_linux.go@@ -33,12 +33,20 @@ func CheckMountEmpty(mountpoint string) error {if err != nil {return fmt.Errorf("cannot read %s: %w", mtabPath, err)}+ foundAutofs := falsefor _, entry := range entries {- if entry.Dir == mountpointAbs && entry.Type != "autofs" {- return fmt.Errorf(msg, mountpointAbs)+ if entry.Dir == mountpointAbs {+ if entry.Type != "autofs" {+ return fmt.Errorf(msg, mountpointAbs)+ }+ foundAutofs = true}}- return nil+ // It isn't safe to list an autofs in the middle of mounting+ if foundAutofs {+ return nil+ }+ return checkMountEmpty(mountpoint)}// CheckMountReady checks whether mountpoint is mounted by rclone.diff --git a/cmd/mountlib/check_other.go b/cmd/mountlib/check_other.goindex c8876632c..328f83bca 100644--- a/cmd/mountlib/check_other.go+++ b/cmd/mountlib/check_other.go@@ -4,33 +4,13 @@package mountlibimport (- "fmt"- "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 {- return fmt.Errorf("cannot open: %s: %w", mountpoint, err)- }- 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 {- return fmt.Errorf(msg, mountpoint)- }- return fmt.Errorf(msg+": %w", mountpoint, err)+ return checkMountEmpty(mountpoint)}// CheckMountReady should check if mountpoint is mounted by rclone.diff --git a/cmd/mountlib/utils.go b/cmd/mountlib/utils.goindex 099e3a767..5148f818b 100644--- a/cmd/mountlib/utils.go+++ b/cmd/mountlib/utils.go@@ -2,6 +2,8 @@ package mountlibimport ("fmt"+ "io"+ "os""path/filepath""runtime""strings"@@ -84,6 +86,26 @@ func (m *MountPoint) CheckAllowed() error {return nil}+// checkMountEmpty checks if mountpoint folder is empty by listing it.+func checkMountEmpty(mountpoint string) error {+ fp, err := os.Open(mountpoint)+ if err != nil {+ return fmt.Errorf("cannot open: %s: %w", mountpoint, err)+ }+ defer fs.CheckClose(fp, &err)++ _, err = fp.Readdirnames(1)+ if err == io.EOF {+ return nil+ }++ const msg = "%q is not empty, use --allow-non-empty to mount anyway"+ if err == nil {+ return fmt.Errorf(msg, mountpoint)+ }+ return fmt.Errorf(msg+": %w", mountpoint, err)+}+// SetVolumeName with sensible defaultfunc (m *MountPoint) SetVolumeName(vol string) {if vol == "" {