github.com/anchore/syft@v1.38.2/syft/pkg/alpm.go (about)

     1  package pkg
     2  
     3  import (
     4  	"sort"
     5  	"time"
     6  
     7  	"github.com/scylladb/go-set/strset"
     8  
     9  	"github.com/anchore/syft/syft/file"
    10  )
    11  
    12  var _ FileOwner = (*AlpmDBEntry)(nil)
    13  
    14  const AlpmDBGlob = "**/var/lib/pacman/local/**/desc"
    15  
    16  // AlpmDBEntry is a struct that represents the package data stored in the pacman flat-file stores for arch linux.
    17  type AlpmDBEntry struct {
    18  	// BasePackage is the base package name this package was built from (source package in Arch build system)
    19  	BasePackage string `mapstructure:"base" json:"basepackage" cyclonedx:"basepackage"`
    20  
    21  	// Package is the package name as found in the desc file
    22  	Package string `mapstructure:"name" json:"package" cyclonedx:"package"`
    23  
    24  	// Version is the package version as found in the desc file
    25  	Version string `mapstructure:"version" json:"version" cyclonedx:"version"`
    26  
    27  	// Description is a human-readable package description
    28  	Description string `mapstructure:"desc" json:"description" cyclonedx:"description"`
    29  
    30  	// Architecture is the target CPU architecture as defined in Arch architecture spec (e.g. x86_64, aarch64, or "any" for arch-independent packages)
    31  	Architecture string `mapstructure:"arch" json:"architecture" cyclonedx:"architecture"`
    32  
    33  	// Size is the installed size in bytes
    34  	Size int `mapstructure:"size" json:"size" cyclonedx:"size"`
    35  
    36  	// Packager is the name and email of the person who packaged this (RFC822 format)
    37  	Packager string `mapstructure:"packager" json:"packager"`
    38  
    39  	// URL is the upstream project URL
    40  	URL string `mapstructure:"url" json:"url"`
    41  
    42  	// Validation is the validation method used for package integrity (e.g. pgp signature, sha256 checksum)
    43  	Validation string `mapstructure:"validation" json:"validation"`
    44  
    45  	// Reason is the installation reason tracked by pacman (0=explicitly installed by user, 1=installed as dependency)
    46  	Reason int `mapstructure:"reason" json:"reason"`
    47  
    48  	// Files are the files installed by this package
    49  	Files []AlpmFileRecord `mapstructure:"files" json:"files"`
    50  
    51  	// Backup is the list of configuration files that pacman backs up before upgrades
    52  	Backup []AlpmFileRecord `mapstructure:"backup" json:"backup"`
    53  
    54  	// Provides are virtual packages provided by this package (allows other packages to depend on capabilities rather than specific packages)
    55  	Provides []string `mapstructure:"provides" json:"provides,omitempty"`
    56  
    57  	// Depends are the runtime dependencies required by this package
    58  	Depends []string `mapstructure:"depends" json:"depends,omitempty"`
    59  }
    60  
    61  // AlpmFileRecord represents a single file entry within an Arch Linux package with its associated metadata tracked by pacman.
    62  type AlpmFileRecord struct {
    63  	// Path is the file path relative to the filesystem root
    64  	Path string `mapstruture:"path" json:"path,omitempty"`
    65  
    66  	// Type is the file type (e.g. regular file, directory, symlink)
    67  	Type string `mapstructure:"type" json:"type,omitempty"`
    68  
    69  	// UID is the file owner user ID as recorded by pacman
    70  	UID string `mapstructure:"uid" json:"uid,omitempty"`
    71  
    72  	// GID is the file owner group ID as recorded by pacman
    73  	GID string `mapstructure:"gid" json:"gid,omitempty"`
    74  
    75  	// Time is the file modification timestamp
    76  	Time time.Time `mapstructure:"time" json:"time,omitempty"`
    77  
    78  	// Size is the file size in bytes
    79  	Size string `mapstructure:"size" json:"size,omitempty"`
    80  
    81  	// Link is the symlink target path if this is a symlink
    82  	Link string `mapstructure:"link" json:"link,omitempty"`
    83  
    84  	// Digests contains file content hashes for integrity verification
    85  	Digests []file.Digest `mapstructure:"digests" json:"digest,omitempty"`
    86  }
    87  
    88  func (m AlpmDBEntry) OwnedFiles() (result []string) {
    89  	s := strset.New()
    90  	for _, f := range m.Files {
    91  		if f.Path != "" {
    92  			s.Add(f.Path)
    93  		}
    94  	}
    95  	result = s.List()
    96  	sort.Strings(result)
    97  	return result
    98  }