[partition] Use (better documented) filesystem-use API

This commit is contained in:
Adriaan de Groot 2021-02-08 15:08:45 +01:00
parent 10bec1d970
commit 559b79f920
2 changed files with 23 additions and 21 deletions

View File

@ -209,6 +209,13 @@ PartitionServiceTests::testFilesystemGS()
useFilesystemGS( &gs, "EXT4", false ); useFilesystemGS( &gs, "EXT4", false );
QVERIFY( !isFilesystemUsedGS( &gs, "EXT4" ) ); QVERIFY( !isFilesystemUsedGS( &gs, "EXT4" ) );
QCOMPARE( isFilesystemUsedGS( &gs, "EXT4" ), isFilesystemUsedGS( &gs, "ext4" ) ); QCOMPARE( isFilesystemUsedGS( &gs, "EXT4" ), isFilesystemUsedGS( &gs, "ext4" ) );
useFilesystemGS( &gs, "ext4", true );
QVERIFY( isFilesystemUsedGS( &gs, "EXT4" ) );
CalamaresUtils::Partition::clearFilesystemGS( &gs );
QVERIFY( !isFilesystemUsedGS( &gs, "ZFS" ) );
QVERIFY( !isFilesystemUsedGS( &gs, "EXT4" ) );
QVERIFY( !isFilesystemUsedGS( &gs, "ext4" ) );
} }

View File

@ -18,6 +18,7 @@
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h" #include "JobQueue.h"
#include "partition/FileSystem.h" #include "partition/FileSystem.h"
#include "partition/Global.h"
#include "partition/PartitionIterator.h" #include "partition/PartitionIterator.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@ -291,35 +292,29 @@ FillGlobalStorageJob::prettyStatusMessage() const
* .. mark as "1" if it's on the system, somewhere * .. mark as "1" if it's on the system, somewhere
* .. mark as "2" if it's one of the claimed / in-use FSses * .. mark as "2" if it's one of the claimed / in-use FSses
* *
* Stores a GS key called "filesystems_use" with this mapping. * Stores a GS key called "filesystem_use" with this mapping.
* @see CalamaresUtils::Partition::useFilesystemGS()
*/ */
static void static void
storeFSUse( Calamares::GlobalStorage* storage, const QVariantList& partitions ) storeFSUse( Calamares::GlobalStorage* storage, const QVariantList& partitions )
{ {
QMap< QString, int > fsUses; if ( storage )
{
CalamaresUtils::Partition::clearFilesystemGS( storage );
for ( const auto& p : partitions ) for ( const auto& p : partitions )
{ {
const auto pmap = p.toMap(); const auto pmap = p.toMap();
QString fs = pmap.value( "fs" ).toString(); QString fs = pmap.value( "fs" ).toString();
int thisUse = pmap.value( "claimed" ).toBool() ? 2 : 1;
if ( fs.isEmpty() ) if ( fs.isEmpty() )
{ {
continue; continue;
} }
int newUse = qMax( fsUses.value( fs ), thisUse ); // value() is 0 if not present CalamaresUtils::Partition::useFilesystemGS( storage, fs, true );
fsUses.insert( fs, newUse );
} }
QVariantMap fsUsesVariant;
for ( auto it = fsUses.cbegin(); it != fsUses.cend(); ++it )
{
fsUsesVariant.insert( it.key(), it.value() );
} }
storage->insert( "filesystems_use", fsUsesVariant );
} }
Calamares::JobResult Calamares::JobResult