diff --git a/src/modules/netinstall/PackageModel.cpp b/src/modules/netinstall/PackageModel.cpp index ac7443c15..3fc2f4d43 100644 --- a/src/modules/netinstall/PackageModel.cpp +++ b/src/modules/netinstall/PackageModel.cpp @@ -378,14 +378,19 @@ PackageModel::appendModelData( const QVariantList& groupList ) if ( !sources.isEmpty() ) { // Prune any existing data from the same source + QList< int > removeList; for ( int i = 0; i < m_rootItem->childCount(); i++ ) { PackageTreeItem* child = m_rootItem->child( i ); if ( sources.contains( child->source() ) ) { - m_rootItem->removeChild( i ); + removeList.insert( 0, i ); } } + for ( const int& item : qAsConst( removeList ) ) + { + m_rootItem->removeChild( item ); + } } // Add the new data to the model diff --git a/src/modules/packagechooser/Config.cpp b/src/modules/packagechooser/Config.cpp index c6f5c9658..491fe5c25 100644 --- a/src/modules/packagechooser/Config.cpp +++ b/src/modules/packagechooser/Config.cpp @@ -27,6 +27,29 @@ #include "utils/Logger.h" #include "utils/Variant.h" +/** @brief This removes any values from @p groups that match @p source + * + * This is used to remove duplicates from the netinstallAdd structure + * It iterates over @p groups and for each map in the list, if the + * "source" element matches @p source, it is removed from the returned + * list. + */ +static QVariantList +pruneNetinstallAdd( const QString& source, const QVariant& groups ) +{ + QVariantList newGroupList; + const QVariantList groupList = groups.toList(); + for ( const QVariant& group : groupList ) + { + QVariantMap groupMap = group.toMap(); + if ( groupMap.value( "source", "" ).toString() != source ) + { + newGroupList.append( groupMap ); + } + } + return newGroupList; +} + const NamedEnumTable< PackageChooserMode >& packageChooserModeNames() { @@ -132,7 +155,14 @@ Config::updateGlobalStorage( const QStringList& selected ) const } else { - Calamares::JobQueue::instance()->globalStorage()->insert( "netinstallAdd", netinstallDataList ); + // If an earlier packagechooser instance added this data to global storage, combine them + auto* gs = Calamares::JobQueue::instance()->globalStorage(); + if ( gs->contains( "netinstallAdd" ) ) + { + netinstallDataList + += pruneNetinstallAdd( QStringLiteral( "packageChooser" ), gs->value( "netinstallAdd" ) ); + } + gs->insert( "netinstallAdd", netinstallDataList ); } } else if ( m_method == PackageChooserMethod::NetSelect )