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

This commit is contained in:
Nick Craig-Wood
2026-04-24 14:14:17 +01:00
parent 55da1abb23
commit 7c56eff1a7
3 changed files with 59 additions and 15 deletions

View File

@@ -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 err == nil {
disks = append(disks, tidy(home))
}
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 !slices.Contains(disks, s) {
disks = append(disks, s)
}
disks = append(disks, mount)
}
// Add home directory
home, err := os.UserHomeDir()
if err == nil {
add(home)
}
// Add root directory
if runtime.GOOS != "windows" {
add("/")
}
// Add mount points
for _, mount := range getMounts() {
if mountOK(mount) {
add(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,
}

1
go.mod
View File

@@ -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

2
go.sum
View File

@@ -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=