Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Feb 25, 2024
1 parent 189b723 commit b2fdb65
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 12 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/bep/lazycache v0.4.0
github.com/bep/logg v0.4.0
github.com/bep/mclib v1.20400.20402
github.com/bep/overlayfs v0.9.1
github.com/bep/overlayfs v0.9.2
github.com/bep/simplecobra v0.4.0
github.com/bep/tmc v0.5.1
github.com/clbanning/mxj/v2 v2.7.0
Expand Down Expand Up @@ -62,7 +62,7 @@ require (
github.com/spf13/afero v1.11.0
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
github.com/spf13/fsync v0.10.0
github.com/spf13/fsync v0.10.1
github.com/spf13/pflag v1.0.5
github.com/tdewolff/minify/v2 v2.20.17
github.com/tdewolff/parse/v2 v2.7.12
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ github.com/bep/mclib v1.20400.20402 h1:olpCE2WSPpOAbFE1R4hnftSEmQ34+xzy2HRzd0m69
github.com/bep/mclib v1.20400.20402/go.mod h1:pkrk9Kyfqg34Uj6XlDq9tdEFJBiL1FvCoCgVKRzw1EY=
github.com/bep/overlayfs v0.9.1 h1:SL54SV8A3zRkmQ+83Jj4TLE88jadHd5d1L4NpfmqJJs=
github.com/bep/overlayfs v0.9.1/go.mod h1:aYY9W7aXQsGcA7V9x/pzeR8LjEgIxbtisZm8Q7zPz40=
github.com/bep/overlayfs v0.9.2 h1:qJEmFInsW12L7WW7dOTUhnMfyk/fN9OCDEO5Gr8HSDs=
github.com/bep/overlayfs v0.9.2/go.mod h1:aYY9W7aXQsGcA7V9x/pzeR8LjEgIxbtisZm8Q7zPz40=
github.com/bep/simplecobra v0.4.0 h1:ufX/6WcOtEVJdCd7hsztTWURlZkOaWYOD+zCqrM8qUE=
github.com/bep/simplecobra v0.4.0/go.mod h1:evSM6iQqRwqpV7W4H4DlYFfe9mZ0x6Hj5GEOnIV7dI4=
github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI=
Expand Down Expand Up @@ -412,6 +414,8 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/fsync v0.10.0 h1:j+zUMN41zWj3sEqueD4mAsPDQwyOvMeJCcrawdmbqXk=
github.com/spf13/fsync v0.10.0/go.mod h1:y+B41vYq5i6Boa3Z+BVoPbDeOvxVkNU5OBXhoT8i4TQ=
github.com/spf13/fsync v0.10.1 h1:JRnB7G72b+gIBaBcpn5ibJSd7ww1iEahXSX2B8G6dSE=
github.com/spf13/fsync v0.10.1/go.mod h1:y+B41vYq5i6Boa3Z+BVoPbDeOvxVkNU5OBXhoT8i4TQ=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
15 changes: 12 additions & 3 deletions helpers/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,19 +322,28 @@ func IsWhitespace(r rune) bool {

// PrintFs prints the given filesystem to the given writer starting from the given path.
// This is useful for debugging.
func PrintFs(fs afero.Fs, path string, w io.Writer) {
func PrintFs(fs afero.Fs, path string, w io.Writer) error {
if fs == nil {
return
return nil
}

afero.Walk(fs, path, func(path string, info os.FileInfo, err error) error {
return afero.Walk(fs, path, func(path string, info os.FileInfo, err error) error {
if err != nil {
panic(fmt.Sprintf("error: path %q: %s", path, err))
}
path = filepath.ToSlash(path)
if path == "" {
path = "."
}
if !info.IsDir() {
// For tests. Open it and copy the content to io.Discard.
f, err := fs.Open(path)
if err != nil {
return err
}
defer f.Close()
io.Copy(io.Discard, f)
}
fmt.Fprintln(w, path, info.IsDir())
return nil
})
Expand Down
17 changes: 11 additions & 6 deletions hugofs/rootmapping_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ type keyRootMappings struct {
roots []RootMapping
}

func (rm *RootMapping) isDir() bool {
return rm.fiSingleFile == nil && rm.fi.IsDir()
}

func (rm *RootMapping) clean() {
rm.From = strings.Trim(filepath.Clean(rm.From), filepathSeparator)
rm.To = filepath.Clean(rm.To)
Expand Down Expand Up @@ -479,6 +483,7 @@ func (fs *RootMappingFs) getAncestors(prefix string) []keyRootMappings {

func (fs *RootMappingFs) newUnionFile(fis ...FileMetaInfo) (afero.File, error) {
if len(fis) == 1 {
fmt.Println("HERE???", fis[0].Meta().Filename)
return fis[0].Meta().Open()
}

Expand Down Expand Up @@ -551,7 +556,6 @@ func (rfs *RootMappingFs) collectDirEntries(prefix string) ([]iofs.DirEntry, err
}

for _, fi := range direntries {

meta := fi.(FileMetaInfo).Meta()
meta.Merge(rm.Meta)

Expand Down Expand Up @@ -704,13 +708,13 @@ func (fs *RootMappingFs) doStat(name string) ([]FileMetaInfo, error) {
fileCount := 0
var wasFiltered bool
for _, root := range roots {

meta := root.fi.Meta()
if !meta.InclusionFilter.Match(strings.TrimPrefix(meta.Filename, meta.SourceRoot), root.fi.IsDir()) {
if !meta.InclusionFilter.Match(strings.TrimPrefix(meta.Filename, meta.SourceRoot), root.isDir()) {
wasFiltered = true
continue
}

if !root.fi.IsDir() {
if root.fiSingleFile != nil {
fileCount++
}
if fileCount > 1 {
Expand All @@ -737,12 +741,13 @@ func (fs *RootMappingFs) doStat(name string) ([]FileMetaInfo, error) {
func (fs *RootMappingFs) statRoot(root RootMapping, filename string) (FileMetaInfo, error) {
dir, name := filepath.Split(filename)
if root.Meta.Rename != nil {
if n := root.Meta.Rename(name, false); n != name {
// TODO1 true vs false.
if n := root.Meta.Rename(name, true); n != name {
filename = filepath.Join(dir, n)
}
}

if !root.Meta.InclusionFilter.Match(root.trimFrom(filename), root.fi.IsDir()) {
if !root.Meta.InclusionFilter.Match(root.trimFrom(filename), root.isDir()) {
return nil, os.ErrNotExist
}

Expand Down
22 changes: 22 additions & 0 deletions hugolib/filesystems/basefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,28 @@ files/f2.txt false
`)
}

func TestMountIssue12141(t *testing.T) {
files := `
-- hugo.toml --
disableKinds = ["taxonomy", "term"]
[module]
[[module.mounts]]
source = "myfiles"
target = "static"
[[module.mounts]]
source = "myfiles/f1.txt"
target = "static/f2.txt"
-- myfiles/f1.txt --
f1
`
b := hugolib.Test(t, files)
fs := b.H.BaseFs.StaticFs("")

b.AssertFs(fs, `
asdf
`)
}

func checkFileCount(fs afero.Fs, dirname string, c *qt.C, expected int) {
c.Helper()
count, names, err := countFilesAndGetFilenames(fs, dirname)
Expand Down
2 changes: 1 addition & 1 deletion hugolib/integrationtest_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (s *IntegrationTestBuilder) AssertPublishDir(matches ...string) {
func (s *IntegrationTestBuilder) AssertFs(fs afero.Fs, matches ...string) {
s.Helper()
var buff bytes.Buffer
helpers.PrintFs(fs, "", &buff)
s.Assert(helpers.PrintFs(fs, "", &buff), qt.IsNil)
printFsLines := strings.Split(buff.String(), "\n")
sort.Strings(printFsLines)
content := strings.TrimSpace((strings.Join(printFsLines, "\n")))
Expand Down

0 comments on commit b2fdb65

Please sign in to comment.