summaryrefslogtreecommitdiffstats
path: root/hugofs
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-02-21 20:16:02 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-02-22 15:36:27 +0100
commit16406d9d77cb4861bba9df8ca39e7dadfe41eb45 (patch)
treef32a3921081e40a748613bd87eba7940d6b975db /hugofs
parente75784930dca9e367019ce498fd15076a63edb34 (diff)
Fix regression on handling of overlapping file mounts
But note that the overlay file system is set up horizontally (project -> module1 -> module2), so I would not recommend too complex overlapping mount setups within the same module. But this worked in v0.122.0, so we should fix it. Fixes #12103
Diffstat (limited to 'hugofs')
-rw-r--r--hugofs/rootmapping_fs.go39
1 files changed, 32 insertions, 7 deletions
diff --git a/hugofs/rootmapping_fs.go b/hugofs/rootmapping_fs.go
index 1efb8ee5f..ce4243fbb 100644
--- a/hugofs/rootmapping_fs.go
+++ b/hugofs/rootmapping_fs.go
@@ -323,7 +323,6 @@ func (fs *RootMappingFs) Stat(name string) (os.FileInfo, error) {
if err != nil {
return nil, err
}
-
return fis[0], nil
}
@@ -403,16 +402,42 @@ func (fs *RootMappingFs) getRoot(key string) []RootMapping {
}
func (fs *RootMappingFs) getRoots(key string) (string, []RootMapping) {
- return fs.getRootsIn(key, fs.rootMapToReal)
-}
+ tree := fs.rootMapToReal
+ levels := strings.Count(key, filepathSeparator)
+ seen := make(map[RootMapping]bool)
-func (fs *RootMappingFs) getRootsReverse(key string) (string, []RootMapping) {
- return fs.getRootsIn(key, fs.realMapToRoot)
+ var roots []RootMapping
+ var s string
+
+ for {
+ var found bool
+ ss, vv, found := tree.LongestPrefix(key)
+ if !found || (levels < 2 && ss == key) {
+ break
+ }
+
+ for _, rm := range vv.([]RootMapping) {
+ if !seen[rm] {
+ seen[rm] = true
+ roots = append(roots, rm)
+ }
+ }
+ s = ss
+
+ // We may have more than one root for this key, so walk up.
+ oldKey := key
+ key = filepath.Dir(key)
+ if key == oldKey {
+ break
+ }
+ }
+
+ return s, roots
}
-func (fs *RootMappingFs) getRootsIn(key string, tree *radix.Tree) (string, []RootMapping) {
+func (fs *RootMappingFs) getRootsReverse(key string) (string, []RootMapping) {
+ tree := fs.realMapToRoot
s, v, found := tree.LongestPrefix(key)
-
if !found {
return "", nil
}