From aee9e11a400ac231eb9e91c005f1fe039b106396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 23 Dec 2021 08:57:28 +0100 Subject: [PATCH] Make sure we always create the /public folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Before this commit, when you had static files in the root of /content and no /public folder, that folder would not be created unless the /static syncer had already run. * So, with a common pattern doing `rm -rf public && hugo` would the fail now and then because /static and /content are processed in parallel (unless you have cleanDestinationDir=true) * This was even worse before commit 0b918e131fe523188b820d1e3fa0b08251abde69 – a frozen build. Closes #8166 --- hugolib/filesystems/basefs.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index a51cc4b27..aae3613f2 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -428,6 +428,11 @@ func NewBase(p *paths.Paths, logger loggers.Logger, options ...func(*BaseFs) err logger = loggers.NewWarningLogger() } + // Make sure we always have the /public folder ready to use. + if err := fs.Destination.MkdirAll(p.AbsPublishDir, 0777); err != nil && !os.IsExist(err) { + return nil, err + } + publishFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Destination, p.AbsPublishDir)) sourceFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Source, p.WorkingDir))