mirror of
https://github.com/rclone/rclone.git
synced 2025-08-16 00:28:09 +02:00
mount: fix check for empty mount point on Linux #3562
This commit is contained in:
@ -2,6 +2,8 @@ package mountlib
|
||||
|
||||
import (
|
||||
"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 default
|
||||
func (m *MountPoint) SetVolumeName(vol string) {
|
||||
if vol == "" {
|
||||
|
Reference in New Issue
Block a user