1
mirror of https://github.com/rclone/rclone synced 2024-11-17 17:30:37 +01:00

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

This was done by stopping the user configuring single letter remotes
and making sure we don't treat single letter remotes as a remote name,
but as a drive letter.
This commit is contained in:
Nick Craig-Wood 2015-02-07 15:49:09 +00:00
parent d64a37772f
commit 20ad96f3cd
4 changed files with 45 additions and 7 deletions

View File

@ -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)

12
fs/driveletter.go Normal file
View File

@ -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
}

13
fs/driveletter_windows.go Normal file
View File

@ -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')
}

View File

@ -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")