Commit ec94f5bf authored by Raine Makelainen's avatar Raine Makelainen

Merge branch 'jb43009' into 'master'

Don't duplicate already unlocked block device to the model

See merge request mer-core/nemo-qml-plugin-systemsettings!81
parents e33b2136 526b35b6
......@@ -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.
......@@ -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);
......@@ -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();
......@@ -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 };
......@@ -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();
}
});
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment