Merge branch 'issue-1169'

FIXES #1169
This commit is contained in:
Adriaan de Groot 2019-06-08 14:39:54 +02:00
commit 7f968e0c83
6 changed files with 80 additions and 32 deletions

View File

@ -21,6 +21,10 @@ This release contains contributions from (alphabetically by first name):
## 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) #

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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 );

View File

@ -86,6 +86,8 @@ private:
QFutureWatcher<void>* m_future;
QSet< PartitionActions::Choices::SwapChoice > m_swapChoices;
qreal m_requiredStorageGiB; // May duplicate setting in the welcome module
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( PartitionViewStepFactory )

View File

@ -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