Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

rc: add user directories to core/disks and filter mounts better

Nick Craig-Wood7c56eff1a772
diff --git a/fs/rc/internal.go b/fs/rc/internal.go
index e2c72df83..36d2fafd5 100644
--- a/fs/rc/internal.go
+++ b/fs/rc/internal.go
@@ -9,9 +9,11 @@ import (
"os"
"os/exec"
"runtime"
+ "slices"
"strings"
"time"
+ "github.com/adrg/xdg"
"github.com/coreos/go-semver/semver"
"github.com/rclone/rclone/fs"
@@ -636,29 +638,68 @@ Returns:
})
}
+func mountOK(path string) bool {
+ if runtime.GOOS == "darwin" {
+ if strings.HasPrefix(path, "/Volumes/") {
+ return true
+ }
+ } else if runtime.GOOS == "windows" {
+ return true
+ } else { // Linux and all other unices
+ // Fedora/Arch/openSUSE standard
+ if strings.HasPrefix(path, "/run/media/") {
+ return true
+ }
+ // Ubuntu/Debian standard
+ if strings.HasPrefix(path, "/media/") {
+ return true
+ }
+ // Traditional unix standard
+ if strings.HasPrefix(path, "/mnt/") {
+ return true
+ }
+ }
+ return false
+}
+
// Disks returns likely local disks and some other useful positions
func rcDisks(ctx context.Context, in Params) (out Params, err error) {
disks := []string{}
- home, err := os.UserHomeDir()
- tidy := func(s string) string {
+ add := func(s string) {
if s != "/" {
s, _ = strings.CutSuffix(s, "/")
}
- return s
+ if !slices.Contains(disks, s) {
+ disks = append(disks, s)
+ }
}
+
+ // Add home directory
+ home, err := os.UserHomeDir()
if err == nil {
- disks = append(disks, tidy(home))
+ add(home)
+ }
+
+ // Add root directory
+ if runtime.GOOS != "windows" {
+ add("/")
}
+
+ // Add mount points
for _, mount := range getMounts() {
- mount = tidy(mount)
- if runtime.GOOS == "linux" {
- if strings.HasPrefix(mount, "/snap/") || strings.HasPrefix(mount, "/var/snap/") || strings.HasPrefix(mount, "/boot/") || mount == "/boot" {
- // ignore boring mounts
- continue
- }
+ if mountOK(mount) {
+ add(mount)
}
- disks = append(disks, mount)
}
+
+ // Add user directories
+ add(xdg.UserDirs.Desktop)
+ add(xdg.UserDirs.Download)
+ add(xdg.UserDirs.Documents)
+ add(xdg.UserDirs.Music)
+ add(xdg.UserDirs.Pictures)
+ add(xdg.UserDirs.Videos)
+
out = Params{
"disks": disks,
}
diff --git a/go.mod b/go.mod
index 0ca90e467..e8904c611 100644
--- a/go.mod
+++ b/go.mod
@@ -18,6 +18,7 @@ require (
github.com/a8m/tree v0.0.0-20240104212747-2c8764a5f17e
github.com/aalpar/deheap v1.1.2
github.com/abbot/go-http-auth v0.4.0
+ github.com/adrg/xdg v0.5.3
github.com/anacrolix/dms v1.7.2
github.com/anacrolix/log v0.17.0
github.com/atotto/clipboard v0.1.4
diff --git a/go.sum b/go.sum
index f5d37d65a..8df04c35c 100644
--- a/go.sum
+++ b/go.sum
@@ -100,6 +100,8 @@ github.com/aalpar/deheap v1.1.2 h1:MABHLcnjqsffb8GLkUFDigqpBBxOMz0DoKM9QfELeTw=
github.com/aalpar/deheap v1.1.2/go.mod h1:A+nfkD4JbS05sewV0he/MYgR/90vfqyMoNNROgs+rmA=
github.com/abbot/go-http-auth v0.4.0 h1:QjmvZ5gSC7jm3Zg54DqWE/T5m1t2AfDu6QlXJT0EVT0=
github.com/abbot/go-http-auth v0.4.0/go.mod h1:Cz6ARTIzApMJDzh5bRMSUou6UMSp0IEXg9km/ci7TJM=
+github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
+github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ=
github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw=
github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/anacrolix/dms v1.7.2 h1:JAAJJIlXp+jT2yEah1EbR1AFpGALHL238uSKFXec2qw=