github.com/anchore/syft@v1.38.2/syft/file/coordinates.go (about) 1 package file 2 3 import ( 4 "fmt" 5 6 "github.com/anchore/syft/internal/log" 7 "github.com/anchore/syft/syft/artifact" 8 ) 9 10 // Coordinates contains the minimal information needed to describe how to find a file within any possible source object (e.g. image and directory sources) 11 type Coordinates struct { 12 // RealPath is the canonical absolute form of the path accessed (all symbolic links have been followed and relative path components like '.' and '..' have been removed). 13 RealPath string `json:"path" cyclonedx:"path"` 14 15 // FileSystemID is an ID representing and entire filesystem. For container images, this is a layer digest. For directories or a root filesystem, this is blank. 16 FileSystemID string `json:"layerID,omitempty" cyclonedx:"layerID"` 17 } 18 19 func NewCoordinates(realPath, fsID string) Coordinates { 20 return Coordinates{ 21 RealPath: realPath, 22 FileSystemID: fsID, 23 } 24 } 25 26 func (c Coordinates) ID() artifact.ID { 27 f, err := artifact.IDByHash(c) 28 if err != nil { 29 // TODO: what to do in this case? 30 log.Debugf("unable to get fingerprint of location coordinate=%+v: %+v", c, err) 31 return "" 32 } 33 34 return f 35 } 36 37 func (c Coordinates) String() string { 38 str := fmt.Sprintf("RealPath=%q", c.RealPath) 39 40 if c.FileSystemID != "" { 41 str += fmt.Sprintf(" Layer=%q", c.FileSystemID) 42 } 43 return fmt.Sprintf("Location<%s>", str) 44 } 45 46 func (c Coordinates) GetCoordinates() Coordinates { 47 return c 48 }