Convert FormatPartitionJob to KPMcore's CreateFileSystemOperation.
This commit is contained in:
parent
638117efa0
commit
1b3ce39ffb
@ -22,15 +22,12 @@
|
||||
#include "utils/Logger.h"
|
||||
|
||||
// KPMcore
|
||||
#include <kpmcore/backend/corebackend.h>
|
||||
#include <kpmcore/backend/corebackendmanager.h>
|
||||
#include <kpmcore/backend/corebackenddevice.h>
|
||||
#include <kpmcore/backend/corebackendpartitiontable.h>
|
||||
#include <kpmcore/core/device.h>
|
||||
#include <kpmcore/core/partition.h>
|
||||
#include <kpmcore/core/partitiontable.h>
|
||||
#include <kpmcore/fs/filesystem.h>
|
||||
#include <kpmcore/util/report.h>
|
||||
#include <core/device.h>
|
||||
#include <core/partition.h>
|
||||
#include <core/partitiontable.h>
|
||||
#include <fs/filesystem.h>
|
||||
#include <ops/createfilesystemoperation.h>
|
||||
#include <util/report.h>
|
||||
|
||||
// Qt
|
||||
#include <QScopedPointer>
|
||||
@ -78,62 +75,13 @@ Calamares::JobResult
|
||||
FormatPartitionJob::exec()
|
||||
{
|
||||
Report report( nullptr ); // Root of the report tree, no parent
|
||||
QString partitionPath = m_partition->partitionPath();
|
||||
QString message = tr( "The installer failed to format partition %1 on disk '%2'." ).arg( partitionPath, m_device->name() );
|
||||
CreateFileSystemOperation op(*m_device, *m_partition, m_partition->fileSystem().type());
|
||||
op.setStatus(Operation::StatusRunning);
|
||||
|
||||
CoreBackend* backend = CoreBackendManager::self()->backend();
|
||||
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() )
|
||||
);
|
||||
}
|
||||
QString message = tr( "The installer failed to format partition %1 on disk '%2'." ).arg( m_partition->partitionPath(), m_device->name() );
|
||||
|
||||
QScopedPointer<CoreBackendPartitionTable> backendPartitionTable( backendDevice->openPartitionTable() );
|
||||
if ( !backendPartitionTable.data() )
|
||||
{
|
||||
return Calamares::JobResult::error(
|
||||
message,
|
||||
tr( "Could not open partition table." )
|
||||
);
|
||||
}
|
||||
if (op.execute(report))
|
||||
return Calamares::JobResult::ok();
|
||||
|
||||
FileSystem& fs = m_partition->fileSystem();
|
||||
|
||||
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();
|
||||
return Calamares::JobResult::error(message, report.toText());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user