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
+`)
+}
"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"
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.