Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tests: add root mapping test
  • Loading branch information
rymut committed Dec 18, 2024
commit 940c938f4b09395f73ddf38cb2b5f876cba23aae
10 changes: 6 additions & 4 deletions hugofs/rootmapping_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,12 @@ func (rfs *RootMappingFs) collectDirEntries(prefix string) ([]iofs.DirEntry, err
seen := make(map[string]bool) // Prevent duplicate directories
level := strings.Count(prefix, filepathSeparator)

// special case requesting root of filesystem
if prefix == filepathSeparator {
prefix = ""
level = 0
}

collectDir := func(rm RootMapping, fi FileMetaInfo) error {
f, err := fi.Meta().Open()
if err != nil {
Expand Down Expand Up @@ -593,10 +599,6 @@ func (rfs *RootMappingFs) collectDirEntries(prefix string) ([]iofs.DirEntry, err

// Next add any file mounts inside the given directory.
prefixInside := prefix + filepathSeparator
// When prefix is root then skip filepathSeparator.
if prefix == filepathSeparator {
prefixInside = prefix
}
rfs.rootMapToReal.WalkPrefix(prefixInside, func(s string, v any) bool {
if (strings.Count(s, filepathSeparator) - level) != 1 {
// This directory is not part of the current, but we
Expand Down
1 change: 1 addition & 0 deletions hugofs/rootmapping_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ func TestRootMappingFsMountOverlap(t *testing.T) {
c.Assert(names, qt.DeepEquals, expect, qt.Commentf(fmt.Sprintf("%#v", names)))
}

checkDirnames(".", []string{"static"})
checkDirnames("static", []string{"a.txt", "b", "e"})
checkDirnames("static/b", []string{"b.txt", "c"})
checkDirnames("static/b/c", []string{"c.txt"})
Expand Down