Move CalaPM init into PMUtils.

main
Teo Mrnjavac 9 years ago
parent c2eef9ac30
commit adc23b99b6

@ -25,10 +25,35 @@
// KPMcore
#include <kpmcore/core/partition.h>
#include <kpmcore/fs/filesystemfactory.h>
#include <kpmcore/backend/corebackendmanager.h>
#include <QDebug>
namespace PMUtils
{
static bool s_KPMcoreInited = false;
bool
initKPMcore()
{
if ( s_KPMcoreInited )
return true;
QByteArray backendName = qgetenv( "KPMCORE_BACKEND" );
if ( backendName.isEmpty() )
backendName = "libparted";
if ( !CoreBackendManager::self()->load( backendName ) )
{
qWarning() << "Failed to load backend plugin" << backendName;
return false;
}
s_KPMcoreInited = true;
return true;
}
bool
isPartitionFreeSpace( Partition* partition )
@ -115,5 +140,4 @@ clonePartition( Device* device, Partition* partition )
);
}
} // namespace

@ -38,6 +38,19 @@ class PartitionRole;
namespace PMUtils
{
/**
* Thin wrapper on top of CoreBackendManager. Hides things like initializing the
* Config instance or instantiating the backend.
*
* Initialize PartitionManager Config object and load a PartitionManager
* backend. It loads the "libparted" plugin by default, but this can be
* overloaded by settings the environment variable KPMCORE_BACKEND. Setting it to
* "dummy" will load the dummy plugin instead.
*
* @return true if initialization was successful.
*/
bool initKPMcore();
bool isPartitionFreeSpace( Partition* );
/**

@ -17,28 +17,27 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include <core/PartitionCoreModule.h>
#include <core/BootLoaderModel.h>
#include <core/DeviceModel.h>
#include <core/PartitionInfo.h>
#include <core/PartitionIterator.h>
#include <core/PartitionModel.h>
#include <core/PMUtils.h>
#include <jobs/ClearMountsJob.h>
#include <jobs/ClearTempMountsJob.h>
#include <jobs/CreatePartitionJob.h>
#include <jobs/CreatePartitionTableJob.h>
#include <jobs/DeletePartitionJob.h>
#include <jobs/FillGlobalStorageJob.h>
#include <jobs/FormatPartitionJob.h>
#include <jobs/ResizePartitionJob.h>
#include <Typedefs.h>
#include <utils/Logger.h>
#include "core/PartitionCoreModule.h"
#include "core/BootLoaderModel.h"
#include "core/DeviceModel.h"
#include "core/PartitionInfo.h"
#include "core/PartitionIterator.h"
#include "core/PartitionModel.h"
#include "core/PMUtils.h"
#include "jobs/ClearMountsJob.h"
#include "jobs/ClearTempMountsJob.h"
#include "jobs/CreatePartitionJob.h"
#include "jobs/CreatePartitionTableJob.h"
#include "jobs/DeletePartitionJob.h"
#include "jobs/FillGlobalStorageJob.h"
#include "jobs/FormatPartitionJob.h"
#include "jobs/ResizePartitionJob.h"
#include "Typedefs.h"
#include "utils/Logger.h"
// KPMcore
#include <CalaPM.h>
#include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h>
#include <kpmcore/backend/corebackend.h>
@ -97,8 +96,8 @@ PartitionCoreModule::PartitionCoreModule( QObject* parent )
, m_deviceModel( new DeviceModel( this ) )
, m_bootLoaderModel( new BootLoaderModel( this ) )
{
if ( !CalaPM::init() )
qFatal( "Failed to init CalaPM" );
if ( !PMUtils::initKPMcore() )
qFatal( "Failed to initialize KPMcore backend" );
FileSystemFactory::init();
init();
}

Loading…
Cancel
Save