fix realPath for first nested archives

Signed-off-by: Kudryavcev Nikolay <kydry.nikolau@gmail.com>
This commit is contained in:
Kudryavcev Nikolay
2025-07-02 01:00:02 +03:00
parent 8f784b5dd0
commit 8cfef40b9c
3 changed files with 20 additions and 9 deletions
+3 -4
View File
@@ -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
@@ -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)
}
+17 -1
View File
@@ -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,