From 22692e48d245dbdd4f80b5836deafdea738d4086 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Sat, 18 Feb 2023 11:17:55 -0800 Subject: [PATCH] filelist/initramfs: add new type for slurping up file listers --- internal/filelist/initramfs/initramfs.go | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 internal/filelist/initramfs/initramfs.go diff --git a/internal/filelist/initramfs/initramfs.go b/internal/filelist/initramfs/initramfs.go new file mode 100644 index 0000000..f119c36 --- /dev/null +++ b/internal/filelist/initramfs/initramfs.go @@ -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 +}