FillGlobalStorageJob: Add the partition UUID to global storage

This commit is contained in:
Aurélien Gâteau 2014-07-28 14:58:06 +02:00
parent 62d706543b
commit 2d9142487b
2 changed files with 28 additions and 4 deletions

View File

@ -17,6 +17,7 @@ A list of dictionaries, one per partition. The dictionary contains the following
- `device`: path to the partition device
- `fs`: the name of the file system
- `mountPoint`: where the device should be mounted
- `uuid`: the UUID of the partition device
## rootMountPoint

View File

@ -29,15 +29,37 @@
#include <core/partition.h>
#include <fs/filesystem.h>
// Qt
#include <QDebug>
#include <QDir>
#include <QFileInfo>
typedef QHash<QString, QString> UuidForPartitionHash;
static const char* UUID_DIR = "/dev/disk/by-uuid";
static UuidForPartitionHash
findPartitionUuids()
{
QDir dir( UUID_DIR );
UuidForPartitionHash hash;
for ( auto info : dir.entryInfoList( QDir::Files ) )
{
QString uuid = info.fileName();
QString path = info.canonicalFilePath();
hash.insert( path, uuid );
}
return hash;
}
static QVariant
mapForPartition( Partition* partition )
mapForPartition( Partition* partition, const QString& uuid )
{
QVariantMap map;
map[ "device" ] = partition->partitionPath();
map[ "mountPoint" ] = PartitionInfo::mountPoint( partition );
map[ "fs" ] = partition->fileSystem().name();
map[ "uuid" ] = uuid;
return map;
}
@ -68,10 +90,11 @@ FillGlobalStorageJob::exec()
QVariant
FillGlobalStorageJob::createPartitionList()
{
UuidForPartitionHash hash = findPartitionUuids();
QVariantList lst;
for ( auto device : m_devices )
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
lst << mapForPartition( *it );
lst << mapForPartition( *it, hash.value( ( *it )->partitionPath() ) );
return lst;
}