From ac34cfadea258224e4d6c881f312ec8ef4e16780 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 1 Nov 2021 20:23:49 +0100 Subject: [PATCH] [partition] Factor out finding the swap-partitions --- src/modules/partition/jobs/ClearMountsJob.cpp | 67 +++++++++++-------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/src/modules/partition/jobs/ClearMountsJob.cpp b/src/modules/partition/jobs/ClearMountsJob.cpp index ea4ed0d00..817007e1a 100644 --- a/src/modules/partition/jobs/ClearMountsJob.cpp +++ b/src/modules/partition/jobs/ClearMountsJob.cpp @@ -72,42 +72,16 @@ getPartitionsForDevice( const QString& deviceName ) return partitions; } -ClearMountsJob::ClearMountsJob( Device* device ) - : Calamares::Job() - , m_device( device ) +STATICTEST static QStringList +getSwapsForDevice( const QString& deviceName ) { -} - -QString -ClearMountsJob::prettyName() const -{ - return tr( "Clear mounts for partitioning operations on %1" ).arg( m_device->deviceNode() ); -} - - -QString -ClearMountsJob::prettyStatusMessage() const -{ - return tr( "Clearing mounts for partitioning operations on %1." ).arg( m_device->deviceNode() ); -} - -Calamares::JobResult -ClearMountsJob::exec() -{ - CalamaresUtils::Partition::Syncer s; - - QString deviceName = m_device->deviceNode().split( '/' ).last(); - - QStringList goodNews; QProcess process; - QStringList partitionsList = getPartitionsForDevice( deviceName ); - // Build a list of partitions of type 82 (Linux swap / Solaris). // We then need to clear them just in case they contain something resumable from a // previous suspend-to-disk. QStringList swapPartitions; - process.start( "sfdisk", { "-d", m_device->deviceNode() } ); + process.start( "sfdisk", { "-d", deviceName } ); process.waitForFinished(); // Sample output: // % sudo sfdisk -d /dev/sda @@ -126,6 +100,41 @@ ClearMountsJob::exec() *it = ( *it ).simplified().split( ' ' ).first(); } + return swapPartitions; +} + + +ClearMountsJob::ClearMountsJob( Device* device ) + : Calamares::Job() + , m_device( device ) +{ +} + +QString +ClearMountsJob::prettyName() const +{ + return tr( "Clear mounts for partitioning operations on %1" ).arg( m_device->deviceNode() ); +} + +QString +ClearMountsJob::prettyStatusMessage() const +{ + return tr( "Clearing mounts for partitioning operations on %1." ).arg( m_device->deviceNode() ); +} + +Calamares::JobResult +ClearMountsJob::exec() +{ + CalamaresUtils::Partition::Syncer s; + + QString deviceName = m_device->deviceNode().split( '/' ).last(); + + QStringList goodNews; + QProcess process; + + const QStringList partitionsList = getPartitionsForDevice( deviceName ); + const QStringList swapPartitions = getSwapsForDevice( m_device->deviceNode() ); + const QStringList cryptoDevices = getCryptoDevices(); for ( const QString& mapperPath : cryptoDevices ) {