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
This commit is contained in:
Bjørn Erik Pedersen 2024-02-21 20:16:02 +01:00
parent e75784930d
commit 16406d9d77
5 changed files with 111 additions and 12 deletions

View file

@ -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)
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) getRootsReverse(key string) (string, []RootMapping) {
return fs.getRootsIn(key, fs.realMapToRoot)
}
func (fs *RootMappingFs) getRootsIn(key string, tree *radix.Tree) (string, []RootMapping) {
tree := fs.realMapToRoot
s, v, found := tree.LongestPrefix(key)
if !found {
return "", nil
}