Partitions: drop devices with mounted partitions.

FIXES #639
This commit is contained in:
Adriaan de Groot 2017-07-11 05:37:50 -04:00 committed by Philip
parent 1919c2a712
commit 1b98974f07

View File

@ -55,6 +55,10 @@
#include <QFutureWatcher>
#include <QtConcurrent/QtConcurrent>
/**
* Does the given @p device contain the root filesystem? This is true if
* the device contains a partition which is currently mounted at / .
*/
static bool
hasRootPartition( Device* device )
{
@ -64,6 +68,19 @@ hasRootPartition( Device* device )
return false;
}
static bool
isMounted( Device* device )
{
cDebug() << "Checking for mounted partitions in" << device->deviceNode();
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
{
cDebug() << " .." << ( *it )->partitionPath() << "mount" << ( *it )->mountPoint();
if ( ! ( *it )->mountPoint().isEmpty() )
return true;
}
return false;
}
static bool
isIso9660( const Device* device )
{
@ -162,9 +179,12 @@ PartitionCoreModule::doInit()
// Remove the device which contains / from the list
for ( DeviceList::iterator it = devices.begin(); it != devices.end(); )
if ( ! ( *it ) || hasRootPartition( *it ) ||
( *it )->deviceNode().startsWith( "/dev/zram" ) ||
isIso9660( *it ) )
if ( ! ( *it ) ||
hasRootPartition( *it ) ||
isIso9660( *it ) ||
isMounted( *it ) ||
( *it )->deviceNode().startsWith( "/dev/zram" )
)
{
cDebug() << " .. Winnowing" << ( ( *it ) ? ( *it )->deviceNode() : QString( "<null device>" ) );
it = devices.erase( it );