From 43be26d1f8cf5094f67a47b5edfe4e15d4f3fee7 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 29 Jun 2013 12:15:55 +0100 Subject: [PATCH] Make local filesystem go last --- fs/fs.go | 11 ++++++++--- local/fs.go | 6 +----- 2 files changed, 9 insertions(+), 8 deletions(-) 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