> Damn, this is a tricky one.
> How about a hacky solution: the file watch service does not update the
> config but writes a log of moved and watched folders.
> This log can be read by strigi after or before updating the index and
> then it can update its config itself without triggering a re-index.
>
>
I was thinking somewhat the same thing except that I've added variable
"restart" to the nepomukstrigiconfig.
The patch works perfectly apart from one thing. In the
IndexWriter::slotConfigChanged, I need to set the "restart" variable in the
strigiconfig to true, if it is false. How do I do that without triggering
the slotConfigChaged function ? I tried disconnected the slot and then later
reconnecting it, but it didn't work! :-(
I've modified the patch that if a folder who's parent is being watch is
moved to a non-indexed location. It gets added to the indexed folders list.
A slight problem that arises (which we can do nothing about unless inotify
improves) is if the folder is moved to a non-watched location. Then the
EvenMoveTo event doesn't occur, and we can't update its location in the
strigi config or update its metadata.
Is what I'm doing with the Regex obvious in
FileWatch::handleStrigiIndexedFolder or should I add comments to explain?
- Vishesh Handa
Index: strigi/indexscheduler.cpp
===================================================================
--- strigi/indexscheduler.cpp (revision 1122801)
+++ strigi/indexscheduler.cpp (working copy)
@@ -36,6 +36,7 @@
#include <KDebug>
#include <KTemporaryFile>
#include <KUrl>
+#include <KConfigGroup>
#include <Nepomuk/Resource>
#include <Nepomuk/ResourceManager>
@@ -254,6 +255,7 @@ void Nepomuk::IndexScheduler::run()
// initialization
queueAllFoldersForUpdate();
+ kDebug() << "Running and calling the dreaded function";
removeOldAndUnwantedEntries();
Strigi::StreamAnalyzer analyzer( *m_analyzerConfig );
@@ -489,9 +491,35 @@ void Nepomuk::IndexScheduler::queueAllFo
void Nepomuk::IndexScheduler::slotConfigChanged()
{
+ if ( isRunning() ) {
+ KConfig config("nepomukstrigirc");
+ bool shouldRestart = config.group( "General" ).readEntry("restart", true);
+ kDebug() << "Should Restart : " << shouldRestart;
+
+ if( shouldRestart ) {
// restart to make sure we update all folders and removeOldAndUnwantedEntries
- if ( isRunning() )
restart();
+ }
+ else {
+ // The metadata mover updated the strigiconfig file because some folders were moved.
+ // We donot want to restart, as the filewatcher is still updating the metadata and
+ // removeOldAndUnwantedEntries would cause certain not yet updated entries to be deleted.
+
+ disconnect( StrigiServiceConfig::self(), SIGNAL( configChanged() ),
+ this, SLOT( slotConfigChanged() ) );
+
+ //Update the strigi config as we want it to restart the next time.
+ kDebug() << "Updating strigiconfig to not restart";
+ {
+ KConfig config("nepomukstrigirc");
+ config.group( "General" ).writeEntry("restart", true);
+ }
+ kDebug() << "Should have changed";
+
+ connect( StrigiServiceConfig::self(), SIGNAL( configChanged() ),
+ this, SLOT( slotConfigChanged() ) );
+ }
+ }
}
@@ -624,6 +652,7 @@ namespace {
void Nepomuk::IndexScheduler::removeOldAndUnwantedEntries()
{
+ kDebug() << Nepomuk::StrigiServiceConfig::self()->includeFolders();
//
// We now query all indexed files that are in folders that should not
// be indexed at once.
Index: strigi/strigiservice.cpp
===================================================================
--- strigi/strigiservice.cpp (revision 1122801)
+++ strigi/strigiservice.cpp (working copy)
@@ -135,6 +135,7 @@ void Nepomuk::StrigiService::updateWatch
"/nepomukfilewatch",
QDBusConnection::sessionBus() );
foreach( const QString& folder, StrigiServiceConfig::self()->includeFolders() ) {
+ kDebug() << "Watching Folder : " << folder;
filewatch.watchFolder( folder );
}
}
Index: filewatch/nepomukfilewatch.cpp
===================================================================
--- filewatch/nepomukfilewatch.cpp (revision 1122801)
+++ filewatch/nepomukfilewatch.cpp (working copy)
@@ -26,12 +26,15 @@
#endif
#include <QtCore/QDir>
+#include <QtCore/QRegExp>
#include <QtDBus/QDBusConnection>
#include <KDebug>
#include <KUrl>
#include <KPluginFactory>
-
+#include <KDirWatch>
+#include <KStandardDirs>
+#include <KConfigGroup>
using namespace Soprano;
@@ -78,6 +81,19 @@ Nepomuk::FileWatch::FileWatch( QObject*
#else
connectToKDirWatch();
#endif
+
+ //Tracking Strigi indexed folder list
+
+ KDirWatch* dirWatch = KDirWatch::self();
+ connect( dirWatch, SIGNAL( dirty( const QString& ) ),
+ this, SLOT( slotStrigiConfigChanged() ) );
+ connect( dirWatch, SIGNAL( created( const QString& ) ),
+ this, SLOT( slotStrigiConfigChanged() ) );
+
+ KConfig config("nepomukstrigirc");
+ dirWatch->addFile( KStandardDirs::locateLocal( "config", config.name() ) );
+
+ slotStrigiConfigChanged();
}
@@ -108,6 +124,8 @@ void Nepomuk::FileWatch::slotFileMoved(
kDebug() << from << to;
m_metadataMover->moveFileMetadata( from, to );
+
+ handleStrigiIndexedFolder( urlFrom, urlTo );
}
@@ -159,4 +177,85 @@ void Nepomuk::FileWatch::slotInotifyWatc
}
#endif
+
+void Nepomuk::FileWatch::slotStrigiConfigChanged()
+{
+ kDebug();
+
+ m_strigiFoldersHash.clear();
+ KConfig config("nepomukstrigirc");
+
+ QStringList include = config.group( "General" ).readPathEntry( "folders", QStringList());
+ foreach( QString path, include ) {
+ m_strigiFoldersHash.insert( path, true );
+ }
+
+ QStringList exclude = config.group( "General" ).readPathEntry( "exclude folders", QStringList());
+ foreach( QString path, exclude ) {
+ m_strigiFoldersHash.insert( path, false );
+ }
+}
+
+
+namespace {
+ bool isParentPresent( const QHash<QString, bool> & hash, QDir dir )
+ {
+ bool cd = dir.cdUp();
+ if ( !cd )
+ return false;
+
+ if( hash.contains( dir.absolutePath() ) )
+ return true;
+
+ return isParentPresent( hash, dir );
+ }
+
+ bool isParentPresent( const QHash<QString, bool> & hash, QString path )
+ {
+ return isParentPresent( hash, QDir(path) );
+ }
+}
+
+
+void Nepomuk::FileWatch::handleStrigiIndexedFolder( const QString& urlFrom, const QString& urlTo )
+{
+ bool subFolder = false;
+
+ if( !m_strigiFoldersHash.contains( urlFrom ) ) {
+ if( isParentPresent( m_strigiFoldersHash, urlFrom ) ) {
+ subFolder = true;
+ }
+ else
+ return;
+ }
+
+ KConfig config("nepomukstrigirc");
+
+
+ QRegExp regex( urlFrom + "(/.*)?$" );
+
+ QStringList includeFolders = config.group( "General" ).readPathEntry( "folders", QStringList());
+ includeFolders.replaceInStrings( regex, urlTo + "\\1" );
+
+ QStringList excludeFolders = config.group( "General" ).readPathEntry( "exclude folders", QStringList());
+ excludeFolders.replaceInStrings( regex, urlTo + "\\1" );
+
+ if( subFolder )
+ includeFolders << urlTo;
+
+ //Optimize include folders
+ QMutableStringListIterator it( includeFolders );
+ while( it.hasNext() ) {
+ QString value = it.next();
+ if( isParentPresent( m_strigiFoldersHash, value ) )
+ it.remove();
+ }
+
+ config.group( "General" ).writePathEntry( "folders", includeFolders );
+ config.group( "General" ).writePathEntry( "exclude folders", excludeFolders );
+ config.group( "General" ).writeEntry( "restart", false );
+ return;
+
+}
+
#include "nepomukfilewatch.moc"
Index: filewatch/nepomukfilewatch.h
===================================================================
--- filewatch/nepomukfilewatch.h (revision 1122801)
+++ filewatch/nepomukfilewatch.h (working copy)
@@ -23,6 +23,7 @@
#include <QtCore/QUrl>
#include <QtCore/QVariant>
+#include <QtCore/QHash>
namespace Soprano {
class Model;
@@ -60,9 +61,12 @@ namespace Nepomuk {
#ifdef BUILD_KINOTIFY
void slotInotifyWatchUserLimitReached();
#endif
+ void slotStrigiConfigChanged();
private:
MetadataMover* m_metadataMover;
+ QHash<QString, bool> m_strigiFoldersHash;
+ void handleStrigiIndexedFolder( const QString& from, const QString& to );
#ifdef BUILD_KINOTIFY
KInotify* m_dirWatch;
_______________________________________________
Nepomuk mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/nepomuk