Merge branch 'issue-1129'

FIXES #1129
This commit is contained in:
Adriaan de Groot 2019-05-09 08:14:25 -04:00
commit bbd2afc20f
14 changed files with 69 additions and 73 deletions

View File

@ -74,7 +74,7 @@ canBeReplaced( Partition* candidate )
bool ok = false;
double requiredStorageGB = Calamares::JobQueue::instance()
->globalStorage()
->value( "requiredStorageGB" )
->value( "requiredStorageGiB" )
.toDouble( &ok );
qint64 availableStorageB = candidate->capacity();
@ -146,7 +146,7 @@ canBeResized( Partition* candidate )
bool ok = false;
double requiredStorageGB = Calamares::JobQueue::instance()
->globalStorage()
->value( "requiredStorageGB" )
->value( "requiredStorageGiB" )
.toDouble( &ok );
// We require a little more for partitioning overhead and swap file
double advisedStorageGB = requiredStorageGB + 0.5 + 2.0;

View File

@ -98,7 +98,7 @@ PartitionIterator::begin( PartitionTable* table )
{
auto it = PartitionIterator( table );
QList< Partition* > children = table->children();
// Does not usually happen, but it did happen on a 10MB disk with an MBR
// Does not usually happen, but it did happen on a tiny (10MiB) disk with an MBR
// partition table.
if ( children.isEmpty() )
return it;

View File

@ -462,7 +462,7 @@ ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice )
gs->value( "defaultFileSystemType" ).toString(),
m_encryptWidget->passphrase(),
gs->value( "efiSystemPartition" ).toString(),
CalamaresUtils::GiBtoBytes( gs->value( "requiredStorageGB" ).toDouble() ),
CalamaresUtils::GiBtoBytes( gs->value( "requiredStorageGiB" ).toDouble() ),
m_eraseSwapChoice
};
@ -560,11 +560,10 @@ ChoicePage::doAlongsideSetupSplitter( const QModelIndex& current,
double requiredStorageGB = Calamares::JobQueue::instance()
->globalStorage()
->value( "requiredStorageGB" )
->value( "requiredStorageGiB" )
.toDouble();
// TODO: make this consistent
qint64 requiredStorageB = qRound64( requiredStorageGB + 0.1 + 2.0 ) * 1024 * 1024 * 1024;
qint64 requiredStorageB = CalamaresUtils::GiBtoBytes( requiredStorageGB + 0.1 + 2.0 );
m_afterPartitionSplitterWidget->setSplitPartition(
part->partitionPath(),
@ -967,11 +966,11 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
qint64 sizeNext )
{
Q_UNUSED( path )
sizeLabel->setText( tr( "%1 will be shrunk to %2MB and a new "
"%3MB partition will be created for %4." )
sizeLabel->setText( tr( "%1 will be shrunk to %2MiB and a new "
"%3MiB partition will be created for %4." )
.arg( m_beforePartitionBarsView->selectionModel()->currentIndex().data().toString() )
.arg( size / ( 1024 * 1024 ) )
.arg( sizeNext / ( 1024 * 1024 ) )
.arg( CalamaresUtils::BytesToMiB( size ) )
.arg( CalamaresUtils::BytesToMiB( sizeNext ) )
.arg( *Calamares::Branding::ShortProductName ) );
} );

View File

@ -19,11 +19,12 @@
#include "PartitionLabelsView.h"
#include <core/PartitionModel.h>
#include <core/ColorUtils.h>
#include "core/PartitionModel.h"
#include "core/ColorUtils.h"
#include <utils/CalamaresUtilsGui.h>
#include <utils/Logger.h>
#include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include "utils/Units.h"
#include <kpmcore/core/device.h>
#include <kpmcore/fs/filesystem.h>
@ -35,6 +36,7 @@
#include <QMouseEvent>
#include <QPainter>
using CalamaresUtils::operator""_MiB;
static const int LAYOUT_MARGIN = 4;
static const int LABEL_PARTITION_SQUARE_MARGIN =
@ -62,12 +64,6 @@ PartitionLabelsView::PartitionLabelsView( QWidget* parent )
setSelectionBehavior( QAbstractItemView::SelectRows );
setSelectionMode( QAbstractItemView::SingleSelection );
this->setObjectName("partitionLabel");
// Debug
connect( this, &PartitionLabelsView::clicked,
this, [=]( const QModelIndex& index )
{
cDebug() << "Clicked row" << index.row();
} );
setMouseTracking( true );
}
@ -162,8 +158,8 @@ PartitionLabelsView::getIndexesToDraw( const QModelIndex& parent ) const
//HACK: horrible special casing follows.
// To save vertical space, we choose to hide short instances of free space.
// Arbitrary limit: 10MB.
const qint64 maxHiddenB = 10000000;
// Arbitrary limit: 10MiB.
const qint64 maxHiddenB = 10_MiB;
if ( index.data( PartitionModel::IsFreeSpaceRole ).toBool() &&
index.data( PartitionModel::SizeRole ).toLongLong() < maxHiddenB )
continue;

