[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::PartitionMatch
ResizeFSJob::findPartition( CoreBackend* backend ) ResizeFSJob::findPartition()
{ {
using DeviceList = QList< Device* >; using DeviceList = QList< Device* >;
#if defined( WITH_KPMCORE4API ) #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 #else
DeviceList devices = backend->scanDevices( /* excludeReadOnly */ true ); DeviceList devices = m_kpmcore.backend()->scanDevices( /* excludeReadOnly */ true );
#endif #endif
cDebug() << "ResizeFSJob found" << devices.count() << "devices."; cDebug() << "ResizeFSJob found" << devices.count() << "devices.";
@ -170,35 +170,17 @@ ResizeFSJob::exec()
tr( "Invalid configuration" ), tr( "Invalid configuration" ),
tr( "The file-system resize job has an invalid configuration and will not run." ) ); tr( "The file-system resize job has an invalid configuration and will not run." ) );
// Get KPMCore if ( !m_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 )
{ {
cWarning() << "Could not load KPMCore backend (2)."; cWarning() << "Could not load KPMCore backend (2).";
return Calamares::JobResult::error( return Calamares::JobResult::error(
tr( "KPMCore not Available" ), tr( "KPMCore not Available" ),
tr( "Calamares cannot start KPMCore for the file-system resize job." ) ); 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 // Now get the partition and FS we want to work on
PartitionMatch m = findPartition( backend_p ); PartitionMatch m = findPartition();
if ( !m.first || !m.second ) if ( !m.first || !m.second )
return Calamares::JobResult::error( return Calamares::JobResult::error(
tr( "Resize Failed" ), tr( "Resize Failed" ),

View file

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