[partition] Add helper for running a KPMCore operation
Most *partition* module jobs run an operation and turn that into a JobResult -- ok if it succeeds, and with the report text otherwise. Factor it out into a separate method that can be used as shorthand.
This commit is contained in:
parent
53c90516b2
commit
dc7a1e43b7
@ -127,4 +127,19 @@ clonePartition( Device* device, Partition* partition )
|
||||
partition->activeFlags() );
|
||||
}
|
||||
|
||||
Calamares::JobResult
|
||||
execute( Operation& operation, const QString& failureMessage )
|
||||
{
|
||||
operation.setStatus( Operation::StatusRunning );
|
||||
|
||||
Report report( nullptr );
|
||||
if ( operation.execute( report ) )
|
||||
{
|
||||
return Calamares::JobResult::ok();
|
||||
}
|
||||
|
||||
return Calamares::JobResult::error( failureMessage, report.toText() );
|
||||
}
|
||||
|
||||
|
||||
} // namespace KPMHelpers
|
||||
|
@ -11,11 +11,13 @@
|
||||
#ifndef KPMHELPERS_H
|
||||
#define KPMHELPERS_H
|
||||
|
||||
// KPMcore
|
||||
#include "Job.h"
|
||||
|
||||
#include <kpmcore/core/partitiontable.h>
|
||||
#include <kpmcore/fs/filesystem.h>
|
||||
#include <kpmcore/ops/operation.h>
|
||||
#include <kpmcore/util/report.h>
|
||||
|
||||
// Qt
|
||||
#include <QList>
|
||||
|
||||
#include <functional>
|
||||
@ -72,6 +74,14 @@ Partition* createNewEncryptedPartition( PartitionNode* parent,
|
||||
|
||||
Partition* clonePartition( Device* device, Partition* partition );
|
||||
|
||||
/** @brief Return a result for an @p operation
|
||||
*
|
||||
* Executes the operation, and if successful, returns a success result.
|
||||
* Otherwise returns an error using @p failureMessage as the primary part
|
||||
* of the error, and details obtained from the operation.
|
||||
*/
|
||||
Calamares::JobResult execute( Operation& operation, const QString& failureMessage );
|
||||
|
||||
} // namespace KPMHelpers
|
||||
|
||||
#endif /* KPMHELPERS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user