mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 06:56:40 +01:00
fix realPath for first nested archives
Signed-off-by: Kudryavcev Nikolay <kydry.nikolau@gmail.com>
This commit is contained in:
@@ -47,7 +47,7 @@ func NewFromDirectory(root, base string, maxArchiveRecursiveIndexDepth int, path
|
|||||||
return nil, cleanupFn, fmt.Errorf("unable to build index: %w", err)
|
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)
|
archiveTempDir, err := os.MkdirTemp("", archiveTempPathPattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cleanupFn, fmt.Errorf("unable to create tempdir for archive processing: %w", err)
|
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))
|
archivesToIndex := make([]archiveAccessPath, len(archives))
|
||||||
for i, archive := range archives {
|
for i, archive := range archives {
|
||||||
archivesToIndex[i] = archiveAccessPath{
|
archivesToIndex[i] = archiveAccessPath{
|
||||||
realPath: archive,
|
realPath: r.Chroot.ToChrootPath(archive),
|
||||||
accessPath: archive,
|
accessPath: r.Chroot.ToChrootPath(archive),
|
||||||
archiveRealPath: archive,
|
archiveRealPath: archive,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,6 @@ loop:
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Chroot = r.Chroot
|
|
||||||
d.realPath = currentArchivePath.realPath
|
d.realPath = currentArchivePath.realPath
|
||||||
d.accessPath = currentArchivePath.accessPath
|
d.accessPath = currentArchivePath.accessPath
|
||||||
d.archiveRealPath = archiveDestinationPath
|
d.archiveRealPath = archiveDestinationPath
|
||||||
|
|||||||
@@ -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.
|
// 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 {
|
func (r FiletreeResolver) responsePath(path string) string {
|
||||||
if r.archiveRealPath != "" && strings.HasPrefix(path, r.archiveRealPath) {
|
|
||||||
path = r.realPath
|
|
||||||
}
|
|
||||||
|
|
||||||
return r.Chroot.ToChrootPath(path)
|
return r.Chroot.ToChrootPath(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestArchiveScan(t *testing.T) {
|
func TestArchiveScan(t *testing.T) {
|
||||||
|
archive := createArchive(t, "test-fixtures/archive", t.TempDir())
|
||||||
|
nestedArchive := createArchive(t, filepath.Dir(archive), t.TempDir())
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
@@ -23,7 +25,21 @@ func TestArchiveScan(t *testing.T) {
|
|||||||
"scan",
|
"scan",
|
||||||
"-o",
|
"-o",
|
||||||
"json",
|
"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{
|
assertions: []traitAssertion{
|
||||||
assertSuccessfulReturnCode,
|
assertSuccessfulReturnCode,
|
||||||
|
|||||||
Reference in New Issue
Block a user