[fsresizer] Use partition service

- Don't need to initialize KPMCore ourself.
 - Simplify error paths.
This commit is contained in:
Adriaan de Groot 2019-06-13 23:36:13 +02:00
parent d0d017f5fe
commit ed999a247a
2 changed files with 10 additions and 26 deletions

View file

@ -58,13 +58,13 @@ ResizeFSJob::prettyName() const
}
ResizeFSJob::PartitionMatch
ResizeFSJob::findPartition( CoreBackend* backend )
ResizeFSJob::findPartition()
{
using DeviceList = QList< Device* >;
#if defined( WITH_KPMCORE4API )
DeviceList devices = backend->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag(0) );
DeviceList devices = m_kpmcore.backend()->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag(0) );
#else
DeviceList devices = backend->scanDevices( /* excludeReadOnly */ true );
DeviceList devices = m_kpmcore.backend()->scanDevices( /* excludeReadOnly */ true );
#endif
cDebug() << "ResizeFSJob found" << devices.count() << "devices.";
@ -170,35 +170,17 @@ ResizeFSJob::exec()
tr( "Invalid configuration" ),
tr( "The file-system resize job has an invalid configuration and will not run." ) );
// Get KPMCore
auto backend_p = CoreBackendManager::self()->backend();
if ( backend_p )
cDebug() << "KPMCore backend @" << ( void* )backend_p << backend_p->id() << backend_p->version();
else
{
cDebug() << "No KPMCore backend loaded yet";
QByteArray backendName = qgetenv( "KPMCORE_BACKEND" );
if ( !CoreBackendManager::self()->load( backendName.isEmpty() ? CoreBackendManager::defaultBackendName() : backendName ) )
{
cWarning() << "Could not load KPMCore backend.";
return Calamares::JobResult::error(
tr( "KPMCore not Available" ),
tr( "Calamares cannot start KPMCore for the file-system resize job." ) );
}
backend_p = CoreBackendManager::self()->backend();
}
if ( !backend_p )
if ( !m_kpmcore)
{
cWarning() << "Could not load KPMCore backend (2).";
return Calamares::JobResult::error(
tr( "KPMCore not Available" ),
tr( "Calamares cannot start KPMCore for the file-system resize job." ) );
}
backend_p->initFSSupport(); // Might not be enough, see below
m_kpmcore.backend()->initFSSupport(); // Might not be enough, see below
// Now get the partition and FS we want to work on
PartitionMatch m = findPartition( backend_p );
PartitionMatch m = findPartition();
if ( !m.first || !m.second )
return Calamares::JobResult::error(
tr( "Resize Failed" ),

View file

@ -24,6 +24,7 @@
#include <CppJob.h>
#include "partition/KPMManager.h"
#include "partition/PartitionSize.h"
#include "utils/PluginFactory.h"
@ -72,6 +73,7 @@ public:
}
private:
CalamaresUtils::Partition::KPMManager m_kpmcore;
PartitionSize m_size;
PartitionSize m_atleast;
QString m_fsname; // Either this, or devicename, is set, not both
@ -79,8 +81,8 @@ private:
bool m_required;
using PartitionMatch = QPair<Device*, Partition*>;
/** @brief Find the configured FS using KPMCore @p backend */
PartitionMatch findPartition( CoreBackend* backend );
/** @brief Find the configured FS */
PartitionMatch findPartition();
/** @brief Return a new end-sector for the given dev-part pair. */
qint64 findGrownEnd( PartitionMatch );