diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-03-23 09:56:22 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-03-23 11:48:38 +0900 |
commit | 40ef766f02ea0e099a3fad77ed7eec519e2d5ec8 (patch) | |
tree | 2691377174181d81f7451ce83543ab83a5b057fc /tdeioslave/media/mediamanager/tdehardwarebackend.cpp | |
parent | d048506bb65a3f77102f07f54c7bfc16c80e003e (diff) | |
download | tdebase-40ef766f02ea0e099a3fad77ed7eec519e2d5ec8.tar.gz tdebase-40ef766f02ea0e099a3fad77ed7eec519e2d5ec8.zip |
tdeio media: add releaseHolders parameter to lock/lockByNode dcop calls.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdeioslave/media/mediamanager/tdehardwarebackend.cpp')
-rw-r--r-- | tdeioslave/media/mediamanager/tdehardwarebackend.cpp | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp index ba99b8c0c..2a54f6b6b 100644 --- a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp +++ b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp @@ -1478,9 +1478,10 @@ TQStringVariantMap TDEBackend::unlock(const TQString &id, const TQString &passwo return result; } -TQStringVariantMap TDEBackend::lock(const TQString &id) +TQStringVariantMap TDEBackend::lock(const TQString &id, bool releaseHolders) { - kdDebug(1219) << "TDEBackend::lock for id " << id << endl; + kdDebug(1219) << "TDEBackend::lock for id " << id << ", release holders " + << releaseHolders << endl; TQStringVariantMap result; @@ -1509,6 +1510,12 @@ TQStringVariantMap TDEBackend::lock(const TQString &id) return result; } + // Release device holders if requested + if (releaseHolders) + { + releaseHolderDevices(medium->deviceNode(), false); + } + TQStringVariantMap lockResult = sdevice->lockDevice(); if (lockResult["result"].toBool() == false) { TQString qerror = i18n("<b>Unable to lock the device.</b>"); @@ -1566,6 +1573,59 @@ TQStringVariantMap TDEBackend::eject(const TQString &id) return result; } +void TDEBackend::releaseHolderDevices(const TQString &deviceNode, bool handleThis) +{ + kdDebug(1219) << "TDEBackend::releaseHolderDevices for node " << deviceNode + << ", handle this " << (handleThis ? "yes" : "no") << endl; + + const Medium *medium = m_mediaList.findByNode(deviceNode); + if (!medium) + { + return; + } + + // Scan the holding devices and unmount/lock them if possible + TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); + TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id()); + if (sdevice) + { + TQStringList holdingDeviceList = sdevice->holdingDevices(); + for (TQStringList::Iterator holdingDevIt = holdingDeviceList.begin(); holdingDevIt != holdingDeviceList.end(); ++holdingDevIt) + { + TDEGenericDevice *hwHolderDevice = hwdevices->findBySystemPath(*holdingDevIt); + if (hwHolderDevice->type() == TDEGenericDeviceType::Disk) + { + TDEStorageDevice *holderSDevice = static_cast<TDEStorageDevice*>(hwHolderDevice); + const Medium *holderMedium = m_mediaList.findByNode(holderSDevice->deviceNode()); + if (holderMedium && !holderMedium->id().isEmpty()) + { + releaseHolderDevices(holderMedium->deviceNode(), true); + } + } + } + } + + if (handleThis) + { + // Unmount if necessary + if (medium->isMountable() && medium->isMounted()) + { + unmount(medium->id()); + // Must process udev events before continuing, to make sure all + // affected devices are properly updated + tqApp->processEvents(); + } + // Lock if necessary. + if (medium->isEncrypted() && !medium->isLocked()) + { + lock(medium->id(), false); + // Must process udev events before continuing, to make sure all + // affected devices are properly updated + tqApp->processEvents(); + } + } +} + void TDEBackend::slotResult(TDEIO::Job *job) { TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); |