1
mirror of https://github.com/rclone/rclone synced 2024-11-24 01:26:25 +01:00

Make local filesystem go last

This commit is contained in:
Nick Craig-Wood 2013-06-29 12:15:55 +01:00
parent b98923a20f
commit 43be26d1f8
2 changed files with 9 additions and 8 deletions

View File

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

View File

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