providers/os: readDir now returns a slice of fs.DirEntry
This commit is contained in:
parent
dc378008d6
commit
eb7da68de6
@ -2,23 +2,12 @@ package os
|
|||||||
|
|
||||||
import "os"
|
import "os"
|
||||||
import "io"
|
import "io"
|
||||||
import "time"
|
|
||||||
import "io/fs"
|
import "io/fs"
|
||||||
import "html/template"
|
import "html/template"
|
||||||
import "git.tebibyte.media/sashakoshka/step"
|
import "git.tebibyte.media/sashakoshka/step"
|
||||||
|
|
||||||
var _ step.FuncProviderFor = new(Provider)
|
var _ step.FuncProviderFor = new(Provider)
|
||||||
|
|
||||||
// FileInfo is like the fs.FileInfo interface, but it directly contains the
|
|
||||||
// values instead of having getters for them.
|
|
||||||
type FileInfo struct {
|
|
||||||
Name string
|
|
||||||
Size int64
|
|
||||||
Mode fs.FileMode
|
|
||||||
ModTime time.Time
|
|
||||||
IsDir bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Provider provides OS functions.
|
// Provider provides OS functions.
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
|
|
||||||
@ -80,18 +69,10 @@ func (this *state) funcIsDir (name string) (bool, error) {
|
|||||||
return info.IsDir(), nil
|
return info.IsDir(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *state) funcStatFile (name string) (FileInfo, error) {
|
func (this *state) funcStatFile (name string) (fs.FileInfo, error) {
|
||||||
name, err := this.document.Rel(name)
|
name, err := this.document.Rel(name)
|
||||||
if err != nil { return FileInfo { }, err }
|
if err != nil { return nil, err }
|
||||||
info, err := os.Stat(name)
|
return os.Stat(name)
|
||||||
if err != nil { return FileInfo { }, err }
|
|
||||||
return FileInfo {
|
|
||||||
Name: info.Name(),
|
|
||||||
Size: info.Size(),
|
|
||||||
Mode: info.Mode(),
|
|
||||||
ModTime: info.ModTime(),
|
|
||||||
IsDir: info.IsDir(),
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *state) funcReadFile (name string) (string, error) {
|
func (this *state) funcReadFile (name string) (string, error) {
|
||||||
@ -105,16 +86,10 @@ func (this *state) funcReadFile (name string) (string, error) {
|
|||||||
return string(buffer), nil
|
return string(buffer), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *state) funcReadDir (name string) ([]string, error) {
|
func (this *state) funcReadDir (name string) ([]fs.DirEntry, error) {
|
||||||
name, err := this.document.Rel(name)
|
name, err := this.document.Rel(name)
|
||||||
if err != nil { return nil, err }
|
if err != nil { return nil, err }
|
||||||
entries, err := os.ReadDir(name)
|
return os.ReadDir(name)
|
||||||
if err != nil { return nil, err }
|
|
||||||
names := make([]string, len(entries))
|
|
||||||
for index, entry := range entries {
|
|
||||||
names[index] = entry.Name()
|
|
||||||
}
|
|
||||||
return names, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *state) funcWriteFile (name, content string) error {
|
func (this *state) funcWriteFile (name, content string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user