Discovery: Add branding option to disable default sync of 'M' directories
authorOlivier Goffart <ogoffart@woboq.com>
Tue, 29 Nov 2016 09:36:37 +0000 (10:36 +0100)
committerMarkus Goetz <markus@woboq.com>
Fri, 27 Jan 2017 14:59:59 +0000 (15:59 +0100)
Issue #5331 and https://github.com/owncloud/enterprise/issues/1594

csync/src/csync_private.h
csync/src/csync_update.c
src/libsync/discoveryphase.cpp
src/libsync/discoveryphase.h
src/libsync/theme.cpp
src/libsync/theme.h

index f204107d2c3f7f692845d973ffbbd140c89105b9..8944699a31c74438c90adcec21a996394929356e 100644 (file)
@@ -89,7 +89,7 @@ struct csync_s {
 
       /* hooks for checking the white list (uses the update_callback_userdata) */
       int (*checkSelectiveSyncBlackListHook)(void*, const char*);
-      int (*checkSelectiveSyncNewFolderHook)(void*, const char*);
+      int (*checkSelectiveSyncNewFolderHook)(void*, const char* /* path */, const char* /* remotePerm */);
 
 
       csync_vio_opendir_hook remote_opendir_hook;
index 2ac248d1556e3865e2d766fcc9479bae25760656..66c8e965c4c903d092518a8c2b4a2a4110b7ed4a 100644 (file)
@@ -436,7 +436,7 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
                 st->instruction = CSYNC_INSTRUCTION_NEW;
 
                 if (fs->type == CSYNC_VIO_FILE_TYPE_DIRECTORY && ctx->current == REMOTE_REPLICA && ctx->callbacks.checkSelectiveSyncNewFolderHook) {
-                    if (ctx->callbacks.checkSelectiveSyncNewFolderHook(ctx->callbacks.update_callback_userdata, path)) {
+                    if (ctx->callbacks.checkSelectiveSyncNewFolderHook(ctx->callbacks.update_callback_userdata, path, fs->remotePerm)) {
                         csync_file_stat_free(st);
                         return 1;
                     }
index bb35f1f97f8a58ddb30a202be4ce6931f5787dba..b629b426ed9a9eadabf84ace8a32bc54335bf3d4 100644 (file)
@@ -20,6 +20,9 @@
 #include <QUrl>
 #include "account.h"
 #include <QFileInfo>
+#include "theme.h"
+#include <cstring>
+
 
 namespace OCC {
 
@@ -81,13 +84,21 @@ int DiscoveryJob::isInSelectiveSyncBlackListCallback(void *data, const char *pat
     return static_cast<DiscoveryJob*>(data)->isInSelectiveSyncBlackList(path);
 }
 
-bool DiscoveryJob::checkSelectiveSyncNewFolder(const QString& path)
+bool DiscoveryJob::checkSelectiveSyncNewFolder(const QString& path, const char *remotePerm)
 {
     // If this path or the parent is in the white list, then we do not block this file
     if (findPathInList(_selectiveSyncWhiteList, path)) {
         return false;
     }
 
+    if (Theme::instance()->dontSyncMountedStorageByDefault()) {
+        // 'M' in the permission means that it is unselected by default. (issue #5331)
+        if (std::strchr(remotePerm, 'M')) {
+            emit newBigFolder(path);
+            return true;
+        }
+    }
+
     if (_newBigFolderSizeLimit < 0) {
         // no limit, everything is allowed;
         return false;
@@ -119,9 +130,9 @@ bool DiscoveryJob::checkSelectiveSyncNewFolder(const QString& path)
     }
 }
 
-int DiscoveryJob::checkSelectiveSyncNewFolderCallback(void *data, const char *path)
+int DiscoveryJob::checkSelectiveSyncNewFolderCallback(void *data, const char *path, const char *remotePerm)
 {
-    return static_cast<DiscoveryJob*>(data)->checkSelectiveSyncNewFolder(QString::fromUtf8(path));
+    return static_cast<DiscoveryJob*>(data)->checkSelectiveSyncNewFolder(QString::fromUtf8(path), remotePerm);
 }
 
 
index c030adb3339177014698e87e860148f767d1950d..701581c06dfd46418add2165c11230e05b037693 100644 (file)
@@ -176,8 +176,8 @@ class DiscoveryJob : public QObject {
      */
     bool isInSelectiveSyncBlackList(const char* path) const;
     static int isInSelectiveSyncBlackListCallback(void *, const char *);
-    bool checkSelectiveSyncNewFolder(const QString &path);
-    static int checkSelectiveSyncNewFolderCallback(void*, const char*);
+    bool checkSelectiveSyncNewFolder(const QString &path, const char *remotePerm);
+    static int checkSelectiveSyncNewFolderCallback(void* data, const char* path, const char* remotePerm);
 
     // Just for progress
     static void update_job_update_callback (bool local,
index 53e850b99997fdc2d3818fbb0cdd6c6ea6470243..3a0c0b3edbbc8ce286eafd89364fc570d7180506 100644 (file)
@@ -478,4 +478,10 @@ QString Theme::quotaBaseFolder() const
 {
     return QLatin1String("/");
 }
+
+bool Theme::dontSyncMountedStorageByDefault() const
+{
+    return false;
+}
+
 } // end namespace client
index 63c86b4aa1f1e9076c8148fd94f17e99c88b3f76..4e6130fd6daf3e46e51785214373f4bc56ebc454 100644 (file)
@@ -302,6 +302,12 @@ public:
      */
     virtual QString quotaBaseFolder() const;
 
+    /**
+     * By default, mounted storage will not be sync'ed (i.e, they will be disabled in the
+     * selective sync
+     */
+    virtual bool dontSyncMountedStorageByDefault() const;
+
 protected:
 #ifndef TOKEN_AUTH_ONLY
     QIcon themeIcon(const QString& name, bool sysTray = false, bool sysTrayMenuVisible = false) const;