[Pkg-owncloud-commits] [owncloud-client] 103/115: Excludes: Add an context free implementation of exclude file loading.

Sandro Knauß hefee-guest at moszumanska.debian.org
Fri Aug 29 22:04:06 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 dc8f437b31b16023453807c764f6d7bc5c8d48fd
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Thu Aug 21 12:43:04 2014 +0200

    Excludes: Add an context free implementation of exclude file loading.
    
    So that we are more thread safe.
---
 csync/src/csync.c         |  2 +-
 csync/src/csync_exclude.c | 48 ++++++++++++++++++++++++++++-------------------
 csync/src/csync_exclude.h | 10 +++++++++-
 src/mirall/folderman.cpp  |  6 ++++++
 src/mirall/socketapi.cpp  | 44 +++++++++++++++++++++++++++++++++----------
 src/mirall/socketapi.h    |  8 +++++++-
 6 files changed, 86 insertions(+), 32 deletions(-)

diff --git a/csync/src/csync.c b/csync/src/csync.c
index 5c4cab8..3d76791 100644
--- a/csync/src/csync.c
+++ b/csync/src/csync.c
@@ -660,7 +660,7 @@ int csync_add_exclude_list(CSYNC *ctx, const char *path) {
     return -1;
   }
 
-  return csync_exclude_load(ctx, path);
+  return csync_exclude_load(path, &ctx->excludes);
 }
 
 void csync_clear_exclude_list(CSYNC *ctx)
diff --git a/csync/src/csync_exclude.c b/csync/src/csync_exclude.c
index eb97eea..7579df3 100644
--- a/csync/src/csync_exclude.c
+++ b/csync/src/csync_exclude.c
@@ -40,28 +40,28 @@
 #define CSYNC_LOG_CATEGORY_NAME "csync.exclude"
 #include "csync_log.h"
 
