70 lines
2.6 KiB
C++
70 lines
2.6 KiB
C++
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
||
|
*
|
||
|
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
|
||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||
|
*
|
||
|
* Calamares is Free Software: see the License-Identifier above.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include "Globals.h"
|
||
|
|
||
|
#include "GlobalStorage.h"
|
||
|
#include "JobQueue.h"
|
||
|
#include "utils/Logger.h"
|
||
|
|
||
|
bool
|
||
|
CalamaresUtils::Packages::setGSPackageAdditions( const Calamares::ModuleSystem::InstanceKey& module,
|
||
|
const QVariantList& installPackages,
|
||
|
const QVariantList& tryInstallPackages )
|
||
|
{
|
||
|
static const char PACKAGEOP[] = "packageOperations";
|
||
|
|
||
|
// Check if there's already a PACAKGEOP entry in GS, and if so we'll
|
||
|
// extend that one (overwriting the value in GS at the end of this method)
|
||
|
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
||
|
QVariantList packageOperations = gs->contains( PACKAGEOP ) ? gs->value( PACKAGEOP ).toList() : QVariantList();
|
||
|
cDebug() << "Existing package operations length" << packageOperations.length();
|
||
|
|
||
|
const QString key = module.toString() + QStringLiteral( ";add" );
|
||
|
|
||
|
// Clear out existing operations for this module, going backwards:
|
||
|
// Sometimes we remove an item, and we don't want the index to
|
||
|
// fall off the end of the list.
|
||
|
bool somethingRemoved = false;
|
||
|
for ( int index = packageOperations.length() - 1; 0 <= index; index-- )
|
||
|
{
|
||
|
const QVariantMap op = packageOperations.at( index ).toMap();
|
||
|
if ( op.contains( "source" ) && op.value( "source" ).toString() == key )
|
||
|
{
|
||
|
cDebug() << Logger::SubEntry << "Removing existing operations for" << key;
|
||
|
packageOperations.removeAt( index );
|
||
|
somethingRemoved = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( !installPackages.empty() )
|
||
|
{
|
||
|
QVariantMap op;
|
||
|
op.insert( "install", QVariant( installPackages ) );
|
||
|
op.insert( "source", key );
|
||
|
packageOperations.append( op );
|
||
|
cDebug() << Logger::SubEntry << installPackages.length() << "critical packages.";
|
||
|
}
|
||
|
if ( !tryInstallPackages.empty() )
|
||
|
{
|
||
|
QVariantMap op;
|
||
|
op.insert( "try_install", QVariant( tryInstallPackages ) );
|
||
|
op.insert( "source", key );
|
||
|
packageOperations.append( op );
|
||
|
cDebug() << Logger::SubEntry << tryInstallPackages.length() << "non-critical packages.";
|
||
|
}
|
||
|
|
||
|
if ( somethingRemoved || !packageOperations.isEmpty() )
|
||
|
{
|
||
|
gs->insert( PACKAGEOP, packageOperations );
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|