summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVishesh Handa <me@vhanda.in>2012-08-08 15:38:30 (GMT)
committerVishesh Handa <me@vhanda.in>2012-08-13 15:20:47 (GMT)
commit24caa3821aed71e590a3e55a76c6e4bc08f7d9d5 (patch)
tree60565550b465afc8146463dbd1a7bdffb8098f79
parent7b428f2e54cce2b33886a7d39f7fa9bfe61db630 (diff)
FileWatch: Remove watches for removeable media before unmounting
Added 2 signals in RemovableMediaCache * deviceRemoved * deviceTeardownRequested When the device is about to be unmounted all the watches are removed so that it can be unmounted sucessfully. BUG: 304943 FIXED-IN: 4.9.1 REIVEW: 106002
-rw-r--r--common/removablemediacache.cpp30
-rw-r--r--common/removablemediacache.h3
-rw-r--r--services/filewatch/nepomukfilewatch.cpp10
-rw-r--r--services/filewatch/nepomukfilewatch.h6
4 files changed, 42 insertions, 7 deletions
diff --git a/common/removablemediacache.cpp b/common/removablemediacache.cpp
index 637c076..fcdec07 100644
--- a/common/removablemediacache.cpp
+++ b/common/removablemediacache.cpp
@@ -116,8 +116,11 @@ Nepomuk2::RemovableMediaCache::Entry* Nepomuk2::RemovableMediaCache::createCache
// we only add to this set and never remove. This is no problem as this is a small set
m_usedSchemas.insert(KUrl(entry.url()).scheme());
- connect( dev.as<Solid::StorageAccess>(), SIGNAL(accessibilityChanged(bool, QString)),
+ const Solid::StorageAccess* storage = dev.as<Solid::StorageAccess>();
+ connect( storage, SIGNAL(accessibilityChanged(bool, QString)),
this, SLOT(slotAccessibilityChanged(bool, QString)) );
+ connect( storage, SIGNAL(teardownRequested(QString)),
+ this, SLOT(slotTeardownRequested(QString)) );
QHash<QString, Entry>::iterator it = m_metadataCache.insert( dev.udi(), entry );
@@ -201,9 +204,11 @@ void Nepomuk2::RemovableMediaCache::slotSolidDeviceAdded( const QString& udi )
void Nepomuk2::RemovableMediaCache::slotSolidDeviceRemoved( const QString& udi )
{
kDebug() << udi;
- if ( m_metadataCache.contains( udi ) ) {
+ QHash< QString, Entry >::iterator it = m_metadataCache.find( udi );
+ if( it != m_metadataCache.end() ) {
kDebug() << "Found removable storage volume for Nepomuk undocking:" << udi;
- m_metadataCache.remove( udi );
+ emit deviceRemoved( &it.value() );
+ m_metadataCache.erase( it );
}
}
@@ -215,14 +220,27 @@ void Nepomuk2::RemovableMediaCache::slotAccessibilityChanged( bool accessible, c
//
// cache new mount path
//
+ QMutexLocker lock(&m_entryCacheMutex);
+ Entry* entry = &m_metadataCache[udi];
+ Q_ASSERT( entry != 0 );
+
if ( accessible ) {
- QMutexLocker lock(&m_entryCacheMutex);
- Entry* entry = &m_metadataCache[udi];
- kDebug() << udi << "accessible at" << entry->device().as<Solid::StorageAccess>()->filePath() << "with identifier" << entry->url();
+ kDebug() << udi << "accessible at" << entry->device().as<Solid::StorageAccess>()->filePath()
+ << "with identifier" << entry->url();
emit deviceMounted(entry);
}
}
+void Nepomuk2::RemovableMediaCache::slotTeardownRequested(const QString& udi)
+{
+ QMutexLocker lock(&m_entryCacheMutex);
+ Entry* entry = &m_metadataCache[udi];
+ Q_ASSERT( entry != 0 );
+
+ emit deviceTeardownRequested(entry);
+}
+
+
Nepomuk2::RemovableMediaCache::Entry::Entry()
{
diff --git a/common/removablemediacache.h b/common/removablemediacache.h
index d11a38c..ed11f7d 100644
--- a/common/removablemediacache.h
+++ b/common/removablemediacache.h
@@ -99,12 +99,15 @@ public:
signals:
void deviceAdded(const Nepomuk2::RemovableMediaCache::Entry* entry);
+ void deviceRemoved(const Nepomuk2::RemovableMediaCache::Entry* entry);
void deviceMounted(const Nepomuk2::RemovableMediaCache::Entry* entry);
+ void deviceTeardownRequested(const Nepomuk2::RemovableMediaCache::Entry* entry);
private slots:
void slotSolidDeviceAdded(const QString &udi);
void slotSolidDeviceRemoved(const QString &udi);
void slotAccessibilityChanged(bool accessible, const QString &udi);
+ void slotTeardownRequested(const QString& udi);
private:
void initCacheEntries();
diff --git a/services/filewatch/nepomukfilewatch.cpp b/services/filewatch/nepomukfilewatch.cpp
index f5c51c4..b021eef 100644
--- a/services/filewatch/nepomukfilewatch.cpp
+++ b/services/filewatch/nepomukfilewatch.cpp
@@ -174,10 +174,12 @@ Nepomuk2::FileWatch::FileWatch( QObject* parent, const QList<QVariant>& )
m_removableMediaCache = new RemovableMediaCache(this);
connect(m_removableMediaCache, SIGNAL(deviceMounted(const Nepomuk2::RemovableMediaCache::Entry*)),
this, SLOT(slotDeviceMounted(const Nepomuk2::RemovableMediaCache::Entry*)));
+ connect(m_removableMediaCache, SIGNAL(deviceTeardownRequested(const Nepomuk2::RemovableMediaCache::Entry*)),
+ this, SLOT(slotDeviceTeardownRequested(const Nepomuk2::RemovableMediaCache::Entry*)));
addWatchesForMountedRemovableMedia();
(new InvalidFileResourceCleaner(this))->start();
-
+
connect( FileIndexerConfig::self(), SIGNAL( configChanged() ),
this, SLOT( updateIndexedFoldersWatches() ) );
}
@@ -407,6 +409,12 @@ void Nepomuk2::FileWatch::slotDeviceMounted(const Nepomuk2::RemovableMediaCache:
watchFolder(entry->mountPath());
}
+void Nepomuk2::FileWatch::slotDeviceTeardownRequested(const Nepomuk2::RemovableMediaCache::Entry* entry )
+{
+ m_dirWatch->removeWatch( entry->mountPath() );
+}
+
+
void Nepomuk2::FileWatch::slotActiveFileQueueTimeout(const KUrl &url)
{
updateFileViaFileIndexer(url.toLocalFile());
diff --git a/services/filewatch/nepomukfilewatch.h b/services/filewatch/nepomukfilewatch.h
index 92daa5f..c076601 100644
--- a/services/filewatch/nepomukfilewatch.h
+++ b/services/filewatch/nepomukfilewatch.h
@@ -93,6 +93,12 @@ namespace Nepomuk2 {
*/
void slotDeviceMounted( const Nepomuk2::RemovableMediaCache::Entry* );
+ /**
+ * Connected to each removable media.
+ * Removes all the watches that were added for that removable media
+ */
+ void slotDeviceTeardownRequested( const Nepomuk2::RemovableMediaCache::Entry* );
+
void slotActiveFileQueueTimeout(const KUrl& url);
private: