github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/pkg/portage.go (about)

     1  package pkg
     2  
     3  import (
     4  	"sort"
     5  
     6  	"github.com/scylladb/go-set/strset"
     7  
     8  	"github.com/anchore/syft/syft/file"
     9  )
    10  
    11  var _ FileOwner = (*PortageEntry)(nil)
    12  
    13  // PortageEntry represents a single package entry in the portage DB flat-file store.
    14  type PortageEntry struct {
    15  	InstalledSize int                 `mapstructure:"InstalledSize" json:"installedSize" cyclonedx:"installedSize"`
    16  	Files         []PortageFileRecord `json:"files"`
    17  }
    18  
    19  // PortageFileRecord represents a single file attributed to a portage package.
    20  type PortageFileRecord struct {
    21  	Path   string       `json:"path"`
    22  	Digest *file.Digest `json:"digest,omitempty"`
    23  }
    24  
    25  func (m PortageEntry) OwnedFiles() (result []string) {
    26  	s := strset.New()
    27  	for _, f := range m.Files {
    28  		if f.Path != "" {
    29  			s.Add(f.Path)
    30  		}
    31  	}
    32  	result = s.List()
    33  	sort.Strings(result)
    34  	return result
    35  }