diff --git a/syft/internal/fileresolver/directory.go b/syft/internal/fileresolver/directory.go index ec529a136..f71ba9ee2 100644 --- a/syft/internal/fileresolver/directory.go +++ b/syft/internal/fileresolver/directory.go @@ -47,7 +47,7 @@ func NewFromDirectory(root, base string, maxArchiveRecursiveIndexDepth int, path return nil, cleanupFn, fmt.Errorf("unable to build index: %w", err) } - if maxArchiveRecursiveIndexDepth != 0 { + if maxArchiveRecursiveIndexDepth != 0 && len(directory.indexer.archivePaths) > 0 { archiveTempDir, err := os.MkdirTemp("", archiveTempPathPattern) if err != nil { return nil, cleanupFn, fmt.Errorf("unable to create tempdir for archive processing: %w", err) @@ -102,8 +102,8 @@ func (r *Directory) buildArchiveIndex(archiveTempDir string, archives []string, archivesToIndex := make([]archiveAccessPath, len(archives)) for i, archive := range archives { archivesToIndex[i] = archiveAccessPath{ - realPath: archive, - accessPath: archive, + realPath: r.Chroot.ToChrootPath(archive), + accessPath: r.Chroot.ToChrootPath(archive), archiveRealPath: archive, } } @@ -173,7 +173,6 @@ loop: }) } - d.Chroot = r.Chroot d.realPath = currentArchivePath.realPath d.accessPath = currentArchivePath.accessPath d.archiveRealPath = archiveDestinationPath diff --git a/syft/internal/fileresolver/filetree_resolver.go b/syft/internal/fileresolver/filetree_resolver.go index 24be3252c..6c1b24d09 100644 --- a/syft/internal/fileresolver/filetree_resolver.go +++ b/syft/internal/fileresolver/filetree_resolver.go @@ -55,10 +55,6 @@ func (r *FiletreeResolver) requestPath(userPath string) (string, error) { // responsePath takes a path from the underlying fs domain and converts it to a path that is relative to the root of the file resolver. func (r FiletreeResolver) responsePath(path string) string { - if r.archiveRealPath != "" && strings.HasPrefix(path, r.archiveRealPath) { - path = r.realPath - } - return r.Chroot.ToChrootPath(path) } diff --git a/test/cli/archive_test.go b/test/cli/archive_test.go index a35b4ead2..233fa2d3a 100644 --- a/test/cli/archive_test.go +++ b/test/cli/archive_test.go @@ -10,6 +10,8 @@ import ( ) func TestArchiveScan(t *testing.T) { + archive := createArchive(t, "test-fixtures/archive", t.TempDir()) + nestedArchive := createArchive(t, filepath.Dir(archive), t.TempDir()) tests := []struct { name string args []string @@ -23,7 +25,21 @@ func TestArchiveScan(t *testing.T) { "scan", "-o", "json", - "file:" + createArchive(t, "test-fixtures/archive", t.TempDir()), + "file:" + archive, + }, + assertions: []traitAssertion{ + assertSuccessfulReturnCode, + assertJsonReport, + assertPackageCount(1), + }, + }, + { + name: "scan an nested archive within the temp dir", + args: []string{ + "scan", + "-o", + "json", + "file:" + nestedArchive, }, assertions: []traitAssertion{ assertSuccessfulReturnCode,