[partition] Make internal methods static

This commit is contained in:
Adriaan de Groot 2021-11-01 20:28:47 +01:00
parent 105517fed7
commit 0c84a87c67
2 changed files with 59 additions and 65 deletions

View File

@ -72,7 +72,7 @@ getPartitionsForDevice( const QString& deviceName )
return partitions; return partitions;
} }
STATICTEST static QStringList STATICTEST QStringList
getSwapsForDevice( const QString& deviceName ) getSwapsForDevice( const QString& deviceName )
{ {
QProcess process; QProcess process;
@ -103,6 +103,64 @@ getSwapsForDevice( const QString& deviceName )
return swapPartitions; return swapPartitions;
} }
STATICTEST QString
tryUmount( const QString& partPath )
{
QProcess process;
process.start( "umount", { partPath } );
process.waitForFinished();
if ( process.exitCode() == 0 )
{
return QString( "Successfully unmounted %1." ).arg( partPath );
}
process.start( "swapoff", { partPath } );
process.waitForFinished();
if ( process.exitCode() == 0 )
{
return QString( "Successfully disabled swap %1." ).arg( partPath );
}
return QString();
}
STATICTEST QString
tryClearSwap( const QString& partPath )
{
QProcess process;
process.start( "blkid", { "-s", "UUID", "-o", "value", partPath } );
process.waitForFinished();
QString swapPartUuid = QString::fromLocal8Bit( process.readAllStandardOutput() ).simplified();
if ( process.exitCode() != 0 || swapPartUuid.isEmpty() )
{
return QString();
}
process.start( "mkswap", { "-U", swapPartUuid, partPath } );
process.waitForFinished();
if ( process.exitCode() != 0 )
{
return QString();
}
return QString( "Successfully cleared swap %1." ).arg( partPath );
}
STATICTEST QString
tryCryptoClose( const QString& mapperPath )
{
QProcess process;
process.start( "cryptsetup", { "close", mapperPath } );
process.waitForFinished();
if ( process.exitCode() == 0 )
{
return QString( "Successfully closed mapper device %1." ).arg( mapperPath );
}
return QString();
}
ClearMountsJob::ClearMountsJob( Device* device ) ClearMountsJob::ClearMountsJob( Device* device )
: Calamares::Job() : Calamares::Job()
@ -248,67 +306,6 @@ ClearMountsJob::exec()
return ok; return ok;
} }
QString
ClearMountsJob::tryUmount( const QString& partPath )
{
QProcess process;
process.start( "umount", { partPath } );
process.waitForFinished();
if ( process.exitCode() == 0 )
{
return QString( "Successfully unmounted %1." ).arg( partPath );
}
process.start( "swapoff", { partPath } );
process.waitForFinished();
if ( process.exitCode() == 0 )
{
return QString( "Successfully disabled swap %1." ).arg( partPath );
}
return QString();
}
QString
ClearMountsJob::tryClearSwap( const QString& partPath )
{
QProcess process;
process.start( "blkid", { "-s", "UUID", "-o", "value", partPath } );
process.waitForFinished();
QString swapPartUuid = QString::fromLocal8Bit( process.readAllStandardOutput() ).simplified();
if ( process.exitCode() != 0 || swapPartUuid.isEmpty() )
{
return QString();
}
process.start( "mkswap", { "-U", swapPartUuid, partPath } );
process.waitForFinished();
if ( process.exitCode() != 0 )
{
return QString();
}
return QString( "Successfully cleared swap %1." ).arg( partPath );
}
QString
ClearMountsJob::tryCryptoClose( const QString& mapperPath )
{
QProcess process;
process.start( "cryptsetup", { "close", mapperPath } );
process.waitForFinished();
if ( process.exitCode() == 0 )
{
return QString( "Successfully closed mapper device %1." ).arg( mapperPath );
}
return QString();
}
QStringList QStringList
ClearMountsJob::getCryptoDevices() const ClearMountsJob::getCryptoDevices() const
{ {

View File

@ -28,9 +28,6 @@ public:
Calamares::JobResult exec() override; Calamares::JobResult exec() override;
private: private:
QString tryUmount( const QString& partPath );
QString tryClearSwap( const QString& partPath );
QString tryCryptoClose( const QString& mapperPath );
QStringList getCryptoDevices() const; QStringList getCryptoDevices() const;
Device* m_device; Device* m_device;
}; };