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

Make local filesystem go last

Nick Craig-Wood43be26d1f8cf
diff --git a/fs/fs.go b/fs/fs.go
index 3446b77a1..d87d7f75a 100644
--- a/fs/fs.go
+++ b/fs/fs.go
@@ -27,8 +27,6 @@ type ConfigInfo struct {
Transfers int
}
-// FIXME need local to go last
-
// Filesystem registry item
type registryItem struct {
match *regexp.Regexp // if this matches then can call newFs
@@ -39,9 +37,16 @@ type registryItem struct {
//
// If a path matches with match then can call newFs on it
//
+// Pass with match nil goes last and matches everything (used by local fs)
+//
// Fs modules should use this in an init() function
func Register(match *regexp.Regexp, newFs func(string) (Fs, error)) {
fsRegistry = append(fsRegistry, registryItem{match: match, newFs: newFs})
+ // Keep one nil match at the end
+ last := len(fsRegistry) - 1
+ if last >= 1 && fsRegistry[last-1].match == nil {
+ fsRegistry[last], fsRegistry[last-1] = fsRegistry[last-1], fsRegistry[last]
+ }
}
// A Filesystem, describes the local filesystem and the remote object store
@@ -136,7 +141,7 @@ type DirChan chan *Dir
// FIXME make more generic
func NewFs(path string) (Fs, error) {
for _, item := range fsRegistry {
- if item.match.MatchString(path) {
+ if item.match == nil || item.match.MatchString(path) {
return item.newFs(path)
}
}
diff --git a/local/fs.go b/local/fs.go
index e7bbed7f8..c7a8a89a9 100644
--- a/local/fs.go
+++ b/local/fs.go
@@ -11,17 +11,13 @@ import (
"os"
"path"
"path/filepath"
- "regexp"
"sync"
"time"
)
-// Pattern to match a local url (matches anything)
-var Match = regexp.MustCompile(``)
-
// Register with Fs
func init() {
- fs.Register(Match, NewFs)
+ fs.Register(nil, NewFs)
}
// FsLocal represents a local filesystem rooted at root