diff --git a/CHANGES b/CHANGES index 5fdba303f..9f72f515c 100644 --- a/CHANGES +++ b/CHANGES @@ -17,10 +17,14 @@ This release contains contributions from (alphabetically by first name): - A crash when no *finished* page (or rather, no page at all) is configured after the last *exec* section of the sequence has been solved. The *finished* page can be left out (but then you don't get - the restart-now functionality). + the restart-now functionality). #1168 ## Modules ## + - *partition* Now has its own setting for *requiredStorage*, duplicating + the same setting in the *welcome* module. This is useful for + configurations where no *welcome* module is used, but a minimum + size must be checked anyway. #1169 # 3.2.9 (2019-06-03) # diff --git a/data/config-appimage/modules/welcome.conf b/data/config-appimage/modules/welcome.conf index 8dae3e957..0cfb59546 100644 --- a/data/config-appimage/modules/welcome.conf +++ b/data/config-appimage/modules/welcome.conf @@ -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 diff --git a/src/libcalamares/utils/Units.h b/src/libcalamares/utils/Units.h index e6d46aaed..8fb34c3e0 100644 --- a/src/libcalamares/utils/Units.h +++ b/src/libcalamares/utils/Units.h @@ -78,6 +78,11 @@ constexpr int BytesToMiB( qint64 b ) return int( b / 1024 / 1024 ); } +constexpr int BytesToGiB( qint64 b ) +{ + return int( b / 1024 / 1024 / 1024 ); +} + constexpr qint64 alignBytesToBlockSize( qint64 bytes, qint64 blocksize ) { qint64 blocks = bytes / blocksize; diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index 7b44d3d64..562474865 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -62,37 +62,55 @@ convenienceName( const Partition* const candidate ) return p; } +/** @brief Get the globalStorage setting for required space. */ +static double +getRequiredStorageGiB( bool& ok ) +{ + return Calamares::JobQueue::instance()->globalStorage()->value( "requiredStorageGiB" ).toDouble( &ok ); +} + bool canBeReplaced( Partition* candidate ) { if ( !candidate ) + { + cDebug() << "Partition* is NULL"; return false; + } + cDebug() << "Checking if" << convenienceName( candidate ) << "can be replaced."; if ( candidate->isMounted() ) + { + cDebug() << Logger::SubEntry << "NO, it is mounted."; return false; + } bool ok = false; - double requiredStorageGB = Calamares::JobQueue::instance() - ->globalStorage() - ->value( "requiredStorageGiB" ) - .toDouble( &ok ); + double requiredStorageGiB = getRequiredStorageGiB( ok ); + if ( !ok ) + { + cDebug() << Logger::SubEntry << "NO, requiredStorageGiB is not set correctly."; + return false; + } qint64 availableStorageB = candidate->capacity(); - qint64 requiredStorageB = ( requiredStorageGB + 0.5 ) * 1024 * 1024 * 1024; - cDebug() << "Required storage B:" << requiredStorageB - << QString( "(%1GB)" ).arg( requiredStorageB / 1024 / 1024 / 1024 ); - cDebug() << "Storage capacity B:" << availableStorageB - << QString( "(%1GB)" ).arg( availableStorageB / 1024 / 1024 / 1024 ) - << "for" << convenienceName( candidate ) << " length:" << candidate->length(); + qint64 requiredStorageB = CalamaresUtils::GiBtoBytes( requiredStorageGiB + 0.5 ); - if ( ok && - availableStorageB > requiredStorageB ) + if ( availableStorageB > requiredStorageB ) { cDebug() << "Partition" << convenienceName( candidate ) << "authorized for replace install."; - return true; } - return false; + else + { + Logger::CDebug deb; + deb << Logger::SubEntry << "NO, insufficient storage"; + deb << Logger::Continuation << "Required storage B:" << requiredStorageB + << QString( "(%1GiB)" ).arg( requiredStorageGiB ); + deb << Logger::Continuation << "Available storage B:" << availableStorageB + << QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) ); + return false; + } } @@ -144,40 +162,35 @@ canBeResized( Partition* candidate ) } bool ok = false; - double requiredStorageGB = Calamares::JobQueue::instance() - ->globalStorage() - ->value( "requiredStorageGiB" ) - .toDouble( &ok ); + double requiredStorageGiB = getRequiredStorageGiB( ok ); + if ( !ok ) + { + cDebug() << Logger::SubEntry << "NO, requiredStorageGiB is not set correctly."; + return false; + } + // We require a little more for partitioning overhead and swap file - double advisedStorageGB = requiredStorageGB + 0.5 + 2.0; + double advisedStorageGiB = requiredStorageGiB + 0.5 + 2.0; qint64 availableStorageB = candidate->available(); + qint64 advisedStorageB = CalamaresUtils::GiBtoBytes( advisedStorageGiB ); - qint64 advisedStorageB = CalamaresUtils::GiBtoBytes( advisedStorageGB ); - - if ( ok && - availableStorageB > advisedStorageB ) + if ( availableStorageB > advisedStorageB ) { cDebug() << "Partition" << convenienceName( candidate ) << "authorized for resize + autopartition install."; - return true; } - else if ( ok ) + else { Logger::CDebug deb; deb << Logger::SubEntry << "NO, insufficient storage"; deb << Logger::Continuation << "Required storage B:" << advisedStorageB - << QString( "(%1GB)" ).arg( advisedStorageGB ); + << QString( "(%1GiB)" ).arg( advisedStorageGiB ); deb << Logger::Continuation << "Available storage B:" << availableStorageB - << QString( "(%1GB)" ).arg( availableStorageB / 1024 / 1024 / 1024 ) + << QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) ) << "for" << convenienceName( candidate ) << "length:" << candidate->length() << "sectorsUsed:" << candidate->sectorsUsed() << "fsType:" << candidate->fileSystem().name(); return false; } - else - { - cDebug() << Logger::SubEntry << "NO, requiredStorageGB is not set correctly."; - return false; - } } diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 58fa17674..8a190b68a 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -69,6 +69,7 @@ PartitionViewStep::PartitionViewStep( QObject* parent ) , m_widget( new QStackedWidget() ) , m_choicePage( nullptr ) , m_manualPartitionPage( nullptr ) + , m_requiredStorageGiB( 0.0 ) { m_widget->setContentsMargins( 0, 0, 0, 0 ); @@ -371,6 +372,14 @@ PartitionViewStep::isAtEnd() const void PartitionViewStep::onActivate() { + // If there's no setting (e.g. from the welcome page) for required storage + // then use ours, if it was set. + auto* gs = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; + if ( m_requiredStorageGiB >= 0.0 && gs && !gs->contains( "requiredStorageGiB" ) ) + { + gs->insert( "requiredStorageGiB", m_requiredStorageGiB ); + } + // if we're coming back to PVS from the next VS if ( m_widget->currentWidget() == m_choicePage && m_choicePage->currentChoice() == ChoicePage::Alongside ) @@ -564,6 +573,9 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) m_swapChoices = choices; + // Settings that overlap with the Welcome module + m_requiredStorageGiB = CalamaresUtils::getDouble( configurationMap, "requiredStorage", -1.0 ); + // These gs settings seem to be unused (in upstream Calamares) outside of // the partition module itself. gs->insert( "ensureSuspendToDisk", ensureSuspendToDisk ); diff --git a/src/modules/partition/gui/PartitionViewStep.h b/src/modules/partition/gui/PartitionViewStep.h index e3d058e67..0a62b3aa3 100644 --- a/src/modules/partition/gui/PartitionViewStep.h +++ b/src/modules/partition/gui/PartitionViewStep.h @@ -86,6 +86,8 @@ private: QFutureWatcher* m_future; QSet< PartitionActions::Choices::SwapChoice > m_swapChoices; + + qreal m_requiredStorageGiB; // May duplicate setting in the welcome module }; CALAMARES_PLUGIN_FACTORY_DECLARATION( PartitionViewStepFactory ) diff --git a/src/modules/partition/partition.conf b/src/modules/partition/partition.conf index 42d1f2ce2..385269fc7 100644 --- a/src/modules/partition/partition.conf +++ b/src/modules/partition/partition.conf @@ -120,3 +120,15 @@ defaultFileSystemType: "ext4" # % of the available drive space if a '%' is appended to the value # - minSize: minimum partition size (optional parameter) # - maxSize: maximum partition size (optional parameter) + +# Checking for available storage +# +# This overlaps with the setting of the same name in the welcome module's +# requirements section. If nothing is set by the welcome module, this +# value is used instead. It is still a problem if there is no required +# size set at all, and the replace and resize options will not be offered +# if no required size is set. +# +# The value is in Gibibytes (GiB). +# +# requiredStorage: 3.5