summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-02-28 09:12:41 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-02-28 13:38:12 +0100
commita322282e70c2935c79f9c0f5c593bfdd032eb964 (patch)
treee70177f71b79c3e1212b5b3584d1a68272a7c3dd /hugolib
parent6bc0d745a5897b70a9356035f959ee0310e83fc9 (diff)
Fix single mount rename panic
Fixes #12141
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/filesystems/basefs.go2
-rw-r--r--hugolib/filesystems/basefs_test.go25
-rw-r--r--hugolib/integrationtest_builder.go30
3 files changed, 55 insertions, 2 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go
index 5479e2266..aa466e0eb 100644
--- a/hugolib/filesystems/basefs.go
+++ b/hugolib/filesystems/basefs.go
@@ -1,4 +1,4 @@
-// Copyright 2018 The Hugo Authors. All rights reserved.
+// Copyright 2024 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
diff --git a/hugolib/filesystems/basefs_test.go b/hugolib/filesystems/basefs_test.go
index f50bdb09f..4fdeba765 100644
--- a/hugolib/filesystems/basefs_test.go
+++ b/hugolib/filesystems/basefs_test.go
@@ -234,6 +234,7 @@ foo
b := hugolib.Test(t, files)
bfs := b.H.BaseFs
watchFilenames := bfs.WatchFilenames()
+ // []string{"/hugo_stats.json", "/content", "/content2", "/themes/t1/layouts", "/themes/t1/layouts/_default", "/themes/t1/static"}
b.Assert(watchFilenames, qt.HasLen, 6)
}
@@ -543,6 +544,30 @@ 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, `
+. true
+f1.txt false
+f2.txt false
+`)
+}
+
func checkFileCount(fs afero.Fs, dirname string, c *qt.C, expected int) {
c.Helper()
count, names, err := countFilesAndGetFilenames(fs, dirname)
diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go
index acbc093ba..642bac7ab 100644
--- a/hugolib/integrationtest_builder.go
+++ b/hugolib/integrationtest_builder.go
@@ -282,7 +282,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(s.printAndCheckFs(fs, "", &buff), qt.IsNil)
printFsLines := strings.Split(buff.String(), "\n")
sort.Strings(printFsLines)
content := strings.TrimSpace((strings.Join(printFsLines, "\n")))
@@ -305,6 +305,34 @@ func (s *IntegrationTestBuilder) AssertFs(fs afero.Fs, matches ...string) {
}
}
+func (s *IntegrationTestBuilder) printAndCheckFs(fs afero.Fs, path string, w io.Writer) error {
+ if fs == nil {
+ return nil
+ }
+
+ return afero.Walk(fs, path, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ return fmt.Errorf("error: path %q: %s", path, err)
+ }
+ path = filepath.ToSlash(path)
+ if path == "" {
+ path = "."
+ }
+ if !info.IsDir() {
+ f, err := fs.Open(path)
+ if err != nil {
+ return fmt.Errorf("error: path %q: %s", path, err)
+ }
+ defer f.Close()
+ // This will panic if the file is a directory.
+ var buf [1]byte
+ io.ReadFull(f, buf[:])
+ }
+ fmt.Fprintln(w, path, info.IsDir())
+ return nil
+ })
+}
+
func (s *IntegrationTestBuilder) AssertFileExists(filename string, b bool) {
checker := qt.IsNil
if !b {