filelist/hookfiles: encapsulate dir searching out of slurpFiles
Move the directory searching / globbing code out of slurpFiles and into the filelist module so it can be used elsewhere.
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
package filelist
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
||||
)
|
||||
|
||||
type FileLister interface {
|
||||
List() (*FileList, error)
|
||||
@@ -45,6 +51,26 @@ func (f *FileList) Import(src *FileList) {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FileList) AddGlobbed(src string, dest string) (error) {
|
||||
fFiles, err := misc.GetFiles([]string{src}, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add %q: %w", src, err)
|
||||
}
|
||||
// loop over all returned files from GetFile
|
||||
for _, file := range fFiles {
|
||||
if len(fFiles) > 1 {
|
||||
// Glob with arbitrary subdirectories, so we need to
|
||||
// remove the src path and prepend the dest path
|
||||
f.Add(file, filepath.Join(dest, file[len(src):]))
|
||||
} else {
|
||||
// dest path specified, and only 1 file
|
||||
f.Add(file, dest)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// iterate through the list and and send each one as a new File over the
|
||||
// returned channel
|
||||
func (f *FileList) IterItems() <-chan File {
|
||||
|
Reference in New Issue
Block a user