mirror of
https://github.com/rclone/rclone.git
synced 2026-06-03 05:49:47 -04:00
Fixes an issue on Windows where mounting the local filesystem in network mode failed
when not using option --volname. Reason was that the volume name in network mode
is a network share path in the basic UNC format, and characters that are invalid
in regular file and directory names are also invalid in such a path. And the default
volume name would typically include a '?', which is invalid, from the unc path of
the local, e.g. "\\server\\? C Temp".
The fix is to use an encoder to encode invalid characters such as '?' with the unicode
equivalent, similar to how rclone encodes filesystem paths in normal operations,
when mounting in network mode. Also performs some automatic cleanup of path separators,
but in general, tries to be conservative on restrictions, and instead rely on --volname
being set to something realistic.
Existing strategy to replace the two characters ':' and '/' with space, regardless of
mounting mode variant, was removed. For network mode the new approach handles these in
a better way. Also the existing method did not apply at all when using the implicit
network mode where volume names are taken from mountpath instead of volname option
("rclone mount remote:path/to/files \\cloud\remote"). For non-network mode they were not
needed.
Default volume names, when not specified by user, will be different with this change.
See: #6234
118 lines
3.1 KiB
Go
118 lines
3.1 KiB
Go
//go:build linux || freebsd
|
|
// +build linux freebsd
|
|
|
|
// Package mount implements a FUSE mounting system for rclone remotes.
|
|
package mount
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
|
|
"bazil.org/fuse"
|
|
fusefs "bazil.org/fuse/fs"
|
|
"github.com/rclone/rclone/cmd/mountlib"
|
|
"github.com/rclone/rclone/fs"
|
|
"github.com/rclone/rclone/vfs"
|
|
)
|
|
|
|
func init() {
|
|
mountlib.NewMountCommand("mount", false, mount)
|
|
mountlib.AddRc("mount", mount)
|
|
}
|
|
|
|
// mountOptions configures the options from the command line flags
|
|
func mountOptions(VFS *vfs.VFS, device string, opt *mountlib.Options) (options []fuse.MountOption) {
|
|
options = []fuse.MountOption{
|
|
fuse.MaxReadahead(uint32(opt.MaxReadAhead)),
|
|
fuse.Subtype("rclone"),
|
|
fuse.FSName(device),
|
|
|
|
// Options from benchmarking in the fuse module
|
|
//fuse.MaxReadahead(64 * 1024 * 1024),
|
|
//fuse.WritebackCache(),
|
|
}
|
|
if opt.AsyncRead {
|
|
options = append(options, fuse.AsyncRead())
|
|
}
|
|
if opt.AllowOther {
|
|
options = append(options, fuse.AllowOther())
|
|
}
|
|
if opt.AllowRoot {
|
|
// options = append(options, fuse.AllowRoot())
|
|
fs.Errorf(nil, "Ignoring --allow-root. Support has been removed upstream - see https://github.com/bazil/fuse/issues/144 for more info")
|
|
}
|
|
if opt.DefaultPermissions {
|
|
options = append(options, fuse.DefaultPermissions())
|
|
}
|
|
if VFS.Opt.ReadOnly {
|
|
options = append(options, fuse.ReadOnly())
|
|
}
|
|
if opt.WritebackCache {
|
|
options = append(options, fuse.WritebackCache())
|
|
}
|
|
if opt.DaemonTimeout != 0 {
|
|
options = append(options, fuse.DaemonTimeout(fmt.Sprint(int(opt.DaemonTimeout.Seconds()))))
|
|
}
|
|
if len(opt.ExtraOptions) > 0 {
|
|
fs.Errorf(nil, "-o/--option not supported with this FUSE backend")
|
|
}
|
|
if len(opt.ExtraFlags) > 0 {
|
|
fs.Errorf(nil, "--fuse-flag not supported with this FUSE backend")
|
|
}
|
|
return options
|
|
}
|
|
|
|
// mount the file system
|
|
//
|
|
// The mount point will be ready when this returns.
|
|
//
|
|
// returns an error, and an error channel for the serve process to
|
|
// report an error when fusermount is called.
|
|
func mount(VFS *vfs.VFS, mountpoint string, opt *mountlib.Options) (<-chan error, func() error, error) {
|
|
f := VFS.Fs()
|
|
if runtime.GOOS == "darwin" {
|
|
fs.Logf(nil, "macOS users: please try \"rclone cmount\" as it will be the default in v1.54")
|
|
}
|
|
if err := mountlib.CheckOverlap(f, mountpoint); err != nil {
|
|
return nil, nil, err
|
|
}
|
|
if err := mountlib.CheckAllowNonEmpty(mountpoint, opt); err != nil {
|
|
return nil, nil, err
|
|
}
|
|
opt.VolumeName = mountlib.MakeVolumeNameValidOnUnix(opt.VolumeName)
|
|
fs.Debugf(f, "Mounting on %q", mountpoint)
|
|
|
|
if opt.DebugFUSE {
|
|
fuse.Debug = func(msg interface{}) {
|
|
fs.Debugf("fuse", "%v", msg)
|
|
}
|
|
}
|
|
|
|
c, err := fuse.Mount(mountpoint, mountOptions(VFS, opt.DeviceName, opt)...)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
filesys := NewFS(VFS, opt)
|
|
filesys.server = fusefs.New(c, nil)
|
|
|
|
// Serve the mount point in the background returning error to errChan
|
|
errChan := make(chan error, 1)
|
|
go func() {
|
|
err := filesys.server.Serve(filesys)
|
|
closeErr := c.Close()
|
|
if err == nil {
|
|
err = closeErr
|
|
}
|
|
errChan <- err
|
|
}()
|
|
|
|
unmount := func() error {
|
|
// Shutdown the VFS
|
|
filesys.VFS.Shutdown()
|
|
return fuse.Unmount(mountpoint)
|
|
}
|
|
|
|
return errChan, unmount, nil
|
|
}
|