diff options
Diffstat (limited to 'hugofs/fs.go')
-rw-r--r-- | hugofs/fs.go | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/hugofs/fs.go b/hugofs/fs.go index 3afa17956..1ddb98214 100644 --- a/hugofs/fs.go +++ b/hugofs/fs.go @@ -16,7 +16,7 @@ package hugofs import ( "github.com/spf13/afero" - "github.com/spf13/viper" + "github.com/spf13/hugo/config" ) // Os points to an Os Afero file system. @@ -39,30 +39,37 @@ type Fs struct { // NewDefault creates a new Fs with the OS file system // as source and destination file systems. -func NewDefault() *Fs { +func NewDefault(cfg config.Provider) *Fs { fs := &afero.OsFs{} - return newFs(fs) + return newFs(fs, cfg) } // NewDefault creates a new Fs with the MemMapFs // as source and destination file systems. // Useful for testing. -func NewMem() *Fs { +func NewMem(cfg config.Provider) *Fs { fs := &afero.MemMapFs{} - return newFs(fs) + return newFs(fs, cfg) } -func newFs(base afero.Fs) *Fs { +// 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) +} + +func newFs(base afero.Fs, cfg config.Provider) *Fs { return &Fs{ Source: base, Destination: base, Os: &afero.OsFs{}, - WorkingDir: getWorkingDirFs(base), + WorkingDir: getWorkingDirFs(base, cfg), } } -func getWorkingDirFs(base afero.Fs) *afero.BasePathFs { - workingDir := viper.GetString("workingDir") +func getWorkingDirFs(base afero.Fs, cfg config.Provider) *afero.BasePathFs { + workingDir := cfg.GetString("workingDir") if workingDir != "" { return afero.NewBasePathFs(afero.NewReadOnlyFs(base), workingDir).(*afero.BasePathFs) |