mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
parent
dd6d0a6de1
commit
3c51625c71
2 changed files with 32 additions and 1 deletions
|
@ -49,3 +49,29 @@ START:|{{ range $entry := $entries }}{{ if not $entry.IsDir }}{{ $entry.Name }}|
|
|||
START:|config.toml|myproject.txt|:END:
|
||||
`)
|
||||
}
|
||||
|
||||
// Issue 9620
|
||||
func TestReadFileNotExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- config.toml --
|
||||
-- layouts/index.html --
|
||||
{{ $fi := (readFile "doesnotexist") }}
|
||||
{{ if $fi }}Failed{{ else }}OK{{ end }}
|
||||
|
||||
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: true,
|
||||
},
|
||||
).Build()
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
OK
|
||||
`)
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/bep/overlayfs"
|
||||
"github.com/gohugoio/hugo/common/herrors"
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
"github.com/spf13/afero"
|
||||
"github.com/spf13/cast"
|
||||
|
@ -101,7 +102,11 @@ func (ns *Namespace) ReadFile(i any) (string, error) {
|
|||
s = ns.deps.PathSpec.RelPathify(s)
|
||||
}
|
||||
|
||||
return readFile(ns.readFileFs, s)
|
||||
s, err = readFile(ns.readFileFs, s)
|
||||
if err != nil && herrors.IsNotExist(err) {
|
||||
return "", nil
|
||||
}
|
||||
return s, err
|
||||
}
|
||||
|
||||
// ReadDir lists the directory contents relative to the configured WorkingDir.
|
||||
|
|
Loading…
Reference in a new issue