Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip: working implementation
  • Loading branch information
rymut committed Dec 16, 2024
commit 397bbb2afc8b11ee779b287634a34b28ca28bb6f
18 changes: 17 additions & 1 deletion hugofs/component_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"path"
"runtime"
"sort"
"fmt"

"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/paths"
Expand Down Expand Up @@ -215,7 +216,22 @@ func (fs *componentFs) applyMeta(fi FileNameIsDir, name string) (FileMetaInfo, b
}

func (f *componentFsDir) Readdir(count int) ([]os.FileInfo, error) {
panic("not supported: Use ReadDir")
dirnames, err := f.Readdirnames(count)
if err != nil {
return nil, fmt.Errorf("error readdirnames: %s", err)
}
files := make([]os.FileInfo, len(dirnames))
for i, d := range dirnames {
file, e := f.fs.Stat(d)
if e != nil {
return nil, fmt.Errorf("error reading dir stat %s: %s", d, e)
}
files[i] = file
}
return files, nil

// fmt.Printf("this is error here\n")
// panic("not supported: Use ReadDir")
}

func (f *componentFsDir) Readdirnames(count int) ([]string, error) {
Expand Down
55 changes: 54 additions & 1 deletion hugofs/rootmapping_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,19 +832,72 @@ func (f *rootMappingDir) Stat() (iofs.FileInfo, error) {
}

func (f *rootMappingDir) Readdir(count int) ([]os.FileInfo, error) {
panic("not supported: use ReadDir")
//panic("not supported: use ReadDir")
/*
dirs, err := f.ReadDir(count)
fmt.Printf("collected files are : %s", dirs)
if err != nil {
return nil, err
}
return dirEntriesToFileInfo(dirs), nil
*/

/*
items, err := f.ReadDir(count)
fmt.Printf("collected files are : %s", items)
if err != nil {
return nil, fmt.Errorf("error readdirnames: %s", err)
}
files := make([]os.FileInfo, len(items))
for i, item := range items {
file, e := item.Info()
if e != nil {
// return nil, fmt.Errorf("error reading dir stat %s: %s", d, e)
}
files[i] = file
}
return files, nil
*/

dirnames, err := f.Readdirnames(count)
fmt.Printf("collected files are : %s\n", dirnames)
if err != nil {
return nil, fmt.Errorf("error readdirnames: %s\n", err)
}
files := make([]os.FileInfo, len(dirnames))
for i, d := range dirnames {
file, e := f.fs.Stat("layouts")
if e != nil {
fmt.Printf("cannot state file %s : %s\n", d, e)

// return nil, fmt.Errorf("error reading dir stat %s: %s", d, e)
}
files[i] = file
}
return files, nil
}

// Note that Readdirnames preserves the order of the underlying filesystem(s),
// which is usually directory order.
func (f *rootMappingDir) Readdirnames(count int) ([]string, error) {
fmt.Printf("\nCALLING READDIRNAMES %d\n", count)
dirs, err := f.ReadDir(count)
fmt.Printf("have %s --- \n", dirs)
if err != nil {
return nil, err
}
return dirEntriesToNames(dirs), nil
}

func dirEntriesToFileInfo(fis []iofs.DirEntry) []os.FileInfo {
names := make([]os.FileInfo, len(fis))
for i, d := range fis {
info, _ := d.Info()
names[i] = info
}
return names
}

func dirEntriesToNames(fis []iofs.DirEntry) []string {
names := make([]string, len(fis))
for i, d := range fis {
Expand Down
28 changes: 25 additions & 3 deletions tpl/os/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/bep/overlayfs"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/hugofs"
"github.com/spf13/afero"
"github.com/spf13/cast"
)
Expand Down Expand Up @@ -134,14 +135,35 @@ func (ns *Namespace) ReadDir(i any, mode ...any) ([]_os.FileInfo, error) {
if (len(mode) != 0) {
old, err = cast.ToBoolE(mode[0])
if err != nil {
return nil, err
return nil, fmt.Errorf("cannot convert value to bool %s: %s", mode[0], err)
}
}
var list []_os.FileInfo
if (old) {
list, err = afero.ReadDir(ns.workFs, path)
//list, err = afero.ReadDir(ns.workFs, path)
} else {
list, err = afero.ReadDir(ns.projectFs, path)
file, _ := ns.projectFs.Open(path)
fmt.Printf("path %s content %T %s", path, file, file)
switch item := file.(type) {
case *overlayfs.Dir:
list, err = item.Readdir(0)
case hugofs.DirOnlyOps: // fully virtual directory // hugofs.rootMappingDir
fmt.Printf("\ndir only opts!!!!\n")
//list, err = item.Readdir(0)
//fmt.Printf("\ndir contents %s: %s\n", list, err)
items, _ := item.Readdirnames(0)
list = make([]_os.FileInfo, len(items))
for i, d := range items {
file, _ := ns.projectFs.Stat(path + "/" + d)
list[i] = file
}
fmt.Printf("\ndir only opts %s!!!!\n", items)
default:
//list, err = afero.ReadDir(ns.projectFs, path)
}
if file != nil {
file.Close()
}
}
if err != nil {
return nil, fmt.Errorf("failed to read directory %q: %s", path, err)
Expand Down