Fix bug with tiny disks and mbr partition tables
This commit is contained in:
parent
26f6943f8a
commit
4c88603872
@ -93,7 +93,12 @@ public:
|
|||||||
PartitionTable* table = device->partitionTable();
|
PartitionTable* table = device->partitionTable();
|
||||||
if ( !table )
|
if ( !table )
|
||||||
return it;
|
return it;
|
||||||
it.m_current = table->children().first();
|
QList< Partition* > children = table->children();
|
||||||
|
// Does not usually happen, but it did happen on a 10MB disk with an MBR
|
||||||
|
// partition table.
|
||||||
|
if ( children.isEmpty() )
|
||||||
|
return it;
|
||||||
|
it.m_current = children.first();
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,15 @@ static const qint64 MB = 1024 * 1024;
|
|||||||
|
|
||||||
using namespace Calamares;
|
using namespace Calamares;
|
||||||
|
|
||||||
|
static
|
||||||
|
Partition* firstFreePartition( PartitionNode* parent )
|
||||||
|
{
|
||||||
|
for( auto child : parent->children() )
|
||||||
|
if ( PMUtils::isPartitionFreeSpace( child ) )
|
||||||
|
return child;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
QueueRunner::QueueRunner( JobQueue* queue )
|
QueueRunner::QueueRunner( JobQueue* queue )
|
||||||
: m_queue( queue )
|
: m_queue( queue )
|
||||||
{
|
{
|
||||||
@ -83,8 +92,15 @@ JobTests::initTestCase()
|
|||||||
void
|
void
|
||||||
JobTests::testPartitionTable()
|
JobTests::testPartitionTable()
|
||||||
{
|
{
|
||||||
|
queuePartitionTableCreation( PartitionTable::msdos );
|
||||||
|
QVERIFY( m_runner.run() );
|
||||||
|
QVERIFY( m_device->partitionTable() );
|
||||||
|
QVERIFY( firstFreePartition( m_device->partitionTable() ) );
|
||||||
|
|
||||||
queuePartitionTableCreation( PartitionTable::gpt );
|
queuePartitionTableCreation( PartitionTable::gpt );
|
||||||
m_runner.run();
|
QVERIFY( m_runner.run() );
|
||||||
|
QVERIFY( m_device->partitionTable() );
|
||||||
|
QVERIFY( firstFreePartition( m_device->partitionTable() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -124,15 +140,6 @@ JobTests::newCreatePartitionJob( Partition* freeSpacePartition, PartitionRole ro
|
|||||||
return new CreatePartitionJob( m_device.data(), partition );
|
return new CreatePartitionJob( m_device.data(), partition );
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
|
||||||
Partition* firstFreePartition( PartitionNode* parent )
|
|
||||||
{
|
|
||||||
for( auto child : parent->children() )
|
|
||||||
if ( PMUtils::isPartitionFreeSpace( child ) )
|
|
||||||
return child;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
JobTests::testCreatePartition()
|
JobTests::testCreatePartition()
|
||||||
{
|
{
|
||||||
@ -140,18 +147,20 @@ JobTests::testCreatePartition()
|
|||||||
CreatePartitionJob* job;
|
CreatePartitionJob* job;
|
||||||
|
|
||||||
Partition* partition = firstFreePartition( m_device->partitionTable() );
|
Partition* partition = firstFreePartition( m_device->partitionTable() );
|
||||||
job = newCreatePartitionJob( partition, PartitionRole( PartitionRole::Primary ), FileSystem::Ext4, 10 * MB);
|
job = newCreatePartitionJob( partition, PartitionRole( PartitionRole::Primary ), FileSystem::Ext4, 1 * MB);
|
||||||
QVERIFY( job );
|
QVERIFY( job );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
m_queue.enqueue( job_ptr( job ) );
|
m_queue.enqueue( job_ptr( job ) );
|
||||||
|
|
||||||
partition = firstFreePartition( m_device->partitionTable() );
|
partition = firstFreePartition( m_device->partitionTable() );
|
||||||
job = newCreatePartitionJob( partition, PartitionRole( PartitionRole::Primary ), FileSystem::LinuxSwap, 10 * MB);
|
QVERIFY( partition );
|
||||||
|
job = newCreatePartitionJob( partition, PartitionRole( PartitionRole::Primary ), FileSystem::LinuxSwap, 1 * MB);
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
m_queue.enqueue( job_ptr( job ) );
|
m_queue.enqueue( job_ptr( job ) );
|
||||||
|
|
||||||
partition = firstFreePartition( m_device->partitionTable() );
|
partition = firstFreePartition( m_device->partitionTable() );
|
||||||
job = newCreatePartitionJob( partition, PartitionRole( PartitionRole::Primary ), FileSystem::Btrfs, 10 * MB);
|
QVERIFY( partition );
|
||||||
|
job = newCreatePartitionJob( partition, PartitionRole( PartitionRole::Primary ), FileSystem::Fat32, 1 * MB);
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
m_queue.enqueue( job_ptr( job ) );
|
m_queue.enqueue( job_ptr( job ) );
|
||||||
|
|
||||||
@ -171,12 +180,14 @@ JobTests::testCreatePartitionExtended()
|
|||||||
m_queue.enqueue( job_ptr( job ) );
|
m_queue.enqueue( job_ptr( job ) );
|
||||||
|
|
||||||
partition = firstFreePartition( m_device->partitionTable() );
|
partition = firstFreePartition( m_device->partitionTable() );
|
||||||
|
QVERIFY( partition );
|
||||||
job = newCreatePartitionJob( partition, PartitionRole( PartitionRole::Extended ), FileSystem::Extended, 10 * MB);
|
job = newCreatePartitionJob( partition, PartitionRole( PartitionRole::Extended ), FileSystem::Extended, 10 * MB);
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
m_queue.enqueue( job_ptr( job ) );
|
m_queue.enqueue( job_ptr( job ) );
|
||||||
Partition* extendedPartition = job->partition();
|
Partition* extendedPartition = job->partition();
|
||||||
|
|
||||||
partition = firstFreePartition( extendedPartition );
|
partition = firstFreePartition( extendedPartition );
|
||||||
|
QVERIFY( partition );
|
||||||
job = newCreatePartitionJob( partition, PartitionRole( PartitionRole::Logical ), FileSystem::Ext4, 0);
|
job = newCreatePartitionJob( partition, PartitionRole( PartitionRole::Logical ), FileSystem::Ext4, 0);
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
m_queue.enqueue( job_ptr( job ) );
|
m_queue.enqueue( job_ptr( job ) );
|
||||||
|
Loading…
Reference in New Issue
Block a user