Skip to content

Commit

Permalink
move coordinates into separate file
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
  • Loading branch information
wagoodman committed Nov 17, 2021
1 parent 2949587 commit de146b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
7 changes: 7 additions & 0 deletions syft/source/coordinates.go
@@ -0,0 +1,7 @@
package source

// Coordinates contains the minimal information needed to describe how to find a file within any possible source object (e.g. image and directory sources)
type Coordinates struct {
RealPath string `json:"path"` // The path where all path ancestors have no hardlinks / symlinks
FileSystemID string `json:"layerID,omitempty"` // An ID representing the filesystem. For container images this is a layer digest, directories or root filesystem this is blank.
}
27 changes: 0 additions & 27 deletions syft/source/location.go
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/image"
"github.com/anchore/syft/internal/log"
"github.com/anchore/syft/syft/artifact"
)

// Location represents a path relative to a particular filesystem resolved to a specific file.Reference. This struct is used as a key
Expand All @@ -19,12 +18,6 @@ type Location struct {
ref file.Reference // The file reference relative to the stereoscope.FileCatalog that has more information about this location.
}

// Coordinates contains the minimal information needed to describe how to find a file within any possible source object (e.g. image and directory sources)
type Coordinates struct {
RealPath string `json:"path"` // The path where all path ancestors have no hardlinks / symlinks
FileSystemID string `json:"layerID,omitempty"` // An ID representing the filesystem. For container images this is a layer digest, directories or root filesystem this is blank.
}

// NewLocation creates a new Location representing a path without denoting a filesystem or FileCatalog reference.
func NewLocation(realPath string) Location {
return Location{
Expand Down Expand Up @@ -105,23 +98,3 @@ func (l Location) Hash() (uint64, error) {
// Location hash should be a pass-through for the coordinates and not include ref or VirtualPath.
return hashstructure.Hash(l.ID(), hashstructure.FormatV2, nil)
}

func (c Coordinates) ID() artifact.ID {
f, err := artifact.IDFromHash(c)
if err != nil {
// TODO: what to do in this case?
log.Warnf("unable to get fingerprint of location coordinate=%+v: %+v", c, err)
return ""
}

return f
}

func (c Coordinates) String() string {
str := fmt.Sprintf("RealPath=%q", c.RealPath)

if c.FileSystemID != "" {
str += fmt.Sprintf(" Layer=%q", c.FileSystemID)
}
return fmt.Sprintf("Location<%s>", str)
}

0 comments on commit de146b7

Please sign in to comment.