From f2438a5bf458d85d47df1857773be4c31bdebbbe Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 24 Jun 2019 13:07:19 +0200 Subject: [PATCH] [partition] Implement other way of getting partitions - Just read /proc/partitions and process it; split into columns, add relevant bits. - This implementation supports devices named "name", which the other didn't (but that would be really weird). The tests now pass. --- .../partition/tests/ClearMountsJobTests.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/modules/partition/tests/ClearMountsJobTests.cpp b/src/modules/partition/tests/ClearMountsJobTests.cpp index 4382d09d8..c74c1f25b 100644 --- a/src/modules/partition/tests/ClearMountsJobTests.cpp +++ b/src/modules/partition/tests/ClearMountsJobTests.cpp @@ -34,6 +34,28 @@ getPartitionsForDevice_other(const QString& deviceName) { QStringList partitions; + 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 partitions; }