diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-02-29 19:05:23 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-03-01 14:18:52 +0100 |
commit | 0d6e593ffb65a67206caa3c3071d94694cfc2183 (patch) | |
tree | 0ee6049b860bab29456152d0096e6869b66205b5 /hugofs | |
parent | 7023cf0f07d07bd943404d88d5fc8f3c5f7c9cc2 (diff) | |
download | hugo-0d6e593ffb65a67206caa3c3071d94694cfc2183.tar.gz hugo-0d6e593ffb65a67206caa3c3071d94694cfc2183.zip |
Fix and add integration test for the Bootstrap SCSS module for both Dart Sass and Libsass
This fixes the reverse filesystem lookup (absolute filename to path relative to the composite filesystem).
The old logic had some assumptions about the locality of the actual files that didn't work in more complex scenarios.
This commit now also adds the popular Bootstrap SCSS Hugo module to the CI build (both for libsass and dartsass transpiler), so we can hopefully avoid similar future breakage.
Fixes #12178
Diffstat (limited to 'hugofs')
-rw-r--r-- | hugofs/rootmapping_fs.go | 49 | ||||
-rw-r--r-- | hugofs/rootmapping_fs_test.go | 6 |
2 files changed, 29 insertions, 26 deletions
diff --git a/hugofs/rootmapping_fs.go b/hugofs/rootmapping_fs.go index a5bf9aadf..336c8b4e7 100644 --- a/hugofs/rootmapping_fs.go +++ b/hugofs/rootmapping_fs.go @@ -21,6 +21,7 @@ import ( "path" "path/filepath" "strings" + "sync/atomic" "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/paths" @@ -43,6 +44,7 @@ var _ ReverseLookupProvder = (*RootMappingFs)(nil) func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) { rootMapToReal := radix.New() realMapToRoot := radix.New() + id := fmt.Sprintf("rfs-%d", rootMappingFsCounter.Add(1)) addMapping := func(key string, rm RootMapping, to *radix.Tree) { var mappings []RootMapping @@ -76,6 +78,16 @@ func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) { rm.Meta = NewFileMeta() } + if rm.FromBase == "" { + panic(" rm.FromBase is empty") + } + + rm.Meta.Component = rm.FromBase + rm.Meta.Module = rm.Module + rm.Meta.ModuleOrdinal = rm.ModuleOrdinal + rm.Meta.IsProject = rm.IsProject + rm.Meta.BaseDir = rm.ToBase + if !fi.IsDir() { // We do allow single file mounts. // However, the file system logic will be much simpler with just directories. @@ -122,19 +134,9 @@ func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) { } } - if rm.FromBase == "" { - panic(" rm.FromBase is empty") - } - // Extract "blog" from "content/blog" rm.path = strings.TrimPrefix(strings.TrimPrefix(rm.From, rm.FromBase), filepathSeparator) - rm.Meta.SourceRoot = fi.(MetaProvider).Meta().Filename - rm.Meta.BaseDir = rm.ToBase - rm.Meta.Module = rm.Module - rm.Meta.ModuleOrdinal = rm.ModuleOrdinal - rm.Meta.Component = rm.FromBase - rm.Meta.IsProject = rm.IsProject meta := rm.Meta.Copy() @@ -156,6 +158,7 @@ func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) { } rfs := &RootMappingFs{ + id: id, Fs: fs, rootMapToReal: rootMapToReal, realMapToRoot: realMapToRoot, @@ -227,11 +230,14 @@ var _ FilesystemUnwrapper = (*RootMappingFs)(nil) // is directories only, and they will be returned in Readdir and Readdirnames // in the order given. type RootMappingFs struct { + id string afero.Fs rootMapToReal *radix.Tree realMapToRoot *radix.Tree } +var rootMappingFsCounter atomic.Int32 + func (fs *RootMappingFs) Mounts(base string) ([]FileMetaInfo, error) { base = filepathSeparator + fs.cleanName(base) roots := fs.getRootsWithPrefix(base) @@ -263,6 +269,10 @@ func (fs *RootMappingFs) Mounts(base string) ([]FileMetaInfo, error) { return fss, nil } +func (fs *RootMappingFs) Key() string { + return fs.id +} + func (fs *RootMappingFs) UnwrapFilesystem() afero.Fs { return fs.Fs } @@ -320,16 +330,16 @@ func (c ComponentPath) ComponentPathJoined() string { } type ReverseLookupProvder interface { - ReverseLookup(filename string, checkExists bool) ([]ComponentPath, error) - ReverseLookupComponent(component, filename string, checkExists bool) ([]ComponentPath, error) + ReverseLookup(filename string) ([]ComponentPath, error) + ReverseLookupComponent(component, filename string) ([]ComponentPath, error) } // func (fs *RootMappingFs) ReverseStat(filename string) ([]FileMetaInfo, error) -func (fs *RootMappingFs) ReverseLookup(filename string, checkExists bool) ([]ComponentPath, error) { - return fs.ReverseLookupComponent("", filename, checkExists) +func (fs *RootMappingFs) ReverseLookup(filename string) ([]ComponentPath, error) { + return fs.ReverseLookupComponent("", filename) } -func (fs *RootMappingFs) ReverseLookupComponent(component, filename string, checkExists bool) ([]ComponentPath, error) { +func (fs *RootMappingFs) ReverseLookupComponent(component, filename string) ([]ComponentPath, error) { filename = fs.cleanName(filename) key := filepathSeparator + filename @@ -360,14 +370,6 @@ func (fs *RootMappingFs) ReverseLookupComponent(component, filename string, chec } else { // Now we know that this file _could_ be in this fs. filename = filepathSeparator + filepath.Join(first.path, dir, name) - - if checkExists { - // Confirm that it exists. - _, err := fs.Stat(first.FromBase + filename) - if err != nil { - continue - } - } } cps = append(cps, ComponentPath{ @@ -667,6 +669,7 @@ func (fs *RootMappingFs) doStat(name string) ([]FileMetaInfo, error) { var fis []FileMetaInfo for _, rm := range roots { + var fi FileMetaInfo fi, err = fs.statRoot(rm, name) if err == nil { diff --git a/hugofs/rootmapping_fs_test.go b/hugofs/rootmapping_fs_test.go index b1ef102d3..83a95d648 100644 --- a/hugofs/rootmapping_fs_test.go +++ b/hugofs/rootmapping_fs_test.go @@ -276,20 +276,20 @@ func TestRootMappingFsMount(t *testing.T) { // Test ReverseLookup. // Single file mounts. - cps, err := rfs.ReverseLookup(filepath.FromSlash("singlefiles/no.txt"), true) + cps, err := rfs.ReverseLookup(filepath.FromSlash("singlefiles/no.txt")) c.Assert(err, qt.IsNil) c.Assert(cps, qt.DeepEquals, []ComponentPath{ {Component: "content", Path: "singles/p1.md", Lang: "no"}, }) - cps, err = rfs.ReverseLookup(filepath.FromSlash("singlefiles/sv.txt"), true) + cps, err = rfs.ReverseLookup(filepath.FromSlash("singlefiles/sv.txt")) c.Assert(err, qt.IsNil) c.Assert(cps, qt.DeepEquals, []ComponentPath{ {Component: "content", Path: "singles/p1.md", Lang: "sv"}, }) // File inside directory mount. - cps, err = rfs.ReverseLookup(filepath.FromSlash("mynoblogcontent/test.txt"), true) + cps, err = rfs.ReverseLookup(filepath.FromSlash("mynoblogcontent/test.txt")) c.Assert(err, qt.IsNil) c.Assert(cps, qt.DeepEquals, []ComponentPath{ {Component: "content", Path: "blog/test.txt", Lang: "no"}, |