filelist/*: implement FileLister in existing types

This commit is contained in:
Clayton Craft
2023-02-18 11:17:18 -08:00
parent e5002f5750
commit 6c2f7b972b
4 changed files with 51 additions and 25 deletions

View File

@@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
)
@@ -22,13 +23,13 @@ func New(filePath string) *HookFiles {
}
}
func (h *HookFiles) List() ([]string, error) {
func (h *HookFiles) List() (*filelist.FileList, error) {
log.Println("- Including files")
fileInfo, err := os.ReadDir(h.filePath)
if err != nil {
return nil, fmt.Errorf("getHookFiles: unable to read hook file dir: %w", err)
}
files := []string{}
files := filelist.NewFileList()
for _, file := range fileInfo {
path := filepath.Join(h.filePath, file.Name())
f, err := os.Open(path)
@@ -40,10 +41,12 @@ func (h *HookFiles) List() ([]string, error) {
log.Printf("-- Including files from: %s\n", path)
s := bufio.NewScanner(f)
for s.Scan() {
if filelist, err := misc.GetFiles([]string{s.Text()}, true); err != nil {
if fFiles, err := misc.GetFiles([]string{s.Text()}, true); err != nil {
return nil, fmt.Errorf("getHookFiles: unable to add file %q required by %q: %w", s.Text(), path, err)
} else {
files = append(files, filelist...)
for _, file := range fFiles {
files.Add(file, file)
}
}
}
if err := s.Err(); err != nil {