archive: add AddItemsExclude method (MR 34)

This allows passing a filelister of things to exclude from the archive
This commit is contained in:
Clayton Craft
2023-03-19 22:44:41 -07:00
parent 67ce1a9c2e
commit 25017f3a3b

View File

@@ -200,6 +200,38 @@ func (archive *Archive) AddItems(flister filelist.FileLister) error {
return nil return nil
} }
// AddItemsExclude is like AddItems, but takes a second FileLister that lists
// items that should not be added to the archive from the first FileLister
func (archive *Archive) AddItemsExclude(flister filelist.FileLister, exclude filelist.FileLister) error {
list, err := flister.List()
if err != nil {
return err
}
excludeList, err := exclude.List()
if err != nil {
return err
}
for i := range list.IterItems() {
dest, found := excludeList.Get(i.Source)
if found {
if i.Dest != dest {
found = false
}
}
if !found {
if err := archive.AddItem(i.Source, i.Dest); err != nil {
return err
}
}
}
return nil
}
// Adds the given file or directory at "source" to the archive at "dest" // Adds the given file or directory at "source" to the archive at "dest"
func (archive *Archive) AddItem(source string, dest string) error { func (archive *Archive) AddItem(source string, dest string) error {