View File

@ -143,7 +143,7 @@ ReplaceWidget::onPartitionSelected()
bool ok = false;
double requiredSpaceB = Calamares::JobQueue::instance()
->globalStorage()
->value( "requiredStorageGB" )
->value( "requiredStorageGiB" )
.toDouble( &ok ) * 1024 * 1024 * 1024;
PartitionModel* model = qobject_cast< PartitionModel* >( m_ui->partitionTreeView->model() );

View File

@ -41,7 +41,7 @@ CreatePartitionJob::CreatePartitionJob( Device* device, Partition* partition )
QString
CreatePartitionJob::prettyName() const
{
return tr( "Create new %2MB partition on %4 (%3) with file system %1." )
return tr( "Create new %2MiB partition on %4 (%3) with file system %1." )
.arg( m_partition->fileSystem().name() )
.arg( CalamaresUtils::BytesToMiB( m_partition->capacity() ) )
.arg( m_device->name() )
@ -52,7 +52,7 @@ CreatePartitionJob::prettyName() const
QString
CreatePartitionJob::prettyDescription() const
{
return tr( "Create new <strong>%2MB</strong> partition on <strong>%4</strong> "
return tr( "Create new <strong>%2MiB</strong> partition on <strong>%4</strong> "
"(%3) with file system <strong>%1</strong>." )
.arg( m_partition->fileSystem().name() )
.arg( CalamaresUtils::BytesToMiB( m_partition->capacity() ) )

View File

@ -38,7 +38,7 @@ FormatPartitionJob::FormatPartitionJob( Device* device, Partition* partition )
QString
FormatPartitionJob::prettyName() const
{
return tr( "Format partition %1 (file system: %2, size: %3 MB) on %4." )
return tr( "Format partition %1 (file system: %2, size: %3 MiB) on %4." )
.arg( m_partition->partitionPath() )
.arg( m_partition->fileSystem().name() )
.arg( m_partition->capacity() / 1024 / 1024 )
@ -49,7 +49,7 @@ FormatPartitionJob::prettyName() const
QString
FormatPartitionJob::prettyDescription() const
{
return tr( "Format <strong>%3MB</strong> partition <strong>%1</strong> with "
return tr( "Format <strong>%3MiB</strong> partition <strong>%1</strong> with "
"file system <strong>%2</strong>." )
.arg( m_partition->partitionPath() )
.arg( m_partition->fileSystem().name() )

View File

@ -52,8 +52,8 @@ ResizePartitionJob::prettyName() const
QString
ResizePartitionJob::prettyDescription() const
{
return tr( "Resize <strong>%2MB</strong> partition <strong>%1</strong> to "
"<strong>%3MB</strong>." )
return tr( "Resize <strong>%2MiB</strong> partition <strong>%1</strong> to "
"<strong>%3MiB</strong>." )
.arg( partition()->partitionPath() )
.arg( ( BytesToMiB( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() ) )
.arg( ( BytesToMiB( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() ) );
@ -63,8 +63,8 @@ ResizePartitionJob::prettyDescription() const
QString
ResizePartitionJob::prettyStatusMessage() const
{
return tr( "Resizing %2MB partition %1 to "
"%3MB." )
return tr( "Resizing %2MiB partition %1 to "
"%3MiB." )
.arg( partition()->partitionPath() )
.arg( ( BytesToMiB( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() ) )
.arg( ( BytesToMiB( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() ) );

View File

@ -49,7 +49,7 @@ SetPartFlagsJob::prettyName() const
return tr( "Set flags on partition %1." ).arg( partition()->partitionPath() );
if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Set flags on %1MB %2 partition." )
return tr( "Set flags on %1MiB %2 partition." )
.arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() );
@ -68,7 +68,7 @@ SetPartFlagsJob::prettyDescription() const
.arg( partition()->partitionPath() );
if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Clear flags on %1MB <strong>%2</strong> partition." )
return tr( "Clear flags on %1MiB <strong>%2</strong> partition." )
.arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() );
@ -82,7 +82,7 @@ SetPartFlagsJob::prettyDescription() const
.arg( flagsList.join( ", " ) );
if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Flag %1MB <strong>%2</strong> partition as "
return tr( "Flag %1MiB <strong>%2</strong> partition as "
"<strong>%3</strong>." )
.arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() )
@ -104,7 +104,7 @@ SetPartFlagsJob::prettyStatusMessage() const
.arg( partition()->partitionPath() );
if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Clearing flags on %1MB <strong>%2</strong> partition." )
return tr( "Clearing flags on %1MiB <strong>%2</strong> partition." )
.arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() );
@ -119,7 +119,7 @@ SetPartFlagsJob::prettyStatusMessage() const
if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Setting flags <strong>%3</strong> on "
"%1MB <strong>%2</strong> partition." )
"%1MiB <strong>%2</strong> partition." )
.arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() )
.arg( flagsList.join( ", " ) );

View File

@ -72,6 +72,7 @@ private:
bool m_mounted;
};
/// @brief Generate random data of given @p size as a QByteArray
static QByteArray
generateTestData( qint64 size )
{
@ -321,10 +322,10 @@ PartitionJobTests::testCreatePartitionExtended()
void
PartitionJobTests::testResizePartition_data()
{
QTest::addColumn< int >( "oldStartMB" );
QTest::addColumn< int >( "oldSizeMB" );
QTest::addColumn< int >( "newStartMB" );
QTest::addColumn< int >( "newSizeMB" );
QTest::addColumn< int >( "oldStartMiB" );
QTest::addColumn< int >( "oldSizeMiB" );
QTest::addColumn< int >( "newStartMiB" );
QTest::addColumn< int >( "newSizeMiB" );
QTest::newRow("grow") << 10 << 50 << 10 << 70;
QTest::newRow("shrink") << 10 << 70 << 10 << 50;
@ -335,22 +336,22 @@ PartitionJobTests::testResizePartition_data()
void
PartitionJobTests::testResizePartition()
{
QFETCH( int, oldStartMB );
QFETCH( int, oldSizeMB );
QFETCH( int, newStartMB );
QFETCH( int, newSizeMB );
QFETCH( int, oldStartMiB );
QFETCH( int, oldSizeMiB );
QFETCH( int, newStartMiB );
QFETCH( int, newSizeMiB );
const qint64 sectorForMB = 1_MiB / m_device->logicalSize();
const qint64 sectorsPerMiB = 1_MiB / m_device->logicalSize();
qint64 oldFirst = sectorForMB * oldStartMB;
qint64 oldLast = oldFirst + sectorForMB * oldSizeMB - 1;
qint64 newFirst = sectorForMB * newStartMB;
qint64 newLast = newFirst + sectorForMB * newSizeMB - 1;
qint64 oldFirst = sectorsPerMiB * oldStartMiB;
qint64 oldLast = oldFirst + sectorsPerMiB * oldSizeMiB - 1;
qint64 newFirst = sectorsPerMiB * newStartMiB;
qint64 newLast = newFirst + sectorsPerMiB * newSizeMiB - 1;
// Make the test data file smaller than the full size of the partition to
// accomodate for the file system overhead
const unsigned long long minSizeMB = qMin( oldSizeMB, newSizeMB );
const QByteArray testData = generateTestData( CalamaresUtils::MiBtoBytes( minSizeMB ) * 3 / 4 );
const unsigned long long minSizeMiB = qMin( oldSizeMiB, newSizeMiB );
const QByteArray testData = generateTestData( CalamaresUtils::MiBtoBytes( minSizeMiB ) * 3 / 4 );
const QString testName = "test.data";
// Setup: create the test partition

View File

@ -56,8 +56,8 @@
GeneralRequirements::GeneralRequirements( QObject* parent )
: QObject( parent )
, m_requiredStorageGB( -1 )
, m_requiredRamGB( -1 )
, m_requiredStorageGiB( -1 )
, m_requiredRamGiB( -1 )
{
}
@ -72,12 +72,12 @@ Calamares::RequirementsList GeneralRequirements::checkRequirements()
bool isRoot = false;
bool enoughScreen = (availableSize.width() >= CalamaresUtils::windowMinimumWidth) && (availableSize.height() >= CalamaresUtils::windowMinimumHeight);
qint64 requiredStorageB = CalamaresUtils::GiBtoBytes(m_requiredStorageGB);
qint64 requiredStorageB = CalamaresUtils::GiBtoBytes(m_requiredStorageGiB);
cDebug() << "Need at least storage bytes:" << requiredStorageB;
if ( m_entriesToCheck.contains( "storage" ) )
enoughStorage = checkEnoughStorage( requiredStorageB );
qint64 requiredRamB = CalamaresUtils::GiBtoBytes(m_requiredRamGB);
qint64 requiredRamB = CalamaresUtils::GiBtoBytes(m_requiredRamGiB);
cDebug() << "Need at least ram bytes:" << requiredRamB;
if ( m_entriesToCheck.contains( "ram" ) )
enoughRam = checkEnoughRam( requiredRamB );
@ -105,16 +105,16 @@ Calamares::RequirementsList GeneralRequirements::checkRequirements()
if ( entry == "storage" )
checkEntries.append( {
entry,
[req=m_requiredStorageGB]{ return tr( "has at least %1 GB available drive space" ).arg( req ); },
[req=m_requiredStorageGB]{ return tr( "There is not enough drive space. At least %1 GB is required." ).arg( req ); },
[req=m_requiredStorageGiB]{ return tr( "has at least %1 GiB available drive space" ).arg( req ); },
[req=m_requiredStorageGiB]{ return tr( "There is not enough drive space. At least %1 GiB is required." ).arg( req ); },
enoughStorage,
m_entriesToRequire.contains( entry )
} );
else if ( entry == "ram" )
checkEntries.append( {
entry,
[req=m_requiredRamGB]{ return tr( "has at least %1 GB working memory" ).arg( req ); },
[req=m_requiredRamGB]{ return tr( "The system does not have enough working memory. At least %1 GB is required." ).arg( req ); },
[req=m_requiredRamGiB]{ return tr( "has at least %1 GiB working memory" ).arg( req ); },
[req=m_requiredRamGiB]{ return tr( "The system does not have enough working memory. At least %1 GiB is required." ).arg( req ); },
enoughRam,
m_entriesToRequire.contains( entry )
} );
@ -209,19 +209,19 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap )
configurationMap.value( "requiredStorage" ).type() == QVariant::Int ) )
{
bool ok = false;
m_requiredStorageGB = configurationMap.value( "requiredStorage" ).toDouble( &ok );
m_requiredStorageGiB = configurationMap.value( "requiredStorage" ).toDouble( &ok );
if ( !ok )
{
cWarning() << "GeneralRequirements entry 'requiredStorage' is invalid.";
m_requiredStorageGB = 3.;
m_requiredStorageGiB = 3.;
}
Calamares::JobQueue::instance()->globalStorage()->insert( "requiredStorageGB", m_requiredStorageGB );
Calamares::JobQueue::instance()->globalStorage()->insert( "requiredStorageGiB", m_requiredStorageGiB );
}
else
{
cWarning() << "GeneralRequirements entry 'requiredStorage' is missing.";
m_requiredStorageGB = 3.;
m_requiredStorageGiB = 3.;
incompleteConfiguration = true;
}
@ -230,18 +230,18 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap )
configurationMap.value( "requiredRam" ).type() == QVariant::Int ) )
{
bool ok = false;
m_requiredRamGB = configurationMap.value( "requiredRam" ).toDouble( &ok );
m_requiredRamGiB = configurationMap.value( "requiredRam" ).toDouble( &ok );
if ( !ok )
{
cWarning() << "GeneralRequirements entry 'requiredRam' is invalid.";
m_requiredRamGB = 1.;
m_requiredRamGiB = 1.;
incompleteConfiguration = true;
}
}
else
{
cWarning() << "GeneralRequirements entry 'requiredRam' is missing.";
m_requiredRamGB = 1.;
m_requiredRamGiB = 1.;
incompleteConfiguration = true;
}

View File

@ -46,8 +46,8 @@ private:
bool checkHasInternet();
bool checkIsRoot();
qreal m_requiredStorageGB;
qreal m_requiredRamGB;
qreal m_requiredStorageGiB;
qreal m_requiredRamGiB;
QString m_checkHasInternetUrl;
};

