github.com/anchore/syft@v1.38.2/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 is total size of installed files in bytes
    16  	InstalledSize int `json:"installedSize" cyclonedx:"installedSize"`
    17  
    18  	// Licenses is license string which may be an expression (e.g. "GPL-2 OR Apache-2.0")
    19  	Licenses string `json:"licenses,omitempty"`
    20  
    21  	// Files are the files installed by this package (tracked in CONTENTS file)
    22  	Files []PortageFileRecord `json:"files"`
    23  }
    24  
    25  // PortageFileRecord represents a single file attributed to a portage package.
    26  type PortageFileRecord struct {
    27  	// Path is the file path relative to the filesystem root
    28  	Path string `json:"path"`
    29  
    30  	// Digest is file content hash (MD5 for regular files in CONTENTS format: "obj filename md5hash mtime")
    31  	Digest *file.Digest `json:"digest,omitempty"`
    32  }
    33  
    34  func (m PortageEntry) OwnedFiles() (result []string) {
    35  	s := strset.New()
    36  	for _, f := range m.Files {
    37  		if f.Path != "" {
    38  			s.Add(f.Path)
    39  		}
    40  	}
    41  	result = s.List()
    42  	sort.Strings(result)
    43  	return result
    44  }