diff --git a/syft/format/common/cyclonedxhelpers/to_format_model.go b/syft/format/common/cyclonedxhelpers/to_format_model.go index ab0a83ed906..aedb3e4a6e6 100644 --- a/syft/format/common/cyclonedxhelpers/to_format_model.go +++ b/syft/format/common/cyclonedxhelpers/to_format_model.go @@ -2,7 +2,6 @@ package cyclonedxhelpers import ( "fmt" - "os" "slices" "strings" "time" @@ -10,6 +9,7 @@ import ( "github.com/CycloneDX/cyclonedx-go" "github.com/google/uuid" + stfile "github.com/anchore/stereoscope/pkg/file" "github.com/anchore/syft/internal/log" "github.com/anchore/syft/syft/artifact" "github.com/anchore/syft/syft/cpe" @@ -52,9 +52,9 @@ func ToFormatModel(s sbom.SBOM) *cyclonedx.BOM { if !exists { continue } - if fileMetadata.IsDir() || - fileMetadata.Mode() == os.ModeSymlink || - fileMetadata.Mode() == os.ModeSocket { + if fileMetadata.Type == stfile.TypeDirectory || + fileMetadata.Type == stfile.TypeSocket || + fileMetadata.Type == stfile.TypeSymLink { // skip dir, symlinks and sockets for the final bom continue } diff --git a/syft/format/common/cyclonedxhelpers/to_format_model_test.go b/syft/format/common/cyclonedxhelpers/to_format_model_test.go index bd7c50c10b1..7529f21e8c0 100644 --- a/syft/format/common/cyclonedxhelpers/to_format_model_test.go +++ b/syft/format/common/cyclonedxhelpers/to_format_model_test.go @@ -2,15 +2,14 @@ package cyclonedxhelpers import ( "fmt" - "os" "testing" - "time" "github.com/CycloneDX/cyclonedx-go" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + stfile "github.com/anchore/stereoscope/pkg/file" "github.com/anchore/syft/syft/artifact" "github.com/anchore/syft/syft/file" "github.com/anchore/syft/syft/format/internal/cyclonedxutil/helpers" @@ -161,7 +160,7 @@ func Test_FileComponents(t *testing.T) { Artifacts: sbom.Artifacts{ Packages: pkg.NewCollection(p1), FileMetadata: map[file.Coordinates]file.Metadata{ - {RealPath: "/test"}: {Path: "/test", FileInfo: newMockFileInfo(false, false)}, // Embed the mock that always returns IsDir() = true + {RealPath: "/test"}: {Path: "/test", Type: stfile.TypeRegular}, }, FileDigests: map[file.Coordinates][]file.Digest{ {RealPath: "/test"}: { @@ -194,7 +193,7 @@ func Test_FileComponents(t *testing.T) { sbom: sbom.SBOM{ Artifacts: sbom.Artifacts{ FileMetadata: map[file.Coordinates]file.Metadata{ - {RealPath: "/test"}: {Path: "/test", FileInfo: newMockFileInfo(false, false)}, + {RealPath: "/test"}: {Path: "/test", Type: stfile.TypeRegular}, }, FileDigests: map[file.Coordinates][]file.Digest{ {RealPath: "/test"}: { @@ -228,7 +227,7 @@ func Test_FileComponents(t *testing.T) { sbom: sbom.SBOM{ Artifacts: sbom.Artifacts{ FileMetadata: map[file.Coordinates]file.Metadata{ - {RealPath: "/test"}: {Path: "/test", FileInfo: newMockFileInfo(false, false)}, + {RealPath: "/test"}: {Path: "/test", Type: stfile.TypeRegular}, }, FileDigests: map[file.Coordinates][]file.Digest{ {RealPath: "/test"}: { @@ -248,14 +247,14 @@ func Test_FileComponents(t *testing.T) { Artifacts: sbom.Artifacts{ FileMetadata: map[file.Coordinates]file.Metadata{ {RealPath: "/testdir"}: { - Path: "/testdir", - FileInfo: newMockFileInfo(true, false), + Path: "/testdir", + Type: stfile.TypeDirectory, }, {RealPath: "/testsym"}: { - Path: "/testsym", - FileInfo: newMockFileInfo(false, true), + Path: "/testsym", + Type: stfile.TypeSymLink, }, - {RealPath: "/test"}: {Path: "/test", FileInfo: newMockFileInfo(false, false)}, + {RealPath: "/test"}: {Path: "/test", Type: stfile.TypeRegular}, }, FileDigests: map[file.Coordinates][]file.Digest{ {RealPath: "/test"}: { @@ -311,29 +310,6 @@ type mockFileInfo struct { isSymlink bool } -func newMockFileInfo(isDir, isSym bool) mockFileInfo { - return mockFileInfo{ - isDir, - isSym, - } -} - -// Implement os.FileInfo interface methods -func (m mockFileInfo) Name() string { return "mockDir" } -func (m mockFileInfo) Size() int64 { return 0 } -func (m mockFileInfo) Mode() os.FileMode { - if m.isSymlink { - return os.ModeSymlink - } - if m.isDir { - return os.ModeDir - } - return os.ModeType -} // Mark as directory -func (m mockFileInfo) ModTime() time.Time { return time.Now() } -func (m mockFileInfo) IsDir() bool { return m.isDir } -func (m mockFileInfo) Sys() any { return nil } - func Test_toBomDescriptor(t *testing.T) { type args struct { name string