[Pkg-owncloud-commits] [owncloud-client] 126/333: Fixed ignored paths matching on OS X.

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Apr 17 23:16:43 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 255d2552173898758793b434d34197c0afdeb96c
Author: Denis Dzyubenko <denis at ddenis.info>
Date:   Tue Feb 18 00:36:41 2014 +0100

    Fixed ignored paths matching on OS X.
    
    We now listen to changes to files and when an event is received we first match
    the file name to the "ignored paths list" and only if the the file that was
    changed didn't match figure out which directory needs to be synced.
---
 src/mirall/folderwatcher.cpp     | 41 +++++++++++++++++++++++++++++++++++-----
 src/mirall/folderwatcher.h       |  4 +++-
 src/mirall/folderwatcher_mac.cpp | 25 +++++++++++++++++++-----
 src/mirall/folderwatcher_mac.h   |  2 +-
 4 files changed, 60 insertions(+), 12 deletions(-)

diff --git a/src/mirall/folderwatcher.cpp b/src/mirall/folderwatcher.cpp
index 2db8e78..d85e677 100644
--- a/src/mirall/folderwatcher.cpp
+++ b/src/mirall/folderwatcher.cpp
@@ -109,21 +109,52 @@ bool FolderWatcher::pathIsIgnored( const QString& path )
 
 void FolderWatcher::changeDetected( const QString& path )
 {
-    qDebug() << Q_FUNC_INFO << path;
+    QStringList paths(path);
+    changeDetected(paths);
+}
+
+void FolderWatcher::changeDetected( const QStringList& paths )
+{
+    qDebug() << Q_FUNC_INFO << paths;
+
+    // TODO: this shortcut doesn't look very reliable:
+    //   - why is the timeout only 1 second?
+    //   - what if there are more than one file being updated frequently?
+    //   - why do we skip the file alltogether instead of e.g. reducing the upload frequency?
+
     // Check if the same path was reported within the last second.
-    if( path == _lastPath && _timer.elapsed() < 1000 ) {
+    QSet<QString> pathsSet = paths.toSet();
+    if( pathsSet == _lastPaths && _timer.elapsed() < 1000 ) {
         // the same path was reported within the last second. Skip.
         return;
     }
-    _lastPath = path;
+    _lastPaths = pathsSet;
     _timer.restart();
 
+    QSet<QString> changedFolders;
+
     // ------- handle ignores:
-    if( pathIsIgnored(path) ) {
+    for (int i = 0; i < paths.size(); ++i) {
+        QString path = paths[i];
+        if( pathIsIgnored(path) ) {
+            continue;
+        }
+
+        QFileInfo fi(path);
+        if (fi.isDir()) {
+            changedFolders.insert(path);
+        } else {
+            changedFolders.insert(fi.dir().path());
+        }
+    }
+    if (changedFolders.isEmpty()) {
         return;
     }
 
-    emit folderChanged(path);
+    qDebug() << "detected changes in folders:" << changedFolders;
+    foreach (const QString &path, changedFolders) {
+        emit folderChanged(path);
+    }
 }
 
 void FolderWatcher::addPath(const QString &path )
diff --git a/src/mirall/folderwatcher.h b/src/mirall/folderwatcher.h
index 172236c..bcdb5f0 100644
--- a/src/mirall/folderwatcher.h
+++ b/src/mirall/folderwatcher.h
@@ -23,6 +23,7 @@
 #include <QTime>
 #include <QHash>
 #include <QScopedPointer>
+#include <QSet>
 
 class QTimer;
 
@@ -82,6 +83,7 @@ signals:
 protected slots:
     // called from the implementations to indicate a change in path
     void changeDetected( const QString& path);
+    void changeDetected( const QStringList& paths);
 
 protected:
     QHash<QString, int> _pendingPathes;
@@ -90,7 +92,7 @@ private:
     QScopedPointer<FolderWatcherPrivate> _d;
     QStringList _ignores;
     QTime _timer;
-    QString _lastPath;
+    QSet<QString> _lastPaths;
 
     friend class FolderWatcherPrivate;
 };
diff --git a/src/mirall/folderwatcher_mac.cpp b/src/mirall/folderwatcher_mac.cpp
index b7da185..18c18b2 100644
--- a/src/mirall/folderwatcher_mac.cpp
+++ b/src/mirall/folderwatcher_mac.cpp
@@ -42,12 +42,26 @@ static void callback(
         ConstFSEventStreamRef streamRef,
         void *clientCallBackInfo,
         size_t numEvents,
-        void *eventPaths,
+        void *eventPathsVoid,
         const FSEventStreamEventFlags eventFlags[],
         const FSEventStreamEventId eventIds[])
 {
     qDebug() << "FolderWatcherPrivate::callback by OS X";
-    reinterpret_cast<FolderWatcherPrivate*>(clientCallBackInfo)->doNotifyParent();
+
+    QStringList paths;
+    CFArrayRef eventPaths = (CFArrayRef)eventPathsVoid;
+    for (int i = 0; i < numEvents; ++i) {
+        CFStringRef path = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(eventPaths, i));
+
+        QString qstring;
+        CFIndex pathLength = CFStringGetLength(path);
+        qstring.resize(pathLength);
+        CFStringGetCharacters(path, CFRangeMake(0, pathLength), reinterpret_cast<UniChar *>(qstring.data()));
+
+        paths.append(qstring);
+    }
+
+    reinterpret_cast<FolderWatcherPrivate*>(clientCallBackInfo)->doNotifyParent(paths);
 }
 
 void FolderWatcherPrivate::startWatching()
@@ -67,7 +81,7 @@ void FolderWatcherPrivate::startWatching()
                                  pathsToWatch,
                                  kFSEventStreamEventIdSinceNow,
                                  0, // latency
-                                 kFSEventStreamCreateFlagNone+kFSEventStreamCreateFlagIgnoreSelf
+                                 kFSEventStreamCreateFlagUseCFTypes|kFSEventStreamCreateFlagFileEvents|kFSEventStreamCreateFlagIgnoreSelf
                                  );
 
     CFRelease(pathsToWatch);
@@ -75,8 +89,9 @@ void FolderWatcherPrivate::startWatching()
     FSEventStreamStart(stream);
 }
 
-void FolderWatcherPrivate::doNotifyParent() {
-    _parent->changeDetected(_folder);
+void FolderWatcherPrivate::doNotifyParent(const QStringList &paths) {
+
+    _parent->changeDetected(paths);
 }
 
 
diff --git a/src/mirall/folderwatcher_mac.h b/src/mirall/folderwatcher_mac.h
index ec7d3c0..4f42e2d 100644
--- a/src/mirall/folderwatcher_mac.h
+++ b/src/mirall/folderwatcher_mac.h
@@ -34,7 +34,7 @@ public:
     void removePath(const QString &) {}
 
     void startWatching();
-    void doNotifyParent();
+    void doNotifyParent(const QStringList &);
 
 private:
     FolderWatcher *_parent;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list