@@ -15,13 +15,13 @@ import (
1515 "go.mondoo.com/mql/v13/cli/execruntime"
1616 "go.mondoo.com/mql/v13/internal/workerpool"
1717 "go.mondoo.com/mql/v13/llx"
18- "go.mondoo.com/mql/v13/utils/slicesx"
1918 "go.mondoo.com/mql/v13/logger"
2019 "go.mondoo.com/mql/v13/providers"
2120 inventory "go.mondoo.com/mql/v13/providers-sdk/v1/inventory"
2221 "go.mondoo.com/mql/v13/providers-sdk/v1/inventory/manager"
2322 "go.mondoo.com/mql/v13/providers-sdk/v1/plugin"
2423 "go.mondoo.com/mql/v13/providers-sdk/v1/upstream"
24+ "go.mondoo.com/mql/v13/utils/slicesx"
2525 "google.golang.org/protobuf/proto"
2626)
2727
@@ -68,19 +68,30 @@ func (d *DiscoveredAssets) Add(asset *inventory.Asset, runtime *providers.Runtim
6868 return false
6969 }
7070
71+ // Evict existing assets whose IDs are a subset of the new asset's IDs.
72+ // This ensures deduplication is order-independent.
73+ kept := d .Assets [:0 ]
7174 for _ , existing := range d .Assets {
7275 if slicesx .IsSubsetOf (asset .PlatformIds , existing .Asset .PlatformIds ) {
7376 log .Debug ().Str ("asset" , asset .Name ).Strs ("platform-ids" , asset .PlatformIds ).Msg ("discovery> skipping duplicate asset" )
7477 return false
7578 }
79+ if slicesx .IsSubsetOf (existing .Asset .PlatformIds , asset .PlatformIds ) {
80+ log .Debug ().Str ("asset" , existing .Asset .Name ).Strs ("platform-ids" , existing .Asset .PlatformIds ).Msg ("discovery> evicting asset that is a subset of new asset" )
81+ if existing .Runtime != nil {
82+ existing .Runtime .Close ()
83+ }
84+ continue
85+ }
86+ kept = append (kept , existing )
7687 }
88+ d .Assets = kept
7789
7890 log .Debug ().Str ("asset" , asset .Name ).Strs ("platform-ids" , asset .PlatformIds ).Int ("total" , len (d .Assets )+ 1 ).Msg ("discovery> added asset" )
7991 d .Assets = append (d .Assets , & AssetWithRuntime {Asset : asset , Runtime : runtime })
8092 return true
8193}
8294
83-
8495func (d * DiscoveredAssets ) AddError (asset * inventory.Asset , err error ) {
8596 d .assetsLock .Lock ()
8697 defer d .assetsLock .Unlock ()
0 commit comments