summaryrefslogtreecommitdiffstats
path: root/hugofs/rootmapping_fs.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-03 17:27:40 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-08 20:13:39 +0200
commit7ff0a8ee9fe8d710d407e57faf1fda43bd635f28 (patch)
tree4baa7d913f735cc1089e465b51ff007014bfe25a /hugofs/rootmapping_fs.go
parentdf374851a0683f1446f33a4afef74c42f7d3eaaf (diff)
Simplify page tree logic
This is preparation for #6041. For historic reasons, the code for bulding the section tree and the taxonomies were very much separate. This works, but makes it hard to extend, maintain, and possibly not so fast as it could be. This simplification also introduces 3 slightly breaking changes, which I suspect most people will be pleased about. See referenced issues: This commit also switches the radix tree dependency to a mutable implementation: github.com/armon/go-radix. Fixes #6154 Fixes #6153 Fixes #6152
Diffstat (limited to 'hugofs/rootmapping_fs.go')
-rw-r--r--hugofs/rootmapping_fs.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/hugofs/rootmapping_fs.go b/hugofs/rootmapping_fs.go
index 37b40a204..e5679e09b 100644
--- a/hugofs/rootmapping_fs.go
+++ b/hugofs/rootmapping_fs.go
@@ -23,7 +23,7 @@ import (
"github.com/pkg/errors"
- radix "github.com/hashicorp/go-immutable-radix"
+ radix "github.com/armon/go-radix"
"github.com/spf13/afero"
)
@@ -33,7 +33,7 @@ var filepathSeparator = string(filepath.Separator)
// of root mappings with some optional metadata about the root.
// Note that From represents a virtual root that maps to the actual filename in To.
func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) {
- rootMapToReal := radix.New().Txn()
+ rootMapToReal := radix.New()
for _, rm := range rms {
(&rm).clean()
@@ -58,7 +58,7 @@ func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) {
// Extract "blog" from "content/blog"
rm.path = strings.TrimPrefix(strings.TrimPrefix(rm.From, fromBase), filepathSeparator)
- key := []byte(rm.rootKey())
+ key := rm.rootKey()
var mappings []RootMapping
v, found := rootMapToReal.Get(key)
if found {
@@ -71,7 +71,7 @@ func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) {
rfs := &RootMappingFs{Fs: fs,
virtualRoots: rms,
- rootMapToReal: rootMapToReal.Commit().Root()}
+ rootMapToReal: rootMapToReal}
return rfs, nil
}
@@ -119,7 +119,7 @@ func (r RootMapping) rootKey() string {
// in the order given.
type RootMappingFs struct {
afero.Fs
- rootMapToReal *radix.Node
+ rootMapToReal *radix.Tree
virtualRoots []RootMapping
filter func(r RootMapping) bool
}
@@ -303,8 +303,8 @@ func (fs *RootMappingFs) isRoot(name string) bool {
}
func (fs *RootMappingFs) getRoots(name string) []RootMapping {
- nameb := []byte(filepath.Clean(name))
- _, v, found := fs.rootMapToReal.LongestPrefix(nameb)
+ name = filepath.Clean(name)
+ _, v, found := fs.rootMapToReal.LongestPrefix(name)
if !found {
return nil
}
@@ -333,10 +333,10 @@ func (fs *RootMappingFs) getRootsWithPrefix(prefix string) []RootMapping {
if fs.isRoot(prefix) {
return fs.virtualRoots
}
- prefixb := []byte(filepath.Clean(prefix))
+ prefix = filepath.Clean(prefix)
var roots []RootMapping
- fs.rootMapToReal.WalkPrefix(prefixb, func(b []byte, v interface{}) bool {
+ fs.rootMapToReal.WalkPrefix(prefix, func(b string, v interface{}) bool {
roots = append(roots, v.([]RootMapping)...)
return false
})