Projects STRLCPY syft Commits 334a775c
🤬
  • ■ ■ ■ ■
    go.mod
    skipped 52 lines
    53 53   github.com/Masterminds/semver v1.5.0
    54 54   github.com/Masterminds/sprig/v3 v3.2.3
    55 55   github.com/anchore/go-logger v0.0.0-20220728155337-03b66a5207d8
    56  - github.com/anchore/stereoscope v0.0.0-20230412183729-8602f1afc574
     56 + github.com/anchore/stereoscope v0.0.0-20230508133058-5543439b749f
    57 57   github.com/deitch/magic v0.0.0-20230404182410-1ff89d7342da
    58 58   github.com/docker/docker v24.0.0+incompatible
    59 59   github.com/github/go-spdx/v2 v2.1.2
    skipped 119 lines
  • ■ ■ ■ ■ ■ ■
    go.sum
    skipped 97 lines
    98 98  github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b/go.mod h1:Bkc+JYWjMCF8OyZ340IMSIi2Ebf3uwByOk6ho4wne1E=
    99 99  github.com/anchore/packageurl-go v0.1.1-0.20230104203445-02e0a6721501 h1:AV7qjwMcM4r8wFhJq3jLRztew3ywIyPTRapl2T1s9o8=
    100 100  github.com/anchore/packageurl-go v0.1.1-0.20230104203445-02e0a6721501/go.mod h1:Blo6OgJNiYF41ufcgHKkbCKF2MDOMlrqhXv/ij6ocR4=
    101  -github.com/anchore/stereoscope v0.0.0-20230412183729-8602f1afc574 h1:VFX+FD9EH6am+tfqwr1KeCAmabAknSJQX95aIY3QJJI=
    102  -github.com/anchore/stereoscope v0.0.0-20230412183729-8602f1afc574/go.mod h1:2GGFHkHry/xDlEQgBrVGcarq+z7Z6hLnHdyhcKB2lfQ=
     101 +github.com/anchore/stereoscope v0.0.0-20230508133058-5543439b749f h1:wiWDirrn2a4gT2TfFeGb5zqFjKoEy3Hx+K8u8lReHzY=
     102 +github.com/anchore/stereoscope v0.0.0-20230508133058-5543439b749f/go.mod h1:2GGFHkHry/xDlEQgBrVGcarq+z7Z6hLnHdyhcKB2lfQ=
    103 103  github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
    104 104  github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
    105 105  github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
    skipped 1100 lines
  • ■ ■ ■ ■
    syft/file/contents_cataloger.go
    skipped 36 lines
    37 37   return nil, err
    38 38   }
    39 39   
    40  - if i.skipFilesAboveSizeInBytes > 0 && metadata.Size > i.skipFilesAboveSizeInBytes {
     40 + if i.skipFilesAboveSizeInBytes > 0 && metadata.Size() > i.skipFilesAboveSizeInBytes {
    41 41   continue
    42 42   }
    43 43   
    skipped 35 lines
  • ■ ■ ■ ■ ■ ■
    syft/file/metadata_cataloger_test.go
    skipped 3 lines
    4 4   "flag"
    5 5   "os"
    6 6   "testing"
    7  - "time"
    8 7   
    9 8   "github.com/stretchr/testify/assert"
    10 9   "github.com/stretchr/testify/require"
    skipped 41 lines
    52 51   path: "/file-1.txt",
    53 52   exists: true,
    54 53   expected: source.FileMetadata{
     54 + FileInfo: file.ManualInfo{
     55 + NameValue: "file-1.txt",
     56 + ModeValue: 0644,
     57 + SizeValue: 7,
     58 + },
    55 59   Path: "/file-1.txt",
    56  - Mode: 0644,
    57 60   Type: file.TypeRegular,
    58 61   UserID: 1,
    59 62   GroupID: 2,
    60  - Size: 7,
    61 63   MIMEType: "text/plain",
    62 64   },
    63 65   },
    skipped 1 lines
    65 67   path: "/hardlink-1",
    66 68   exists: true,
    67 69   expected: source.FileMetadata{
     70 + FileInfo: file.ManualInfo{
     71 + NameValue: "hardlink-1",
     72 + ModeValue: 0644,
     73 + },
    68 74   Path: "/hardlink-1",
    69  - Mode: 0644,
    70 75   Type: file.TypeHardLink,
    71 76   LinkDestination: "file-1.txt",
    72 77   UserID: 1,
    skipped 5 lines
    78 83   path: "/symlink-1",
    79 84   exists: true,
    80 85   expected: source.FileMetadata{
    81  - Path: "/symlink-1",
    82  - Mode: 0777 | os.ModeSymlink,
     86 + Path: "/symlink-1",
     87 + FileInfo: file.ManualInfo{
     88 + NameValue: "symlink-1",
     89 + ModeValue: 0777 | os.ModeSymlink,
     90 + },
    83 91   Type: file.TypeSymLink,
    84 92   LinkDestination: "file-1.txt",
    85 93   UserID: 0,
    skipped 5 lines
    91 99   path: "/char-device-1",
    92 100   exists: true,
    93 101   expected: source.FileMetadata{
    94  - Path: "/char-device-1",
    95  - Mode: 0644 | os.ModeDevice | os.ModeCharDevice,
     102 + Path: "/char-device-1",
     103 + FileInfo: file.ManualInfo{
     104 + NameValue: "char-device-1",
     105 + ModeValue: 0644 | os.ModeDevice | os.ModeCharDevice,
     106 + },
    96 107   Type: file.TypeCharacterDevice,
    97 108   UserID: 0,
    98 109   GroupID: 0,
    skipped 4 lines
    103 114   path: "/block-device-1",
    104 115   exists: true,
    105 116   expected: source.FileMetadata{
    106  - Path: "/block-device-1",
    107  - Mode: 0644 | os.ModeDevice,
     117 + Path: "/block-device-1",
     118 + FileInfo: file.ManualInfo{
     119 + NameValue: "block-device-1",
     120 + ModeValue: 0644 | os.ModeDevice,
     121 + },
    108 122   Type: file.TypeBlockDevice,
    109 123   UserID: 0,
    110 124   GroupID: 0,
    skipped 4 lines
    115 129   path: "/fifo-1",
    116 130   exists: true,
    117 131   expected: source.FileMetadata{
    118  - Path: "/fifo-1",
    119  - Mode: 0644 | os.ModeNamedPipe,
     132 + Path: "/fifo-1",
     133 + FileInfo: file.ManualInfo{
     134 + NameValue: "fifo-1",
     135 + ModeValue: 0644 | os.ModeNamedPipe,
     136 + },
    120 137   Type: file.TypeFIFO,
    121 138   UserID: 0,
    122 139   GroupID: 0,
    skipped 4 lines
    127 144   path: "/bin",
    128 145   exists: true,
    129 146   expected: source.FileMetadata{
    130  - Path: "/bin",
    131  - Mode: 0755 | os.ModeDir,
     147 + Path: "/bin",
     148 + FileInfo: file.ManualInfo{
     149 + NameValue: "bin",
     150 + ModeValue: 0755 | os.ModeDir,
     151 + },
    132 152   Type: file.TypeDirectory,
    133 153   UserID: 0,
    134 154   GroupID: 0,
    135 155   MIMEType: "",
    136  - IsDir: true,
    137 156   },
    138 157   },
    139 158   }
    skipped 6 lines
    146 165   l := source.NewLocationFromImage(test.path, *ref.Reference, img)
    147 166   
    148 167   if _, ok := actual[l.Coordinates]; ok {
    149  - redact := actual[l.Coordinates]
    150  - redact.ModTime = time.Time{}
    151  - actual[l.Coordinates] = redact
     168 + // we're not interested in keeping the test fixtures up to date with the latest file modification times
     169 + // thus ModTime is not under test
     170 + fi := test.expected.FileInfo.(file.ManualInfo)
     171 + fi.ModTimeValue = actual[l.Coordinates].ModTime()
     172 + test.expected.FileInfo = fi
    152 173   }
    153 174   
    154  - assert.Equal(t, test.expected, actual[l.Coordinates], "mismatched metadata")
    155  - 
     175 + assert.True(t, test.expected.Equal(actual[l.Coordinates]))
    156 176   })
    157 177   }
    158 178   
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    syft/file/secrets_cataloger.go
    skipped 70 lines
    71 71   return nil, err
    72 72   }
    73 73   
    74  - if metadata.Size == 0 {
     74 + if metadata.Size() == 0 {
    75 75   return nil, nil
    76 76   }
    77 77   
    78  - if i.skipFilesAboveSize > 0 && metadata.Size > i.skipFilesAboveSize {
     78 + if i.skipFilesAboveSize > 0 && metadata.Size() > i.skipFilesAboveSize {
    79 79   return nil, nil
    80 80   }
    81 81   
    skipped 75 lines
  • ■ ■ ■ ■ ■
    syft/formats/syftjson/encoder_test.go
    skipped 102 lines
    103 103   Packages: catalog,
    104 104   FileMetadata: map[source.Coordinates]source.FileMetadata{
    105 105   source.NewLocation("/a/place").Coordinates: {
    106  - Mode: 0775,
     106 + FileInfo: stereoFile.ManualInfo{
     107 + NameValue: "/a/place",
     108 + ModeValue: 0775,
     109 + },
    107 110   Type: stereoFile.TypeDirectory,
    108 111   UserID: 0,
    109 112   GroupID: 0,
    110 113   },
    111 114   source.NewLocation("/a/place/a").Coordinates: {
    112  - Mode: 0775,
     115 + FileInfo: stereoFile.ManualInfo{
     116 + NameValue: "/a/place/a",
     117 + ModeValue: 0775,
     118 + },
    113 119   Type: stereoFile.TypeRegular,
    114 120   UserID: 0,
    115 121   GroupID: 0,
    116 122   },
    117 123   source.NewLocation("/b").Coordinates: {
    118  - Mode: 0775,
     124 + FileInfo: stereoFile.ManualInfo{
     125 + NameValue: "/b",
     126 + ModeValue: 0775,
     127 + },
    119 128   Type: stereoFile.TypeSymLink,
    120 129   LinkDestination: "/c",
    121 130   UserID: 0,
    122 131   GroupID: 0,
    123 132   },
    124 133   source.NewLocation("/b/place/b").Coordinates: {
    125  - Mode: 0644,
     134 + FileInfo: stereoFile.ManualInfo{
     135 + NameValue: "/b/place/b",
     136 + ModeValue: 0644,
     137 + },
    126 138   Type: stereoFile.TypeRegular,
    127 139   UserID: 1,
    128 140   GroupID: 2,
    skipped 87 lines
  • ■ ■ ■ ■ ■ ■
    syft/formats/syftjson/to_format_model.go
    skipped 130 lines
    131 131   return nil
    132 132   }
    133 133   
    134  - mode, err := strconv.Atoi(fmt.Sprintf("%o", metadata.Mode))
    135  - if err != nil {
    136  - log.Warnf("invalid mode found in file catalog @ location=%+v mode=%q: %+v", coordinates, metadata.Mode, err)
    137  - mode = 0
     134 + var mode int
     135 + var size int64
     136 + if metadata != nil && metadata.FileInfo != nil {
     137 + var err error
     138 + 
     139 + mode, err = strconv.Atoi(fmt.Sprintf("%o", metadata.Mode()))
     140 + if err != nil {
     141 + log.Warnf("invalid mode found in file catalog @ location=%+v mode=%q: %+v", coordinates, metadata.Mode, err)
     142 + mode = 0
     143 + }
     144 + 
     145 + size = metadata.Size()
    138 146   }
    139 147   
    140 148   return &model.FileMetadataEntry{
    skipped 3 lines
    144 152   UserID: metadata.UserID,
    145 153   GroupID: metadata.GroupID,
    146 154   MIMEType: metadata.MIMEType,
    147  - Size: metadata.Size,
     155 + Size: size,
    148 156   }
    149 157  }
    150 158   
    skipped 144 lines
  • ■ ■ ■ ■ ■ ■
    syft/formats/syftjson/to_format_model_test.go
    skipped 152 lines
    153 153   assert.ElementsMatch(t, allTypesTested, file.AllTypes(), "not all file.Types are under test")
    154 154  }
    155 155   
     156 +func Test_toFileMetadataEntry(t *testing.T) {
     157 + coords := source.Coordinates{
     158 + RealPath: "/path",
     159 + FileSystemID: "x",
     160 + }
     161 + tests := []struct {
     162 + name string
     163 + metadata *source.FileMetadata
     164 + want *model.FileMetadataEntry
     165 + }{
     166 + {
     167 + name: "no metadata",
     168 + },
     169 + {
     170 + name: "no file info",
     171 + metadata: &source.FileMetadata{
     172 + FileInfo: nil,
     173 + },
     174 + want: &model.FileMetadataEntry{
     175 + Type: file.TypeRegular.String(),
     176 + },
     177 + },
     178 + {
     179 + name: "with file info",
     180 + metadata: &source.FileMetadata{
     181 + FileInfo: &file.ManualInfo{
     182 + ModeValue: 1,
     183 + },
     184 + },
     185 + want: &model.FileMetadataEntry{
     186 + Mode: 1,
     187 + Type: file.TypeRegular.String(),
     188 + },
     189 + },
     190 + }
     191 + for _, tt := range tests {
     192 + t.Run(tt.name, func(t *testing.T) {
     193 + assert.Equal(t, tt.want, toFileMetadataEntry(coords, tt.metadata))
     194 + })
     195 + }
     196 +}
     197 + 
  • ■ ■ ■ ■ ■ ■
    syft/formats/syftjson/to_syft_model.go
    skipped 2 lines
    3 3  import (
    4 4   "fmt"
    5 5   "os"
     6 + "path"
    6 7   "strconv"
    7 8   "strings"
    8 9   
    skipped 70 lines
    79 80   fm := os.FileMode(mode)
    80 81   
    81 82   ret.FileMetadata[coord] = source.FileMetadata{
     83 + FileInfo: stereoscopeFile.ManualInfo{
     84 + NameValue: path.Base(coord.RealPath),
     85 + SizeValue: f.Metadata.Size,
     86 + ModeValue: fm,
     87 + },
    82 88   Path: coord.RealPath,
    83 89   LinkDestination: f.Metadata.LinkDestination,
    84  - Size: f.Metadata.Size,
    85 90   UserID: f.Metadata.UserID,
    86 91   GroupID: f.Metadata.GroupID,
    87 92   Type: toSyftFileType(f.Metadata.Type),
    88  - IsDir: fm.IsDir(),
    89  - Mode: fm,
    90 93   MIMEType: f.Metadata.MIMEType,
    91 94   }
    92 95   }
    skipped 251 lines
  • ■ ■ ■ ■ ■ ■
    syft/formats/syftjson/to_syft_model_test.go
    skipped 201 lines
    202 202   want: sbom.Artifacts{
    203 203   FileMetadata: map[source.Coordinates]source.FileMetadata{
    204 204   coord: {
     205 + FileInfo: stereoFile.ManualInfo{
     206 + NameValue: "place",
     207 + SizeValue: 92,
     208 + ModeValue: 511, // 777 octal = 511 decimal
     209 + },
    205 210   Path: coord.RealPath,
    206 211   LinkDestination: "",
    207  - Size: 92,
    208 212   UserID: 42,
    209 213   GroupID: 32,
    210 214   Type: stereoFile.TypeRegular,
    211  - IsDir: false,
    212  - Mode: 511, // 777 octal = 511 decimal
    213 215   MIMEType: "text/plain",
    214 216   },
    215 217   },
    skipped 135 lines
  • ■ ■ ■ ■
    syft/source/directory_indexer.go
    skipped 306 lines
    307 307   // - link destinations twice, once for the real file and another through the virtual path
    308 308   // - infinite link cycles
    309 309   if indexed, metadata := r.hasBeenIndexed(path); indexed {
    310  - if metadata.IsDir {
     310 + if metadata.IsDir() {
    311 311   // signal to walk() that we should skip this directory entirely
    312 312   return fs.SkipDir
    313 313   }
    skipped 53 lines
  • ■ ■ ■ ■ ■ ■
    syft/source/directory_resolver.go
    skipped 195 lines
    196 196   }
    197 197   
    198 198   // don't consider directories
    199  - if entry.Metadata.IsDir {
     199 + if entry.Metadata.IsDir() {
    200 200   continue
    201 201   }
    202 202   
    skipped 35 lines
    238 238   }
    239 239   
    240 240   // don't consider directories
    241  - if entry.Metadata.IsDir {
     241 + if entry.Metadata.IsDir() {
    242 242   continue
    243 243   }
    244 244   
    skipped 128 lines
  • ■ ■ ■ ■
    syft/source/directory_resolver_test.go
    skipped 948 lines
    949 949   for loc := range resolver.AllLocations() {
    950 950   entry, err := resolver.index.Get(loc.ref)
    951 951   require.NoError(t, err)
    952  - if entry.Metadata.IsDir {
     952 + if entry.Metadata.IsDir() {
    953 953   dirLoc = &loc
    954 954   break
    955 955   }
    skipped 41 lines
  • ■ ■ ■ ■ ■ ■
    syft/source/image_all_layers_resolver.go
    skipped 99 lines
    100 100   if err != nil {
    101 101   return nil, fmt.Errorf("unable to get file metadata for path=%q: %w", ref.RealPath, err)
    102 102   }
    103  - if metadata.Metadata.IsDir {
     103 + if metadata.Metadata.IsDir() {
    104 104   continue
    105 105   }
    106 106   }
    skipped 36 lines
    143 143   return nil, fmt.Errorf("unable to get file metadata for path=%q: %w", result.RequestPath, err)
    144 144   }
    145 145   // don't consider directories
    146  - if metadata.Metadata.IsDir {
     146 + if metadata.Metadata.IsDir() {
    147 147   continue
    148 148   }
    149 149   }
    skipped 104 lines
  • ■ ■ ■ ■
    syft/source/image_all_layers_resolver_test.go
    skipped 369 lines
    370 370   for loc := range resolver.AllLocations() {
    371 371   entry, err := resolver.img.FileCatalog.Get(loc.ref)
    372 372   require.NoError(t, err)
    373  - if entry.Metadata.IsDir {
     373 + if entry.Metadata.IsDir() {
    374 374   dirLoc = &loc
    375 375   break
    376 376   }
    skipped 286 lines
  • ■ ■ ■ ■ ■ ■
    syft/source/image_squash_resolver.go
    skipped 55 lines
    56 56   return nil, fmt.Errorf("unable to get file metadata for path=%q: %w", ref.RealPath, err)
    57 57   }
    58 58   // don't consider directories
    59  - if metadata.Metadata.IsDir {
     59 + if metadata.Metadata.IsDir() {
    60 60   continue
    61 61   }
    62 62   }
    skipped 40 lines
    103 103   return nil, fmt.Errorf("unable to get file metadata for path=%q: %w", result.RequestPath, err)
    104 104   }
    105 105   // don't consider directories
    106  - if metadata.Metadata.IsDir {
     106 + if metadata.Metadata.IsDir() {
    107 107   continue
    108 108   }
    109 109   }
    skipped 103 lines
  • ■ ■ ■ ■
    syft/source/image_squash_resolver_test.go
    skipped 353 lines
    354 354   for loc := range resolver.AllLocations() {
    355 355   entry, err := resolver.img.FileCatalog.Get(loc.ref)
    356 356   require.NoError(t, err)
    357  - if entry.Metadata.IsDir {
     357 + if entry.Metadata.IsDir() {
    358 358   dirLoc = &loc
    359 359   break
    360 360   }
    skipped 235 lines
  • ■ ■ ■ ■ ■ ■
    syft/source/mock_resolver.go
    skipped 167 lines
    168 168   }
    169 169   
    170 170   return FileMetadata{
    171  - Mode: info.Mode(),
    172  - Type: ty,
    173  - UserID: 0, // not supported
    174  - GroupID: 0, // not supported
    175  - Size: info.Size(),
     171 + FileInfo: info,
     172 + Type: ty,
     173 + UserID: 0, // not supported
     174 + GroupID: 0, // not supported
    176 175   }, nil
    177 176  }
    178 177   
    skipped 33 lines
  • ■ ■ ■ ■ ■ ■
    test/cli/all_formats_convertible_test.go
    skipped 51 lines
    52 52   convertArgs = append(convertArgs, "--template", test.template)
    53 53   }
    54 54   cmd, stdout, stderr = runSyft(t, test.env, convertArgs...)
     55 + if cmd.ProcessState.ExitCode() != 0 {
     56 + t.Log("STDOUT:\n", stdout)
     57 + t.Log("STDERR:\n", stderr)
     58 + t.Log("COMMAND:", strings.Join(cmd.Args, " "))
     59 + t.Fatalf("failure executing syft creating an sbom")
     60 + return
     61 + }
    55 62   for _, traitFn := range assertions {
    56 63   traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode())
    57 64   }
    skipped 5 lines
  • ■ ■ ■ ■ ■ ■
    test/cli/spdx_tooling_validation_test.go
    skipped 14 lines
    15 15  )
    16 16   
    17 17  func TestSpdxValidationTooling(t *testing.T) {
    18  - img := imagetest.GetFixtureImage(t, "docker-archive", "image-java-spdx-tools")
    19  - require.NotEmpty(t, img.Metadata.Tags)
    20  - imgTag := img.Metadata.Tags[0]
     18 + // note: the external tooling requires that the daemon explicitly has the image loaded, not just that
     19 + // we can get the image from a cache tar.
     20 + imgTag := imagetest.LoadFixtureImageIntoDocker(t, "image-java-spdx-tools")
    21 21   
    22 22   images := []string{
    23 23   "alpine:3.17.3@sha256:b6ca290b6b4cdcca5b3db3ffa338ee0285c11744b4a6abaa9627746ee3291d8d",
    skipped 70 lines
Please wait...
Page is in error, reload to recover