Skip to content

Commit

Permalink
Fix module mount in sub folder
Browse files Browse the repository at this point in the history
This addresses a specific issue, but is a also a major simplification of the filesystem file mounts.

Fixes #6730
  • Loading branch information
bep committed Feb 3, 2020
1 parent 2997310 commit 80dd6dd
Show file tree
Hide file tree
Showing 10 changed files with 494 additions and 335 deletions.
3 changes: 1 addition & 2 deletions hugofs/decorators.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func DecorateBasePathFs(base *afero.BasePathFs) afero.Fs {
}

// NewBaseFileDecorator decorates the given Fs to provide the real filename
// and an Opener func. If
// and an Opener func.
func NewBaseFileDecorator(fs afero.Fs) afero.Fs {

ffs := &baseFileDecoratorFs{Fs: fs}
Expand All @@ -102,7 +102,6 @@ func NewBaseFileDecorator(fs afero.Fs) afero.Fs {

opener := func() (afero.File, error) {
return ffs.open(filename)

}

return decorateFileInfo(fi, ffs, opener, filename, "", meta), nil
Expand Down
34 changes: 29 additions & 5 deletions hugofs/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"os"
"path/filepath"
"runtime"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -271,13 +272,21 @@ func (fi *dirNameOnlyFileInfo) Sys() interface{} {
return nil
}

func newDirNameOnlyFileInfo(name string, isOrdered bool, fileOpener func() (afero.File, error)) FileMetaInfo {
func newDirNameOnlyFileInfo(name string, meta FileMeta, isOrdered bool, fileOpener func() (afero.File, error)) FileMetaInfo {
name = normalizeFilename(name)
_, base := filepath.Split(name)
return NewFileMetaInfo(&dirNameOnlyFileInfo{name: base}, FileMeta{
metaKeyFilename: name,
metaKeyIsOrdered: isOrdered,
metaKeyOpener: fileOpener})

m := copyFileMeta(meta)
if _, found := m[metaKeyFilename]; !found {
m.setIfNotZero(metaKeyFilename, name)
}
m[metaKeyOpener] = fileOpener
m[metaKeyIsOrdered] = isOrdered

return NewFileMetaInfo(
&dirNameOnlyFileInfo{name: base},
m,
)
}

func decorateFileInfo(
Expand Down Expand Up @@ -339,3 +348,18 @@ func fileInfosToNames(fis []os.FileInfo) []string {
}
return names
}

func fromSlash(filenames []string) []string {
for i, name := range filenames {
filenames[i] = filepath.FromSlash(name)
}
return filenames
}

func sortFileInfos(fis []os.FileInfo) {
sort.Slice(fis, func(i, j int) bool {
fimi, fimj := fis[i].(FileMetaInfo), fis[j].(FileMetaInfo)
return fimi.Meta().Filename() < fimj.Meta().Filename()

})
}
1 change: 1 addition & 0 deletions hugofs/nosymlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func TestNoSymlinkFs(t *testing.T) {
c.Assert(err, qt.IsNil)
// There is at least one unsported symlink inside workDir
_, err = f.Readdir(-1)
c.Assert(err, qt.IsNil)
f.Close()
c.Assert(logger.WarnCounter.Count(), qt.Equals, uint64(1))

Expand Down
Loading

0 comments on commit 80dd6dd

Please sign in to comment.