summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVishesh Handa <me@vhanda.in>2012-08-03 14:01:44 (GMT)
committerVishesh Handa <me@vhanda.in>2012-08-03 15:21:42 (GMT)
commit48d909c8aa4baca11e7bc1cf4ba5a23c1474fc22 (patch)
tree7d8aad884f39531d1d2f38c0560da0387b78971d
parentc4f3c8cee274c7429dcbcc84d3626ec767d06801 (diff)
FileWatcher: Check the mtime of the file for CloseOnWrite events
Tons of applications open files in 'write' mode even though they have no intention of writing to them. When they close the file descriptor, it produces a CloseOnWrite event and the FileWatcher service would add it to the queue, and ask the fileindexer to index it. REVIEW: 105839
-rw-r--r--services/filewatch/nepomukfilewatch.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/services/filewatch/nepomukfilewatch.cpp b/services/filewatch/nepomukfilewatch.cpp
index c998dc9..f5c51c4 100644
--- a/services/filewatch/nepomukfilewatch.cpp
+++ b/services/filewatch/nepomukfilewatch.cpp
@@ -46,6 +46,7 @@
#include <Soprano/QueryResultIterator>
#include <Soprano/Node>
+using namespace Nepomuk2::Vocabulary;
NEPOMUK_EXPORT_SERVICE( Nepomuk2::FileWatch, "nepomukfilewatch")
@@ -249,12 +250,26 @@ void Nepomuk2::FileWatch::slotFileCreated( const QString& path, bool isDir )
}
}
-
void Nepomuk2::FileWatch::slotFileClosedAfterWrite( const QString& path )
{
if(FileIndexerConfig::self()->shouldBeIndexed(path)) {
- // we do not tell the file indexer right away but wait a short while in case the file is modified very often (irc logs for example)
- m_fileModificationQueue->enqueueUrl( path );
+ //
+ // Check the modification time cause loads of applications open files with the write flags
+ // and do not actually modify anything
+ //
+ QFileInfo info(path);
+ QString query = QString::fromLatin1("ask where { ?r %1 %2 ; %3 %4 . }")
+ .arg( Soprano::Node::resourceToN3(NIE::url()),
+ Soprano::Node::resourceToN3(QUrl::fromLocalFile(path)),
+ Soprano::Node::resourceToN3(NIE::lastModified()),
+ Soprano::Node::literalToN3(info.lastModified().toUTC()) );
+
+ Soprano::Model* model = ResourceManager::instance()->mainModel();
+ if( !model->executeQuery(query, Soprano::Query::QueryLanguageSparql).boolValue() ) {
+ // we do not tell the file indexer right away but wait a short while in case the
+ // file is modified very often (irc logs for example)
+ m_fileModificationQueue->enqueueUrl( path );
+ }
}
}