diff --git a/src/modules/partition/jobs/ClearMountsJob.cpp b/src/modules/partition/jobs/ClearMountsJob.cpp index 4e156945b..b116ce1b4 100644 --- a/src/modules/partition/jobs/ClearMountsJob.cpp +++ b/src/modules/partition/jobs/ClearMountsJob.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -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; +} diff --git a/src/modules/partition/jobs/ClearMountsJob.h b/src/modules/partition/jobs/ClearMountsJob.h index 464793f27..d4f639ffc 100644 --- a/src/modules/partition/jobs/ClearMountsJob.h +++ b/src/modules/partition/jobs/ClearMountsJob.h @@ -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; };