mount,cmount: Add --volname flag and remove special chars from it #2287

Before this change rclone would set the volume name from the
remote:path normally.  However this has `:` and `/` in which make it
difficult to use in macOS.

Now rclone will remove the special characters and replace them with
spaces.  It also allows the volume name to be set with the --volname
flag.
This commit is contained in:
Nick Craig-Wood 2018-05-03 09:34:07 +01:00
parent 1755ffd1f3
commit 6ce32e4661
3 changed files with 14 additions and 2 deletions

View File

@ -53,7 +53,7 @@ func mountOptions(device string, mountpoint string) (options []string) {
// OSX options
if runtime.GOOS == "darwin" {
options = append(options, "-o", "volname="+device)
options = append(options, "-o", "volname="+mountlib.VolumeName)
options = append(options, "-o", "noappledouble")
options = append(options, "-o", "noapplexattr")
}

View File

@ -28,7 +28,7 @@ func mountOptions(device string) (options []fuse.MountOption) {
options = []fuse.MountOption{
fuse.MaxReadahead(uint32(mountlib.MaxReadAhead)),
fuse.Subtype("rclone"),
fuse.FSName(device), fuse.VolumeName(device),
fuse.FSName(device), fuse.VolumeName(mountlib.VolumeName),
fuse.NoAppleDouble(),
fuse.NoAppleXattr(),

View File

@ -5,6 +5,7 @@ import (
"log"
"os"
"runtime"
"strings"
"time"
"github.com/ncw/rclone/cmd"
@ -29,6 +30,7 @@ var (
ExtraOptions []string
ExtraFlags []string
AttrTimeout = 1 * time.Second // how long the kernel caches attribute for
VolumeName string
)
// Check is folder is empty
@ -228,6 +230,15 @@ be copied to the vfs cache before opening with --vfs-cache-mode full.
}
}
// Work out the volume name, removing special
// characters from it if necessary
if VolumeName == "" {
VolumeName = fdst.Name() + ":" + fdst.Root()
}
VolumeName = strings.Replace(VolumeName, ":", " ", -1)
VolumeName = strings.Replace(VolumeName, "/", " ", -1)
VolumeName = strings.TrimSpace(VolumeName)
// Start background task if --background is specified
if Daemon {
daemonized := startBackgroundMode()
@ -260,6 +271,7 @@ be copied to the vfs cache before opening with --vfs-cache-mode full.
flags.StringArrayVarP(flagSet, &ExtraOptions, "option", "o", []string{}, "Option for libfuse/WinFsp. Repeat if required.")
flags.StringArrayVarP(flagSet, &ExtraFlags, "fuse-flag", "", []string{}, "Flags or arguments to be passed direct to libfuse/WinFsp. Repeat if required.")
flags.BoolVarP(flagSet, &Daemon, "daemon", "", Daemon, "Run mount as a daemon (background mode).")
flags.StringVarP(flagSet, &VolumeName, "volname", "", VolumeName, "Set the volume name (not supported by all OSes).")
// Add in the generic flags
vfsflags.AddFlags(flagSet)