diff --git a/src/modules/partition/jobs/ClearMountsJob.cpp b/src/modules/partition/jobs/ClearMountsJob.cpp index 3c06fc04d..2678a70a3 100644 --- a/src/modules/partition/jobs/ClearMountsJob.cpp +++ b/src/modules/partition/jobs/ClearMountsJob.cpp @@ -63,20 +63,31 @@ ClearMountsJob::prettyStatusMessage() const QStringList getPartitionsForDevice( const QString& deviceName ) { - QProcess process; - process.setProgram( "sh" ); - process.setArguments( { - "-c", - QString( "echo $(awk '{print $4}' /proc/partitions | sed -e '/name/d' -e '/^$/d' -e '/[1-9]/!d' | grep %1)" ) - .arg( deviceName ) - } ); - process.start(); - process.waitForFinished(); + QStringList partitions; - const QString partitions = process.readAllStandardOutput(); - const QStringList partitionsList = partitions.simplified().split( ' ' ); + QFile dev_partitions( "/proc/partitions" ); + if ( dev_partitions.open( QFile::ReadOnly ) ) + { + cDebug() << "Reading from" << dev_partitions.fileName(); + QTextStream in( &dev_partitions ); + (void) in.readLine(); // That's the header line, skip it + while ( !in.atEnd() ) + { + // The fourth column (index from 0, so index 3) is the name of the device; + // keep it if it is followed by something. + QStringList columns = in.readLine().split( ' ', QString::SkipEmptyParts ); + if ( ( columns.count() >= 4 ) && ( columns[3].startsWith( deviceName ) ) && ( columns[3] != deviceName ) ) + { + partitions.append( columns[3] ); + } + } + } + else + { + cDebug() << "Could not open" << dev_partitions.fileName(); + } - return partitionsList; + return partitions; } Calamares::JobResult diff --git a/src/modules/partition/tests/ClearMountsJobTests.cpp b/src/modules/partition/tests/ClearMountsJobTests.cpp index c74c1f25b..1f01c4638 100644 --- a/src/modules/partition/tests/ClearMountsJobTests.cpp +++ b/src/modules/partition/tests/ClearMountsJobTests.cpp @@ -32,31 +32,20 @@ getPartitionsForDevice( const QString& deviceName ); QStringList getPartitionsForDevice_other(const QString& deviceName) { - QStringList partitions; + QProcess process; + process.setProgram( "sh" ); + process.setArguments( { + "-c", + QString( "echo $(awk '{print $4}' /proc/partitions | sed -e '/name/d' -e '/^$/d' -e '/[1-9]/!d' | grep %1)" ) + .arg( deviceName ) + } ); + process.start(); + process.waitForFinished(); - QFile dev_partitions( "/proc/partitions" ); - if ( dev_partitions.open( QFile::ReadOnly ) ) - { - cDebug() << "Reading from" << dev_partitions.fileName(); - QTextStream in( &dev_partitions ); - (void) in.readLine(); // That's the header line, skip it - while ( !in.atEnd() ) - { - // The fourth column (index from 0, so index 3) is the name of the device; - // keep it if it is followed by something. - QStringList columns = in.readLine().split( ' ', QString::SkipEmptyParts ); - if ( ( columns.count() >= 4 ) && ( columns[3].startsWith( deviceName ) ) && ( columns[3] != deviceName ) ) - { - partitions.append( columns[3] ); - } - } - } - else - { - cDebug() << "Could not open" << dev_partitions.fileName(); - } + const QString partitions = process.readAllStandardOutput(); + const QStringList partitionsList = partitions.simplified().split( ' ' ); - return partitions; + return partitionsList; }