github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/dpkg_metadata.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  const DpkgDBGlob = "**/var/lib/dpkg/{status,status.d/**}"
    12  
    13  var _ FileOwner = (*DpkgMetadata)(nil)
    14  
    15  // DpkgMetadata represents all captured data for a Debian package DB entry; available fields are described
    16  // at http://manpages.ubuntu.com/manpages/xenial/man1/dpkg-query.1.html in the --showformat section.
    17  type DpkgMetadata struct {
    18  	Package       string           `mapstructure:"Package" json:"package"`
    19  	Source        string           `mapstructure:"Source" json:"source" cyclonedx:"source"`
    20  	Version       string           `mapstructure:"Version" json:"version"`
    21  	SourceVersion string           `mapstructure:"SourceVersion" json:"sourceVersion" cyclonedx:"sourceVersion"`
    22  	Architecture  string           `mapstructure:"Architecture" json:"architecture"`
    23  	Maintainer    string           `mapstructure:"Maintainer" json:"maintainer"`
    24  	InstalledSize int              `mapstructure:"InstalledSize" json:"installedSize" cyclonedx:"installedSize"`
    25  	Description   string           `mapstructure:"Description" hash:"ignore" json:"-"`
    26  	Files         []DpkgFileRecord `json:"files"`
    27  }
    28  
    29  // DpkgFileRecord represents a single file attributed to a debian package.
    30  type DpkgFileRecord struct {
    31  	Path         string       `json:"path"`
    32  	Digest       *file.Digest `json:"digest,omitempty"`
    33  	IsConfigFile bool         `json:"isConfigFile"`
    34  }
    35  
    36  func (m DpkgMetadata) OwnedFiles() (result []string) {
    37  	s := strset.New()
    38  	for _, f := range m.Files {
    39  		if f.Path != "" {
    40  			s.Add(f.Path)
    41  		}
    42  	}
    43  	result = s.List()
    44  	sort.Strings(result)
    45  	return
    46  }