summaryrefslogtreecommitdiffstats
path: root/hugofs
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-04-18 10:28:54 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-04-18 19:17:27 +0200
commite66e2e9ce5f2036174ecb114b96761ad023d95a1 (patch)
tree90cf4e7a352ab12970b7851a148accd2bdd5382f /hugofs
parent5de6f8a02c3abb3145ce7985dff985e9e783e9b3 (diff)
Revert "Revert "Fix PostProcess regression for hugo server""
This reverts commit 6c35a1a9eacf2aa86a11ecd31c4022ce330b2f16. Updates #9794
Diffstat (limited to 'hugofs')
-rw-r--r--hugofs/fs.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/hugofs/fs.go b/hugofs/fs.go
index 436387f13..63c25a4c0 100644
--- a/hugofs/fs.go
+++ b/hugofs/fs.go
@@ -65,7 +65,7 @@ type Fs struct {
// as source and destination file systems.
func NewDefault(cfg config.Provider) *Fs {
fs := Os
- return newFs(fs, cfg)
+ return newFs(fs, fs, cfg)
}
// NewMem creates a new Fs with the MemMapFs
@@ -73,17 +73,23 @@ func NewDefault(cfg config.Provider) *Fs {
// Useful for testing.
func NewMem(cfg config.Provider) *Fs {
fs := &afero.MemMapFs{}
- return newFs(fs, cfg)
+ return newFs(fs, fs, cfg)
}
// NewFrom creates a new Fs based on the provided Afero Fs
// as source and destination file systems.
// Useful for testing.
func NewFrom(fs afero.Fs, cfg config.Provider) *Fs {
- return newFs(fs, cfg)
+ return newFs(fs, fs, cfg)
}
-func newFs(base afero.Fs, cfg config.Provider) *Fs {
+// NewFrom creates a new Fs based on the provided Afero Fss
+// as the source and destination file systems.
+func NewFromSourceAndDestination(source, destination afero.Fs, cfg config.Provider) *Fs {
+ return newFs(source, destination, cfg)
+}
+
+func newFs(source, destination afero.Fs, cfg config.Provider) *Fs {
workingDir := cfg.GetString("workingDir")
publishDir := cfg.GetString("publishDir")
if publishDir == "" {
@@ -91,27 +97,27 @@ func newFs(base afero.Fs, cfg config.Provider) *Fs {
}
// Sanity check
- if IsOsFs(base) && len(workingDir) < 2 {
+ if IsOsFs(source) && len(workingDir) < 2 {
panic("workingDir is too short")
}
absPublishDir := paths.AbsPathify(workingDir, publishDir)
// Make sure we always have the /public folder ready to use.
- if err := base.MkdirAll(absPublishDir, 0777); err != nil && !os.IsExist(err) {
+ if err := source.MkdirAll(absPublishDir, 0777); err != nil && !os.IsExist(err) {
panic(err)
}
- pubFs := afero.NewBasePathFs(base, absPublishDir)
+ pubFs := afero.NewBasePathFs(destination, absPublishDir)
return &Fs{
- Source: base,
+ Source: source,
PublishDir: pubFs,
PublishDirServer: pubFs,
PublishDirStatic: pubFs,
Os: &afero.OsFs{},
- WorkingDirReadOnly: getWorkingDirFsReadOnly(base, workingDir),
- WorkingDirWritable: getWorkingDirFsWritable(base, workingDir),
+ WorkingDirReadOnly: getWorkingDirFsReadOnly(source, workingDir),
+ WorkingDirWritable: getWorkingDirFsWritable(source, workingDir),
}
}