Close crypto devices in ClearMountsJob.
This commit is contained in:
parent
1a8a09b0d8
commit
4c2a327d21
@ -27,6 +27,7 @@
|
||||
#include <kpmcore/core/partition.h>
|
||||
#include <kpmcore/util/report.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QProcess>
|
||||
#include <QStringList>
|
||||
|
||||
@ -99,6 +100,14 @@ ClearMountsJob::exec()
|
||||
*it = (*it).simplified().split( ' ' ).first();
|
||||
}
|
||||
|
||||
foreach ( QString mapperPath, getCryptoDevices() )
|
||||
{
|
||||
tryUmount( mapperPath );
|
||||
QString news = tryCryptoClose( mapperPath );
|
||||
if ( !news.isEmpty() )
|
||||
goodNews.append( news );
|
||||
}
|
||||
|
||||
// First we umount all LVM logical volumes we can find
|
||||
process.start( "lvscan", { "-a" } );
|
||||
process.waitForFinished();
|
||||
@ -151,6 +160,14 @@ ClearMountsJob::exec()
|
||||
else
|
||||
cDebug() << "WARNING: this system does not seem to have LVM2 tools.";
|
||||
|
||||
foreach ( QString mapperPath, getCryptoDevices() )
|
||||
{
|
||||
tryUmount( mapperPath );
|
||||
QString news = tryCryptoClose( mapperPath );
|
||||
if ( !news.isEmpty() )
|
||||
goodNews.append( news );
|
||||
}
|
||||
|
||||
foreach ( QString p, partitionsList )
|
||||
{
|
||||
QString partPath = QString( "/dev/%1" ).arg( p );
|
||||
@ -214,3 +231,33 @@ ClearMountsJob::tryClearSwap( const QString& partPath )
|
||||
|
||||
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
|
||||
ClearMountsJob::getCryptoDevices()
|
||||
{
|
||||
QDir mapperDir( "/dev/mapper" );
|
||||
QFileInfoList fiList = mapperDir.entryInfoList( QDir::Files );
|
||||
QStringList list;
|
||||
QProcess process;
|
||||
foreach ( QFileInfo fi, fiList )
|
||||
{
|
||||
if ( fi.baseName() == "control" )
|
||||
continue;
|
||||
list.append( fi.absoluteFilePath() );
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ public:
|
||||
private:
|
||||
QString tryUmount( const QString& partPath );
|
||||
QString tryClearSwap( const QString& partPath );
|
||||
QString tryCryptoClose( const QString& mapperPath );
|
||||
QStringList getCryptoDevices();
|
||||
Device* m_device;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user