mirror of
https://github.com/anchore/syft.git
synced 2026-10-31 14:36:33 +01:00
fix: name nested files in SPDX by their archive chain
SPDX wrote `FileName` from `RealPath` only, so two archives' `META-INF/MANIFEST.MF` became two SPDX files with the same name and nothing saying which archive each came from. Worse, a consumer reading just the name would take a nested file for one at that path in the scan root. - a file inside an archive is now named by its full chain, using the same `:` convention and escaping as `ArchivePath` / java's `VirtualPath`: `app.war:WEB-INF/lib/a.jar:META-INF/MANIFEST.MF` - `FileComment` gains an `archivePath: ...` line (next to the existing `layerID: ...`, one per line), so decoding recovers `ArchivePath` and the entry's own `RealPath` without guessing where the chain ends - files outside archives are unchanged Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -52,12 +52,20 @@ func VirtualPath(loc file.Location) string {
|
||||
return loc.ArchivePath + ":" + strings.TrimPrefix(escapeEntryPath(loc.Path()), "/")
|
||||
}
|
||||
|
||||
var entryPathEscaper = strings.NewReplacer("%", "%25", ":", "%3A")
|
||||
var (
|
||||
entryPathEscaper = strings.NewReplacer("%", "%25", ":", "%3A")
|
||||
entryPathUnescaper = strings.NewReplacer("%3A", ":", "%25", "%")
|
||||
)
|
||||
|
||||
func escapeEntryPath(p string) string {
|
||||
return entryPathEscaper.Replace(p)
|
||||
}
|
||||
|
||||
// UnescapeEntryPath reverses the escaping VirtualPath applies to one segment of the chain.
|
||||
func UnescapeEntryPath(p string) string {
|
||||
return entryPathUnescaper.Replace(p)
|
||||
}
|
||||
|
||||
type traversalCtxKey struct{}
|
||||
|
||||
func WithTraversal(ctx context.Context, t *Traversal) context.Context {
|
||||
|
||||
Reference in New Issue
Block a user