[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kdecore/io
From:       David Faure <faure () kde ! org>
Date:       2010-11-05 23:24:08
Message-ID: 20101105232408.D96F9AC89B () svn ! kde ! org
[Download RAW message or body]

SVN commit 1193424 by dfaure:

Fix compilation of QFileSystemWatcher backend on linux (still disabled in \
CMakeLists.txt though). Create the watcher instance on demand, rather than in the \
ctor. Factorize the useINotify/useFAM/useStat/useQFSWatch into a common method.


 M  +53 -32    kdirwatch.cpp  
 M  +2 -1      kdirwatch_p.h  


--- trunk/KDE/kdelibs/kdecore/io/kdirwatch.cpp #1193423:1193424
@@ -102,6 +102,25 @@
   }
 }
 
+#ifndef NDEBUG
+static const char* methodToString(KDirWatch::Method method)
+{
+    switch (method) {
+    case KDirWatch::FAM:
+        return "FAM";
+    case KDirWatch::INotify:
+        return "INotify";
+    case KDirWatch::DNotify:
+        return "DNotify";
+    case KDirWatch::Stat:
+        return "Stat";
+    case KDirWatch::QFSWatch:
+        return "QFSWatch";
+    default:
+        return "ERROR!";
+    }
+}
+#endif
 
 //
 // Class KDirWatchPrivate (singleton)
@@ -212,11 +231,9 @@
 #endif
 #ifdef HAVE_QFILESYSTEMWATCHER
   availableMethods << "QFileSystemWatcher";
-  fsWatcher = new KFileSystemWatcher();
-  connect(fsWatcher, SIGNAL(directoryChanged(QString)), this, \
                SLOT(fswEventReceived(QString)));
-  connect(fsWatcher, SIGNAL(fileChanged(QString)),      this, \
SLOT(fswEventReceived(QString))); +  fsWatcher = 0;
 #endif
-  kDebug(7001) << "Available methods: " << availableMethods;
+  kDebug(7001) << "Available methods: " << availableMethods << "preferred=" << \
methodToString(m_preferredMethod);  }
 
 /* This is called on app exit (K_GLOBAL_STATIC) */
@@ -676,6 +693,12 @@
     return true;
   }
 
+  kDebug(7001) << "fsWatcher->addPath" << e->path;
+  if (!fsWatcher) {
+      fsWatcher = new KFileSystemWatcher();
+      connect(fsWatcher, SIGNAL(directoryChanged(QString)), this, \
SLOT(fswEventReceived(QString))); +      connect(fsWatcher, \
SIGNAL(fileChanged(QString)),      this, SLOT(fswEventReceived(QString))); +  }
   fsWatcher->addPath( e->path );
   return true;
 }
@@ -861,6 +884,11 @@
     }
   }
 
+  addWatch(e);
+}
+
+void KDirWatchPrivate::addWatch(Entry* e)
+{
   // If the watch is on a network filesystem use the nfsPreferredMethod as the
   // default, otherwise use preferredMethod as the default, if the methods are
   // the same we can skip the mountpoint check
@@ -980,7 +1008,7 @@
 #endif
 
 #ifdef HAVE_QFILESYSTEMWATCHER
-  if (e->m_mode == QFSWatchMode) {
+  if (e->m_mode == QFSWatchMode && fsWatcher) {
     fsWatcher->removePath(e->path);
   }
 #endif
@@ -1236,9 +1264,9 @@
     }
 #endif
 
-    if ( (e->m_ctime != invalid_ctime) &&
+    if ( ((e->m_ctime != invalid_ctime) &&
           ((qMax(stat_buf.st_ctime, stat_buf.st_mtime) != e->m_ctime) ||
-          (stat_buf.st_nlink != (nlink_t) e->m_nlink))
+          (stat_buf.st_nlink != (nlink_t) e->m_nlink)))
 #if defined( HAVE_QFILESYSTEMWATCHER )
           // we trust QFSW to get it right, the ctime comparisons above
           // fail for example when adding files to directories on Windows
@@ -1395,8 +1423,9 @@
     if (s_verboseDebug)
       kDebug(7001) << "scanEntry for" << entry->path << "says" << ev;
 
+    switch(entry->m_mode) {
 #ifdef HAVE_SYS_INOTIFY_H
-    if (entry->m_mode == INotifyMode) {
+    case INotifyMode:
       if ( ev == Deleted ) {
         if (s_verboseDebug)
           kDebug(7001) << "scanEntry says" << entry->path << "was deleted";
@@ -1406,24 +1435,21 @@
           kDebug(7001) << "scanEntry says" << entry->path << "was created. wd=" << \
entry->wd;  if (entry->wd < 0) {
           cList.append(entry);
-          if (!useINotify(entry)) {
-            useStat(entry);
+          addWatch(entry);
           }
         }
-      }
-    }
+      break;
 #endif
-    if (entry->m_mode == FAMMode) {
+    case FAMMode:
+    case QFSWatchMode:
       if (ev == Created) {
-        // TODO move this into a common method
-        if (!useFAM(entry)) {
-#ifdef HAVE_SYS_INOTIFY_H
-          if (!useINotify(entry))
-#endif
-            useStat(entry);
+        addWatch(entry);
         }
+      break;
+    default:
+        // dunno about StatMode...
+        break;
       }
-    }
 
     if (entry->isDir) {
       // Report and clear the the list of files that have changed in this directory.
@@ -1487,15 +1513,12 @@
       use_fam = false;
       delete sn; sn = 0;
 
-      // Replace all FAMMode entries with DNotify/Stat
-      EntryMap::Iterator it;
-      it = m_mapEntries.begin();
+      // Replace all FAMMode entries with INotify/Stat
+      EntryMap::Iterator it = m_mapEntries.begin();
       for( ; it != m_mapEntries.end(); ++it )
         if ((*it).m_mode == FAMMode && (*it).m_clients.count()>0) {
-#ifdef HAVE_SYS_INOTIFY_H
-          if (useINotify( &(*it) )) continue;
-#endif
-          useStat( &(*it) );
+            Entry* e = &(*it);
+            addWatch(e);
         }
     }
     else
@@ -1664,6 +1687,8 @@
 // Slot for QFileSystemWatcher
 void KDirWatchPrivate::fswEventReceived(const QString &path)
 {
+  if (s_verboseDebug)
+    kDebug(7001) << path;
   EntryMap::Iterator it;
   it = m_mapEntries.find(path);
   if(it != m_mapEntries.end()) {
@@ -1696,11 +1721,7 @@
         //QByteArray tpath = QFile::encodeName(path);
         //KDE_stat(tpath, &stat_buf);
 
-        if(!useQFSWatch(sub_entry))
-#ifdef HAVE_SYS_INOTIFY_H
-          if(!useINotify(sub_entry))
-#endif
-            useStat(sub_entry);
+        addWatch(sub_entry);
         fswEventReceived(sub_entry->path);
       }
     }
--- trunk/KDE/kdelibs/kdecore/io/kdirwatch_p.h #1193423:1193424
@@ -102,7 +102,7 @@
   QHash<QString,QFileSystemWatcher*> m_paths;
 };
 #else
-typedef KFileSystemWatcher QFileSystemWatcher;
+typedef QFileSystemWatcher KFileSystemWatcher;
 #endif
 #endif
 
@@ -200,6 +200,7 @@
   void removeEntries(KDirWatch*);
   void statistics();
 
+  void addWatch(Entry* entry);
   Entry* entry(const QString&);
   int scanEntry(Entry* e);
   void emitEvent(const Entry* e, int event, const QString &fileName = QString());


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic