filelist/initramfs: add new type for slurping up file listers
This commit is contained in:
34
internal/filelist/initramfs/initramfs.go
Normal file
34
internal/filelist/initramfs/initramfs.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package initramfs
|
||||
|
||||
import (
|
||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
||||
)
|
||||
|
||||
// Initramfs allows building arbitrarily complex lists of features, by slurping
|
||||
// up types that implement FileLister (which includes this type! yippee) and
|
||||
// combining the output from them.
|
||||
type Initramfs struct {
|
||||
features []filelist.FileLister
|
||||
}
|
||||
|
||||
// New returns a new Initramfs that generate a list of files based on the given
|
||||
// list of FileListers.
|
||||
func New(features []filelist.FileLister) *Initramfs {
|
||||
return &Initramfs{
|
||||
features: features,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Initramfs) List() (*filelist.FileList, error) {
|
||||
files := filelist.NewFileList()
|
||||
|
||||
for _, f := range i.features {
|
||||
list, err := f.List()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files.Import(list)
|
||||
}
|
||||
|
||||
return files, nil
|
||||
}
|
Reference in New Issue
Block a user