From e96cdfe9664cb38c3e16cc00cc630cf6f258d547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 28 May 2023 10:07:03 +0200 Subject: [PATCH] Don't create the public folder unless needed Fixes #11031 --- hugofs/fs.go | 6 +----- main_test.go | 5 +++++ testscripts/commands/hugo__noconfig.txt | 6 +++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/hugofs/fs.go b/hugofs/fs.go index 5dae3a78a..ce92a626d 100644 --- a/hugofs/fs.go +++ b/hugofs/fs.go @@ -116,13 +116,9 @@ func newFs(source, destination afero.Fs, workingDir, publishDir string) *Fs { panic("workingDir is too short") } + // If this does not exist, it will be created later. absPublishDir := paths.AbsPathify(workingDir, publishDir) - // Make sure we always have the /public folder ready to use. - if err := source.MkdirAll(absPublishDir, 0777); err != nil && !os.IsExist(err) { - panic(err) - } - pubFs := afero.NewBasePathFs(destination, absPublishDir) return &Fs{ diff --git a/main_test.go b/main_test.go index ffd700d57..73b9a0838 100644 --- a/main_test.go +++ b/main_test.go @@ -132,6 +132,11 @@ var commonTestScriptsParam = testscript.Params{ if err != nil { ts.Fatalf("%v", err) } + if len(fis) == 0 { + // To simplify empty dir checks. + fmt.Fprintln(ts.Stdout(), "Empty dir") + return + } for _, fi := range fis { fmt.Fprintf(ts.Stdout(), "%s %04o %s %s\n", fi.Mode(), fi.Mode().Perm(), fi.ModTime().Format(time.RFC3339Nano), fi.Name()) } diff --git a/testscripts/commands/hugo__noconfig.txt b/testscripts/commands/hugo__noconfig.txt index c3a6f6588..21fbdb9a0 100644 --- a/testscripts/commands/hugo__noconfig.txt +++ b/testscripts/commands/hugo__noconfig.txt @@ -1,4 +1,8 @@ +mkdir mysite +cd mysite ! hugo -stderr 'Unable to locate config file or config directory' \ No newline at end of file +stderr 'Unable to locate config file or config directory' +ls . +stdout 'Empty dir' \ No newline at end of file