-static int _csync_exclude_add(CSYNC *ctx, const char *string) {
+static int _csync_exclude_add(c_strlist_t **inList, const char *string) {
     c_strlist_t *list;
 
-    if (ctx->excludes == NULL) {
-        ctx->excludes = c_strlist_new(32);
-        if (ctx->excludes == NULL) {
+    if (*inList == NULL) {
+        *inList = c_strlist_new(32);
+        if (*inList == NULL) {
             return -1;
         }
     }
 
-    if (ctx->excludes->count == ctx->excludes->size) {
-        list = c_strlist_expand(ctx->excludes, 2 * ctx->excludes->size);
+    if ((*inList)->count == (*inList)->size) {
+        list = c_strlist_expand(*inList, 2 * (*inList)->size);
         if (list == NULL) {
             return -1;
         }
-        ctx->excludes = list;
+        *inList = list;
     }
 
-    return c_strlist_add(ctx->excludes, string);
+    return c_strlist_add(*inList, string);
 }
 
-int csync_exclude_load(CSYNC *ctx, const char *fname) {
+int csync_exclude_load(const char *fname, c_strlist_t **list) {
   int fd = -1;
   int i = 0;
   int rc = -1;
@@ -70,7 +70,7 @@ int csync_exclude_load(CSYNC *ctx, const char *fname) {
   char *entry = NULL;
   mbchar_t *w_fname;
 
-  if (ctx == NULL || fname == NULL) {
+  if (fname == NULL) {
       return -1;
   }
 
@@ -119,7 +119,7 @@ int csync_exclude_load(CSYNC *ctx, const char *fname) {
         buf[i] = '\0';
         if (*entry != '#') {
           CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "Adding entry: %s", entry);
-          rc = _csync_exclude_add(ctx, entry);
+          rc = _csync_exclude_add(list, entry);
           if (rc < 0) {
               goto out;
           }
@@ -145,6 +145,21 @@ void csync_exclude_destroy(CSYNC *ctx) {
 }
 
 CSYNC_EXCLUDE_TYPE csync_excluded(CSYNC *ctx, const char *path, int filetype) {
+
+    CSYNC_EXCLUDE_TYPE match = CSYNC_NOT_EXCLUDED;
+
+    match = csync_excluded_no_ctx( ctx->excludes, path, filetype );
+
+    if (match == CSYNC_NOT_EXCLUDED && ctx->checkBlackListHook) {
+        if (ctx->checkBlackListHook(ctx->checkBlackListData, path)) {
+            match = CSYNC_FILE_EXCLUDE_LIST;
+        }
+    }
+
+    return match;
+}
+
+CSYNC_EXCLUDE_TYPE csync_excluded_no_ctx(c_strlist_t *excludes, const char *path, int filetype) {
   size_t i = 0;
   const char *p = NULL;
   char *bname = NULL;
@@ -226,14 +241,14 @@ CSYNC_EXCLUDE_TYPE csync_excluded(CSYNC *ctx, const char *path, int filetype) {
   SAFE_FREE(bname);
   SAFE_FREE(dname);
 
-  if (ctx == NULL || ctx->excludes == NULL) {
+  if( ! excludes ) {
       goto out;
   }
 
   /* Loop over all exclude patterns and evaluate the given path */
-  for (i = 0; match == CSYNC_NOT_EXCLUDED && i < ctx->excludes->count; i++) {
+  for (i = 0; match == CSYNC_NOT_EXCLUDED && i < excludes->count; i++) {
       bool match_dirs_only = false;
-      char *pattern_stored = c_strdup(ctx->excludes->vector[i]);
+      char *pattern_stored = c_strdup(excludes->vector[i]);
       char* pattern = pattern_stored;
 
       type = CSYNC_FILE_EXCLUDE_LIST;
@@ -313,11 +328,6 @@ CSYNC_EXCLUDE_TYPE csync_excluded(CSYNC *ctx, const char *path, int filetype) {
       SAFE_FREE(dname);
   }
 
-  if (match == CSYNC_NOT_EXCLUDED && ctx->checkBlackListHook) {
-      if (ctx->checkBlackListHook(ctx->checkBlackListData, path)) {
-          match = CSYNC_FILE_EXCLUDE_LIST;
-      }
-  }
 
 out:
 
diff --git a/csync/src/csync_exclude.h b/csync/src/csync_exclude.h
index fabeeca..9e30d8a 100644
--- a/csync/src/csync_exclude.h
+++ b/csync/src/csync_exclude.h
@@ -37,7 +37,7 @@ typedef enum csync_exclude_type_e CSYNC_EXCLUDE_TYPE;
  *
  * @return  0 on success, -1 if an error occured with errno set.
  */
-int csync_exclude_load(CSYNC *ctx, const char *fname);
+int csync_exclude_load(const char *fname, c_strlist_t **list);
 
 /**
  * @brief Clear the exclude list in memory.
@@ -65,6 +65,14 @@ void csync_exclude_destroy(CSYNC *ctx);
  */
 CSYNC_EXCLUDE_TYPE csync_excluded(CSYNC *ctx, const char *path, int filetype);
 
+/**
+ * @brief csync_excluded_no_ctx
+ * @param excludes
+ * @param path
+ * @param filetype
+ * @return
+ */
+CSYNC_EXCLUDE_TYPE csync_excluded_no_ctx(c_strlist_t *excludes, const char *path, int filetype);
 #endif /* _CSYNC_EXCLUDE_H */
 
 /* vim: set ft=c.doxygen ts=8 sw=2 et cindent: */
diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp
index c530c17..b8973d5 100644
--- a/src/mirall/folderman.cpp
+++ b/src/mirall/folderman.cpp
@@ -53,6 +53,7 @@ FolderMan::FolderMan(QObject *parent) :
     _instance = this;
 
     _socketApi = new SocketApi(this);
+    _socketApi->slotReadExcludes();
 }
 
 FolderMan *FolderMan::instance()
@@ -489,6 +490,11 @@ void FolderMan::slotScheduleFolderSync()
                 _currentSyncFolder = alias;
 
                 f->startSync( QStringList() );
+
+                // reread the excludes of the socket api
+                // FIXME: the excludes need rework.
+                _socketApi->slotClearExcludesList();
+                _socketApi->slotReadExcludes();
             }
         }
     }
diff --git a/src/mirall/socketapi.cpp b/src/mirall/socketapi.cpp
index 2ef9279..f657cd4 100644
--- a/src/mirall/socketapi.cpp
+++ b/src/mirall/socketapi.cpp
@@ -43,8 +43,8 @@ enum csync_exclude_type_e {
 };
 typedef enum csync_exclude_type_e CSYNC_EXCLUDE_TYPE;
 
-CSYNC_EXCLUDE_TYPE csync_excluded(CSYNC *ctx, const char *path, int filetype);
-
+CSYNC_EXCLUDE_TYPE csync_excluded_no_ctx(c_strlist_t *excludes, const char *path, int filetype);
+int csync_exclude_load(const char *fname, c_strlist_t **list);
 }
 
 namespace {
@@ -57,7 +57,7 @@ namespace Mirall {
 
 namespace SocketApiHelper {
 
-SyncFileStatus fileStatus(Folder *folder, const QString& systemFileName );
+SyncFileStatus fileStatus(Folder *folder, const QString& systemFileName, c_strlist_t *excludes );
 
 /**
  * @brief recursiveFolderStatus
@@ -70,7 +70,7 @@ SyncFileStatus fileStatus(Folder *folder, const QString& systemFileName );
  */
 // compute the file status of a directory recursively. It returns either
 // "all in sync" or "needs update" or "error", no more details.
-SyncFileStatus recursiveFolderStatus(Folder *folder, const QString& fileName )
+SyncFileStatus recursiveFolderStatus(Folder *folder, const QString& fileName, c_strlist_t *excludes  )
 {
     QDir dir(folder->path() + fileName);
 
@@ -84,14 +84,14 @@ SyncFileStatus recursiveFolderStatus(Folder *folder, const QString& fileName )
         SyncFileStatus sfs;
 
         if( fi.isDir() ) {
-            sfs = recursiveFolderStatus(folder, normalizedFile );
+            sfs = recursiveFolderStatus(folder, normalizedFile, excludes );
         } else {
             QString fs( normalizedFile );
             if( fileName.isEmpty() ) {
                 // toplevel, no slash etc. needed.
                 fs = entry.normalized(QString::NormalizationForm_C);
             }
-            sfs = fileStatus(folder, fs );
+            sfs = fileStatus(folder, fs, excludes);
         }
 
         if( sfs.tag() == SyncFileStatus::STATUS_STAT_ERROR || sfs.tag() == SyncFileStatus::STATUS_ERROR ) {
@@ -106,7 +106,7 @@ SyncFileStatus recursiveFolderStatus(Folder *folder, const QString& fileName )
 /**
  * Get status about a single file.
  */
-SyncFileStatus fileStatus(Folder *folder, const QString& systemFileName )
+SyncFileStatus fileStatus(Folder *folder, const QString& systemFileName, c_strlist_t *excludes )
 {
     // FIXME: Find a way for STATUS_ERROR
 
@@ -142,7 +142,8 @@ SyncFileStatus fileStatus(Folder *folder, const QString& systemFileName )
 
     // '\' is ignored, so convert to unix path before passing the path in.
     QString unixFileName = QDir::fromNativeSeparators(fileName);
-    CSYNC_EXCLUDE_TYPE excl = csync_excluded(folder->csyncContext(), unixFileName.toUtf8(), type);
+
+    CSYNC_EXCLUDE_TYPE excl = csync_excluded_no_ctx(excludes, unixFileName.toUtf8(), type);
     if( excl != CSYNC_NOT_EXCLUDED ) {
         return SyncFileStatus(SyncFileStatus::STATUS_IGNORE);
     }
@@ -157,7 +158,7 @@ SyncFileStatus fileStatus(Folder *folder, const QString& systemFileName )
     SyncFileStatus status(SyncFileStatus::STATUS_NONE);
     if( type == CSYNC_FTW_TYPE_DIR ) {
         // compute recursive status of the directory
-        status = recursiveFolderStatus( folder, fileName );
+        status = recursiveFolderStatus( folder, fileName, excludes );
     } else if(fi.lastModified() != rec._modtime ) {
         // file was locally modified.
         status.set(SyncFileStatus::STATUS_EVAL);
@@ -179,6 +180,7 @@ SyncFileStatus fileStatus(Folder *folder, const QString& systemFileName )
 SocketApi::SocketApi(QObject* parent)
     : QObject(parent)
     , _localServer(new QTcpServer(this))
+    , _excludes(0)
 {
     // setup socket
     DEBUG << "Establishing SocketAPI server at" << PORT;
@@ -197,6 +199,28 @@ SocketApi::~SocketApi()
 {
     DEBUG << "dtor";
     _localServer->close();
+    slotClearExcludesList();
+}
+
+void SocketApi::slotClearExcludesList()
+{
+    c_strlist_clear(_excludes);
+}
+
+void SocketApi::slotReadExcludes()
+{
+    MirallConfigFile cfgFile;
+    slotClearExcludesList();
+    QString excludeList = cfgFile.excludeFile( MirallConfigFile::SystemScope );
+    if( !excludeList.isEmpty() ) {
+        qDebug() << "==== added system ignore list to socketapi:" << excludeList.toUtf8();
+        csync_exclude_load(excludeList.toUtf8(), &_excludes);
+    }
+    excludeList = cfgFile.excludeFile( MirallConfigFile::UserScope );
+    if( !excludeList.isEmpty() ) {
+        qDebug() << "==== added user defined ignore list to csync:" << excludeList.toUtf8();
+        csync_exclude_load(excludeList.toUtf8(), &_excludes);
+    }
 }
 
 void SocketApi::slotNewConnection()
@@ -366,7 +390,7 @@ void SocketApi::command_RETRIEVE_FILE_STATUS(const QString& argument, QTcpSocket
         statusString = QLatin1String("NOP");
     } else {
         const QString file = argument.mid(syncFolder->path().length());
-        SyncFileStatus fileStatus = SocketApiHelper::fileStatus(syncFolder, file);
+        SyncFileStatus fileStatus = SocketApiHelper::fileStatus(syncFolder, file, _excludes);
 
         statusString = fileStatus.toSocketAPIString();
     }
diff --git a/src/mirall/socketapi.h b/src/mirall/socketapi.h
index e8f4ac0..cfab53e 100644
--- a/src/mirall/socketapi.h
+++ b/src/mirall/socketapi.h
@@ -16,6 +16,10 @@
 #ifndef SOCKETAPI_H
 #define SOCKETAPI_H
 
+extern "C" {
+#include <std/c_string.h>
+}
+
 #include <QWeakPointer>
 #include <QTcpSocket>
 #include <QTcpServer>
@@ -40,7 +44,8 @@ public slots:
     void slotUpdateFolderView(const QString&);
     void slotUnregisterPath( const QString& alias );
     void slotRegisterPath( const QString& alias );
-
+    void slotReadExcludes();
+    void slotClearExcludesList();
 private slots:
     void slotNewConnection();
     void onLostConnection();
@@ -57,6 +62,7 @@ private:
 private:
     QTcpServer *_localServer;
     QList<QTcpSocket*> _listeners;
+    c_strlist_t *_excludes;
 };
 
 }

-- 
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