Addresses #1267 where removals might consider/process the same item multiple times

This commit is contained in:
Greg Neagle
2025-09-19 13:20:54 -07:00
parent 9c3d199ff3
commit e498022578
@@ -177,18 +177,28 @@ func getAllItemsWithName(_ name: String, catalogList: [String]) -> [PlistDict] {
let nameTable = catalogDB["named"] as? CatalogDBTable,
let versionsDict = nameTable[itemName]
{
var indexesToAdd: Set<Int> = []
for (version, indexes) in versionsDict {
if version == "latest" {
continue
}
indexesToAdd.formUnion(indexes)
}
for index in indexesToAdd {
let item = items[index]
let version = item["version"] as? String ?? "<unknown>"
display.debug1("Adding item \(itemName), version \(version) from catalog \(catalogName)...")
itemList.append(item)
for index in indexes {
do {
let item = items[index]
// need to compare encoded representations because
// PlistDict (aka [String: Any] is not hashable
let itemEncoded = try plistToData(item)
let alreadyAddedItem = try itemList.contains(
where: { try plistToData($0) == itemEncoded })
if !alreadyAddedItem {
let version = item["version"] as? String ?? "<unknown>"
display.debug1("Adding item \(itemName), version \(version) from catalog \(catalogName)...")
itemList.append(item)
}
} catch {
// error converting an item to plistData. Really unlikely,
// but if it happens we just don't add the item and continue on
}
}
}
}
}