View File

@ -66,7 +66,7 @@ is_cdrom(const char *path)
int fd;
fd = open(path, O_RDONLY | O_NONBLOCK);
ioctl(fd, CDIOCCAPABILITY, NULL);
ioctl(fd, CDIOCCAPABILITY, NULL);
close(fd);
if (errno != EBADF && errno != ENOTTY)
@ -120,7 +120,7 @@ check_big_enough(long long required_space)
for (dev = NULL; NULL != (dev = ped_device_get_next(dev));)
{
long long dev_size = process_device(dev);
if (dev_size > required_space)
if (dev_size >= required_space)
{
big_enough = true;
break;

View File

@ -15,12 +15,12 @@ showReleaseNotesUrl: true
# that are checked. They may not match with the actual requirements
# imposed by other modules in the system.
requirements:
# Amount of available disk, in GB. Floating-point is allowed here.
# Amount of available disk, in GiB. Floating-point is allowed here.
# Note that this does not account for *usable* disk, so it is possible
# to pass this requirement, yet have no space to install to.
requiredStorage: 5.5
# Amount of available RAM, in GB. Floating-point is allowed here.
# Amount of available RAM, in GiB. Floating-point is allowed here.
requiredRam: 1.0
# To check for internet connectivity, Calamares does a HTTP GET