diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-03-21 09:35:15 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-04-08 13:26:17 +0200 |
commit | d070bdf10f14d233288f7318a4e9f7555f070a65 (patch) | |
tree | fff8d59f98bdab3027bb45c4e10ca88594332872 /hugolib/filesystems | |
parent | b08193971a821fc27e549a73120c15e5e5186775 (diff) |
Rework the Destination filesystem to make --renderStaticToDisk work
See #9626
Diffstat (limited to 'hugolib/filesystems')
-rw-r--r-- | hugolib/filesystems/basefs.go | 24 | ||||
-rw-r--r-- | hugolib/filesystems/basefs_test.go | 17 |
2 files changed, 15 insertions, 26 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index 0290d2e1c..693dd8575 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -38,8 +38,8 @@ import ( "github.com/gohugoio/hugo/modules" + hpaths "github.com/gohugoio/hugo/common/paths" "github.com/gohugoio/hugo/hugofs" - "github.com/gohugoio/hugo/hugolib/paths" "github.com/spf13/afero" ) @@ -68,12 +68,12 @@ type BaseFs struct { // This usually maps to /my-project/public. PublishFs afero.Fs - // A read-only filesystem starting from the project workDir. - WorkDir afero.Fs - // The filesystem used for renderStaticToDisk. PublishFsStatic afero.Fs + // A read-only filesystem starting from the project workDir. + WorkDir afero.Fs + theBigFs *filesystemsCollector // Locks. @@ -434,21 +434,13 @@ 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)) + publishFs := hugofs.NewBaseFileDecorator(fs.PublishDir) sourceFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Source, p.WorkingDir)) - publishFsStatic := afero.NewBasePathFs(fs.Source, p.AbsPublishDir) - - // Same as sourceFs, but no decoration. This is what's used by os.ReadDir etc. - workDir := afero.NewBasePathFs(afero.NewReadOnlyFs(fs.Source), p.WorkingDir) + publishFsStatic := fs.PublishDirStatic b := &BaseFs{ SourceFs: sourceFs, - WorkDir: workDir, + WorkDir: fs.WorkingDirReadOnly, PublishFs: publishFs, PublishFsStatic: publishFsStatic, buildMu: lockedfile.MutexAt(filepath.Join(p.WorkingDir, lockFileBuild)), @@ -638,7 +630,7 @@ func (b *sourceFilesystemsBuilder) createModFs( if filepath.IsAbs(path) { return "", path } - return md.dir, paths.AbsPathify(md.dir, path) + return md.dir, hpaths.AbsPathify(md.dir, path) } for i, mount := range md.Mounts() { diff --git a/hugolib/filesystems/basefs_test.go b/hugolib/filesystems/basefs_test.go index 32d1eef71..a729e63b1 100644 --- a/hugolib/filesystems/basefs_test.go +++ b/hugolib/filesystems/basefs_test.go @@ -75,7 +75,7 @@ func initConfig(fs afero.Fs, cfg config.Provider) error { func TestNewBaseFs(t *testing.T) { c := qt.New(t) - v := config.New() + v := config.NewWithTestDefaults() fs := hugofs.NewMem(v) @@ -181,7 +181,7 @@ theme = ["atheme"] } func createConfig() config.Provider { - v := config.New() + v := config.NewWithTestDefaults() v.Set("contentDir", "mycontent") v.Set("i18nDir", "myi18n") v.Set("staticDir", "mystatic") @@ -219,22 +219,19 @@ func TestNewBaseFsEmpty(t *testing.T) { func TestRealDirs(t *testing.T) { c := qt.New(t) v := createConfig() + root, themesDir := t.TempDir(), t.TempDir() + v.Set("workingDir", root) + v.Set("themesDir", themesDir) + v.Set("theme", "mytheme") + fs := hugofs.NewDefault(v) sfs := fs.Source - root, err := afero.TempDir(sfs, "", "realdir") - c.Assert(err, qt.IsNil) - themesDir, err := afero.TempDir(sfs, "", "themesDir") - c.Assert(err, qt.IsNil) defer func() { os.RemoveAll(root) os.RemoveAll(themesDir) }() - v.Set("workingDir", root) - v.Set("themesDir", themesDir) - v.Set("theme", "mytheme") - c.Assert(sfs.MkdirAll(filepath.Join(root, "myassets", "scss", "sf1"), 0755), qt.IsNil) c.Assert(sfs.MkdirAll(filepath.Join(root, "myassets", "scss", "sf2"), 0755), qt.IsNil) c.Assert(sfs.MkdirAll(filepath.Join(themesDir, "mytheme", "assets", "scss", "sf2"), 0755), qt.IsNil) |