Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

windows: Stop drive letters (eg C:) getting mixed up with remotes (eg drive:)

Nick Craig-Wood20ad96f3cd5b
diff --git a/fs/config.go b/fs/config.go
index f1ba64fde..01dcb9e7a 100644
--- a/fs/config.go
+++ b/fs/config.go
@@ -330,9 +330,19 @@ func EditConfig() {
name := ChooseRemote()
EditRemote(name)
case 'n':
- fmt.Printf("name> ")
- name := ReadLine()
- NewRemote(name)
+ for {
+ fmt.Printf("name> ")
+ name := ReadLine()
+ switch {
+ case name == "":
+ fmt.Printf("Can't use empty name\n")
+ case isDriveLetter(name):
+ fmt.Printf("Can't use %q as it can be confused a drive letter\n", name)
+ default:
+ NewRemote(name)
+ break
+ }
+ }
case 'd':
name := ChooseRemote()
DeleteRemote(name)
diff --git a/fs/driveletter.go b/fs/driveletter.go
new file mode 100644
index 000000000..65b4e2567
--- /dev/null
+++ b/fs/driveletter.go
@@ -0,0 +1,12 @@
+// +build !windows
+
+package fs
+
+// isDriveLetter returns a bool indicating whether name is a valid
+// Windows drive letter
+//
+// On non windows platforms we don't have drive letters so we always
+// return false
+func isDriveLetter(name string) bool {
+ return false
+}
diff --git a/fs/driveletter_windows.go b/fs/driveletter_windows.go
new file mode 100644
index 000000000..ee9160a37
--- /dev/null
+++ b/fs/driveletter_windows.go
@@ -0,0 +1,13 @@
+// +build windows
+
+package fs
+
+// isDriveLetter returns a bool indicating whether name is a valid
+// Windows drive letter
+func isDriveLetter(name string) bool {
+ if len(name) != 1 {
+ return false
+ }
+ c := name[0]
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
+}
diff --git a/fs/fs.go b/fs/fs.go
index e107d4b5a..0a148c52f 100644
--- a/fs/fs.go
+++ b/fs/fs.go
@@ -196,9 +196,6 @@ type Dir struct {
// A channel of Dir objects
type DirChan chan *Dir
-// Pattern to match a url
-var matcher = regexp.MustCompile(`^([\w_-]+):(.*)$`)
-
// Finds a FsInfo object for the name passed in
//
// Services are looked up in the config file
@@ -211,16 +208,22 @@ func Find(name string) (*FsInfo, error) {
return nil, fmt.Errorf("Didn't find filing system for %q", name)
}
+// Pattern to match an rclone url
+var matcher = regexp.MustCompile(`^([\w_-]+):(.*)$`)
+
// NewFs makes a new Fs object from the path
//
// The path is of the form remote:path
//
// Remotes are looked up in the config file. If the remote isn't
// found then NotFoundInConfigFile will be returned.
+//
+// On Windows avoid single character remote names as they can be mixed
+// up with drive letters.
func NewFs(path string) (Fs, error) {
parts := matcher.FindStringSubmatch(path)
fsName, configName, fsPath := "local", "local", path
- if parts != nil {
+ if parts != nil && !isDriveLetter(parts[1]) {
configName, fsPath = parts[1], parts[2]
var err error
fsName, err = ConfigFile.GetValue(configName, "type")