filelist/*: implement FileLister in existing types
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user