From 6ce32e46613b275c965eac1b4a799555e4dcba4a Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 3 May 2018 09:34:07 +0100 Subject: [PATCH] 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. --- cmd/cmount/mount.go | 2 +- cmd/mount/mount.go | 2 +- cmd/mountlib/mount.go | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/cmount/mount.go b/cmd/cmount/mount.go index 325dfe175..096710745 100644 --- a/cmd/cmount/mount.go +++ b/cmd/cmount/mount.go @@ -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") } diff --git a/cmd/mount/mount.go b/cmd/mount/mount.go index 4e4bb38df..5f2ae6573 100644 --- a/cmd/mount/mount.go +++ b/cmd/mount/mount.go @@ -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(), diff --git a/cmd/mountlib/mount.go b/cmd/mountlib/mount.go index 0d7d347e5..7efecab42 100644 --- a/cmd/mountlib/mount.go +++ b/cmd/mountlib/mount.go @@ -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)