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:
parent
b98923a20f
commit
43be26d1f8
11
fs/fs.go
11
fs/fs.go
@ -27,8 +27,6 @@ type ConfigInfo struct {
|
|||||||
Transfers int
|
Transfers int
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME need local to go last
|
|
||||||
|
|
||||||
// Filesystem registry item
|
// Filesystem registry item
|
||||||
type registryItem struct {
|
type registryItem struct {
|
||||||
match *regexp.Regexp // if this matches then can call newFs
|
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
|
// 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
|
// Fs modules should use this in an init() function
|
||||||
func Register(match *regexp.Regexp, newFs func(string) (Fs, error)) {
|
func Register(match *regexp.Regexp, newFs func(string) (Fs, error)) {
|
||||||
fsRegistry = append(fsRegistry, registryItem{match: match, newFs: newFs})
|
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
|
// A Filesystem, describes the local filesystem and the remote object store
|
||||||
@ -136,7 +141,7 @@ type DirChan chan *Dir
|
|||||||
// FIXME make more generic
|
// FIXME make more generic
|
||||||
func NewFs(path string) (Fs, error) {
|
func NewFs(path string) (Fs, error) {
|
||||||
for _, item := range fsRegistry {
|
for _, item := range fsRegistry {
|
||||||
if item.match.MatchString(path) {
|
if item.match == nil || item.match.MatchString(path) {
|
||||||
return item.newFs(path)
|
return item.newFs(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Pattern to match a local url (matches anything)
|
|
||||||
var Match = regexp.MustCompile(``)
|
|
||||||
|
|
||||||
// Register with Fs
|
// Register with Fs
|
||||||
func init() {
|
func init() {
|
||||||
fs.Register(Match, NewFs)
|
fs.Register(nil, NewFs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FsLocal represents a local filesystem rooted at root
|
// FsLocal represents a local filesystem rooted at root
|
||||||
|
Loading…
Reference in New Issue
Block a user