mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
(fix): delete collection name/type key entries when empty (#3797)
Signed-off-by: Adam McClenaghan <adam@mcclenaghan.co.uk>
This commit is contained in:
parent
0bcf2881c4
commit
1f15361ecf
@ -201,7 +201,11 @@ func (c *Collection) deleteNameFromIndex(p Package) {
|
|||||||
|
|
||||||
nameIndex := c.idsByName[p.Name]
|
nameIndex := c.idsByName[p.Name]
|
||||||
nameIndex.delete(p.id)
|
nameIndex.delete(p.id)
|
||||||
c.idsByName[p.Name] = nameIndex
|
if len(nameIndex.slice) == 0 {
|
||||||
|
delete(c.idsByName, p.Name)
|
||||||
|
} else {
|
||||||
|
c.idsByName[p.Name] = nameIndex
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collection) deleteTypeFromIndex(p Package) {
|
func (c *Collection) deleteTypeFromIndex(p Package) {
|
||||||
@ -209,7 +213,11 @@ func (c *Collection) deleteTypeFromIndex(p Package) {
|
|||||||
|
|
||||||
typeIndex := c.idsByType[p.Type]
|
typeIndex := c.idsByType[p.Type]
|
||||||
typeIndex.delete(p.id)
|
typeIndex.delete(p.id)
|
||||||
c.idsByType[p.Type] = typeIndex
|
if len(typeIndex.slice) == 0 {
|
||||||
|
delete(c.idsByType, p.Type)
|
||||||
|
} else {
|
||||||
|
c.idsByType[p.Type] = typeIndex
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collection) deletePathsFromIndex(p Package) {
|
func (c *Collection) deletePathsFromIndex(p Package) {
|
||||||
|
|||||||
@ -184,6 +184,24 @@ func TestCatalogDeleteRemovesPackages(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "delete idsBy key entries when all deleted",
|
||||||
|
pkgs: []Package{
|
||||||
|
{
|
||||||
|
id: artifact.ID("pkg:deb/debian/1"),
|
||||||
|
Name: "debian",
|
||||||
|
Version: "1",
|
||||||
|
Type: DebPkg,
|
||||||
|
Locations: file.NewLocationSet(
|
||||||
|
file.NewVirtualLocation("/c/path", "/another/path1"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
deleteIDs: []artifact.ID{
|
||||||
|
artifact.ID("pkg:deb/debian/1"),
|
||||||
|
},
|
||||||
|
expectedIndexes: expectedIndexes{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user