Skip to content

Commit

Permalink
Merge branch 'jb43009' into 'master'
Browse files Browse the repository at this point in the history
Don't duplicate already unlocked block device to the model

See merge request mer-core/nemo-qml-plugin-systemsettings!81
  • Loading branch information
rainemak committed Sep 25, 2018
2 parents e33b213 + 526b35b commit ec94f5b
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/udisks2monitor.cpp
Expand Up @@ -222,7 +222,8 @@ void UDisks2::Monitor::format(const QString &devicePath, const QString &type, co
void UDisks2::Monitor::interfacesAdded(const QDBusObjectPath &objectPath, const UDisks2::InterfacePropertyMap &interfaces)
{
QString path = objectPath.path();
qCInfo(lcMemoryCardLog) << "UDisks interface added:" << path << interfaces << externalBlockDevice(path);
qCDebug(lcMemoryCardLog) << "UDisks interface added:" << path << externalBlockDevice(path);
qCInfo(lcMemoryCardLog) << "UDisks dump interface:" << interfaces;
// External device must have file system or partition so that it can added to the model.
// Devices without partition table have filesystem interface.

Expand Down Expand Up @@ -264,7 +265,8 @@ void UDisks2::Monitor::interfacesAdded(const QDBusObjectPath &objectPath, const
void UDisks2::Monitor::interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces)
{
QString path = objectPath.path();
qCInfo(lcMemoryCardLog) << "UDisks interface removed:" << path << interfaces;
qCDebug(lcMemoryCardLog) << "UDisks interface removed:" << path;
qCInfo(lcMemoryCardLog) << "UDisks dump interface:" << interfaces;

if (m_jobsToWait.contains(path)) {
UDisks2::Job *job = m_jobsToWait.take(path);
Expand Down Expand Up @@ -300,7 +302,7 @@ void UDisks2::Monitor::setPartitionProperties(QExplicitlySharedDataPointer<Parti
label = blockDevice->idUUID();
}

qCInfo(lcMemoryCardLog) << "Set partition properties";
qCDebug(lcMemoryCardLog) << "Set partition properties";
blockDevice->dumpInfo();

partition->devicePath = blockDevice->device();
Expand Down Expand Up @@ -581,9 +583,7 @@ void UDisks2::Monitor::createPartition(const UDisks2::Block *block)
QExplicitlySharedDataPointer<PartitionPrivate> partition(new PartitionPrivate(m_manager.data()));
partition->storageType = Partition::External;
partition->devicePath = block->device();

partition->bytesTotal = block->size();

setPartitionProperties(partition, block);
partition->valid = true;
PartitionManagerPrivate::Partitions addedPartitions = { partition };
Expand All @@ -603,28 +603,40 @@ void UDisks2::Monitor::createBlockDevice(const QString &dbusObjectPath, const UD

// Upon creation.
connect(block, &UDisks2::Block::completed, this, [this]() {
UDisks2::Block *block = qobject_cast<UDisks2::Block *>(sender());
if (block->isExternal() && (block->isMountable() || block->isEncrypted())) {
const QString cryptoBackingDeviceObjectPath = block->cryptoBackingDeviceObjectPath();
if (block->hasCryptoBackingDevice() && m_blockDevices.contains(cryptoBackingDeviceObjectPath)) {
UDisks2::Block *completedBlock = qobject_cast<UDisks2::Block *>(sender());
bool unlocked = false;

// Check if device is already unlocked.
if (completedBlock->isEncrypted()) {
for (const Block *b : m_blockDevices.values()) {
if (b->cryptoBackingDeviceObjectPath() == completedBlock->path()) {
unlocked = true;
break;
}
}
}

if (!unlocked && completedBlock->isExternal() && (completedBlock->isMountable() || completedBlock->isEncrypted())) {
const QString cryptoBackingDeviceObjectPath = completedBlock->cryptoBackingDeviceObjectPath();
if (completedBlock->hasCryptoBackingDevice() && m_blockDevices.contains(cryptoBackingDeviceObjectPath)) {
// Update crypto backing device to file system device.
UDisks2::Block *cryptoBackingDev = m_blockDevices.value(cryptoBackingDeviceObjectPath);
*cryptoBackingDev = *block;
*cryptoBackingDev = *completedBlock;

m_blockDevices.remove(cryptoBackingDeviceObjectPath);
m_blockDevices.insert(cryptoBackingDev->path(), cryptoBackingDev);

updatePartitionProperties(cryptoBackingDev);

block->deleteLater();
} else if (!m_blockDevices.contains(block->path())) {
m_blockDevices.insert(block->path(), block);
createPartition(block);
completedBlock->deleteLater();
} else if (!m_blockDevices.contains(completedBlock->path())) {
m_blockDevices.insert(completedBlock->path(), completedBlock);
createPartition(completedBlock);
}
} else {
// This is garbage block device that should not be exposed
// from the partition model.
block->deleteLater();
completedBlock->deleteLater();
}
});

Expand Down Expand Up @@ -661,7 +673,7 @@ void UDisks2::Monitor::createBlockDevice(const QString &dbusObjectPath, const UD
QVariantMap data;
data.insert(UDISKS2_JOB_KEY_OPERATION, block->mountPath().isEmpty() ? UDISKS2_JOB_OP_FS_UNMOUNT : UDISKS2_JOB_OP_FS_MOUNT);
data.insert(UDISKS2_JOB_KEY_OBJECTS, QStringList() << block->path());
qCInfo(lcMemoryCardLog) << "New partition status:" << data;
qCDebug(lcMemoryCardLog) << "New partition status:" << data;
UDisks2::Job tmpJob(QString(), data);
tmpJob.complete(true);
updatePartitionStatus(&tmpJob, true);
Expand Down

0 comments on commit ec94f5b

Please sign in to comment.