Convert FormatPartitionJob to KPMcore's CreateFileSystemOperation.

This commit is contained in:
Andrius Štikonas 2017-12-19 18:27:49 +00:00
parent 638117efa0
commit 1b3ce39ffb

View File

@ -22,15 +22,12 @@
#include "utils/Logger.h" #include "utils/Logger.h"
// KPMcore // KPMcore
#include <kpmcore/backend/corebackend.h> #include <core/device.h>
#include <kpmcore/backend/corebackendmanager.h> #include <core/partition.h>
#include <kpmcore/backend/corebackenddevice.h> #include <core/partitiontable.h>
#include <kpmcore/backend/corebackendpartitiontable.h> #include <fs/filesystem.h>
#include <kpmcore/core/device.h> #include <ops/createfilesystemoperation.h>
#include <kpmcore/core/partition.h> #include <util/report.h>
#include <kpmcore/core/partitiontable.h>
#include <kpmcore/fs/filesystem.h>
#include <kpmcore/util/report.h>
// Qt // Qt
#include <QScopedPointer> #include <QScopedPointer>
@ -78,62 +75,13 @@ Calamares::JobResult
FormatPartitionJob::exec() FormatPartitionJob::exec()
{ {
Report report( nullptr ); // Root of the report tree, no parent Report report( nullptr ); // Root of the report tree, no parent
QString partitionPath = m_partition->partitionPath(); CreateFileSystemOperation op(*m_device, *m_partition, m_partition->fileSystem().type());
QString message = tr( "The installer failed to format partition %1 on disk '%2'." ).arg( partitionPath, m_device->name() ); op.setStatus(Operation::StatusRunning);
CoreBackend* backend = CoreBackendManager::self()->backend(); QString message = tr( "The installer failed to format partition %1 on disk '%2'." ).arg( m_partition->partitionPath(), m_device->name() );
QScopedPointer<CoreBackendDevice> backendDevice( backend->openDevice( m_device->deviceNode() ) );
if ( !backendDevice.data() )
{
return Calamares::JobResult::error(
message,
tr( "Could not open device '%1'." ).arg( m_device->deviceNode() )
);
}
QScopedPointer<CoreBackendPartitionTable> backendPartitionTable( backendDevice->openPartitionTable() ); if (op.execute(report))
if ( !backendPartitionTable.data() ) return Calamares::JobResult::ok();
{
return Calamares::JobResult::error(
message,
tr( "Could not open partition table." )
);
}
FileSystem& fs = m_partition->fileSystem(); return Calamares::JobResult::error(message, report.toText());
bool ok = fs.create( report, partitionPath );
int retries = 0;
const int MAX_RETRIES = 10;
while ( !ok )
{
cDebug() << "Partition" << m_partition->partitionPath()
<< "might not be ready yet, retrying (" << ++retries
<< "/" << MAX_RETRIES << ") ...";
QThread::sleep( 2 /*seconds*/ );
ok = fs.create( report, partitionPath );
if ( retries == MAX_RETRIES )
break;
}
if ( !ok )
{
return Calamares::JobResult::error(
tr( "The installer failed to create file system on partition %1." )
.arg( partitionPath ),
report.toText()
);
}
if ( !backendPartitionTable->setPartitionSystemType( report, *m_partition ) )
{
return Calamares::JobResult::error(
tr( "The installer failed to update partition table on disk '%1'." ).arg( m_device->name() ),
report.toText()
);
}
backendPartitionTable->commit();
return Calamares::JobResult::ok();
} }