From b39fa54ab22e2fa551a6693c90e2d3c90e2d6fd4 Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Mon, 8 Feb 2021 15:50:56 +0100 Subject: [PATCH] mount: allow mounting to root directory on windows --- cmd/cmount/mountpoint_windows.go | 10 ++++------ cmd/mountlib/mount.go | 10 +++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cmd/cmount/mountpoint_windows.go b/cmd/cmount/mountpoint_windows.go index 5018ae6a8..8ac05b879 100644 --- a/cmd/cmount/mountpoint_windows.go +++ b/cmd/cmount/mountpoint_windows.go @@ -103,8 +103,9 @@ func handleLocalMountpath(mountpath string, opt *mountlib.Options) (string, erro } else if !os.IsNotExist(err) { return "", errors.Wrap(err, "failed to retrieve mountpoint path information") } - //if isDriveRootPath(mountpath) { // Assume intention with "X:\" was "X:" - // mountpoint = mountpath[:len(mountpath)-1] // WinFsp needs drive mountpoints without trailing path separator + if isDriveRootPath(mountpath) { // Assume intention with "X:\" was "X:" + mountpath = mountpath[:len(mountpath)-1] // WinFsp needs drive mountpoints without trailing path separator + } if !isDrive(mountpath) { // Assuming directory path, since it is not a pure drive letter string such as "X:". // Drive letter string can be used as is, since we have already checked it does not exist, @@ -115,10 +116,7 @@ func handleLocalMountpath(mountpath string, opt *mountlib.Options) (string, erro } parent := filepath.Join(mountpath, "..") if parent == "" || parent == "." { - return "", errors.New("mountpoint directory is not valid: " + parent) - } - if os.IsPathSeparator(parent[len(parent)-1]) { // Ends in a separator only if it is the root directory - return "", errors.New("mountpoint directory is at root: " + parent) + return "", errors.New("mountpoint parent path is not valid: " + parent) } if _, err := os.Stat(parent); err != nil { if os.IsNotExist(err) { diff --git a/cmd/mountlib/mount.go b/cmd/mountlib/mount.go index 0f0944183..391d4b58c 100644 --- a/cmd/mountlib/mount.go +++ b/cmd/mountlib/mount.go @@ -179,15 +179,15 @@ is an **empty** **existing** directory: On Windows you can start a mount in different ways. See [below](#mounting-modes-on-windows) for details. The following examples will mount to an automatically assigned drive, -to specific drive letter |X:|, to path |C:\path\to\nonexistent\directory| -(which must be **non-existent** subdirectory of an **existing** parent directory or drive, +to specific drive letter |X:|, to path |C:\path\parent\mount| +(where parent directory or drive must exist, and mount must **not** exist, and is not supported when [mounting as a network drive](#mounting-modes-on-windows)), and the last example will mount as network share |\\cloud\remote| and map it to an automatically assigned drive: rclone @ remote:path/to/files * rclone @ remote:path/to/files X: - rclone @ remote:path/to/files C:\path\to\nonexistent\directory + rclone @ remote:path/to/files C:\path\parent\mount rclone @ remote:path/to/files \\cloud\remote When the program ends while in foreground mode, either via Ctrl+C or receiving @@ -241,14 +241,14 @@ and experience unexpected program errors, freezes or other issues, consider moun as a network drive instead. When mounting as a fixed disk drive you can either mount to an unused drive letter, -or to a path - which must be **non-existent** subdirectory of an **existing** parent +or to a path representing a **non-existent** subdirectory of an **existing** parent directory or drive. Using the special value |*| will tell rclone to automatically assign the next available drive letter, starting with Z: and moving backward. Examples: rclone @ remote:path/to/files * rclone @ remote:path/to/files X: - rclone @ remote:path/to/files C:\path\to\nonexistent\directory + rclone @ remote:path/to/files C:\path\parent\mount rclone @ remote:path/to/files X: Option |--volname| can be used to set a custom volume name for the mounted