Placeholders: Move the placeholder option from the account to the folder
authorOlivier Goffart <ogoffart@woboq.com>
Mon, 15 Jan 2018 16:29:48 +0000 (17:29 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:57:48 +0000 (10:57 +0100)
src/gui/folder.cpp
src/gui/folder.h
src/libsync/account.h
src/libsync/syncengine.cpp
src/libsync/syncoptions.h
test/testsyncplaceholders.cpp

index 8cd997340bfb2037f3b43690b85cd2e5f8861def..2ed886550374cc82e22ee619beec23bbdce76cfb 100644 (file)
@@ -714,6 +714,7 @@ void Folder::setSyncOptions()
     opt._newBigFolderSizeLimit = newFolderLimit.first ? newFolderLimit.second * 1000LL * 1000LL : -1; // convert from MB to B
     opt._confirmExternalStorage = cfgFile.confirmExternalStorage();
     opt._moveFilesToTrash = cfgFile.moveToTrash();
+    opt._usePlaceholders = _definition.usePlaceholders;
 
     QByteArray chunkSizeEnv = qgetenv("OWNCLOUD_CHUNK_SIZE");
     if (!chunkSizeEnv.isEmpty()) {
@@ -1126,6 +1127,7 @@ void FolderDefinition::save(QSettings &settings, const FolderDefinition &folder)
     settings.setValue(QLatin1String("targetPath"), folder.targetPath);
     settings.setValue(QLatin1String("paused"), folder.paused);
     settings.setValue(QLatin1String("ignoreHiddenFiles"), folder.ignoreHiddenFiles);
+    settings.setValue(QLatin1String("usePlaceholders"), folder.usePlaceholders);
 
     // Happens only on Windows when the explorer integration is enabled.
     if (!folder.navigationPaneClsid.isNull())
@@ -1146,6 +1148,7 @@ bool FolderDefinition::load(QSettings &settings, const QString &alias,
     folder->paused = settings.value(QLatin1String("paused")).toBool();
     folder->ignoreHiddenFiles = settings.value(QLatin1String("ignoreHiddenFiles"), QVariant(true)).toBool();
     folder->navigationPaneClsid = settings.value(QLatin1String("navigationPaneClsid")).toUuid();
+    folder->usePlaceholders = settings.value(QLatin1String("usePlaceholders")).toBool();
     settings.endGroup();
 
     // Old settings can contain paths with native separators. In the rest of the
index 095a813d0fe5eed2d3d1ef55cc9fff620fb58ec4..778e35ad5b7819a71fa0932d42d81693d2773d4b 100644 (file)
@@ -59,6 +59,8 @@ public:
     bool paused = false;
     /// whether the folder syncs hidden files
     bool ignoreHiddenFiles = false;
+    /// New files are downloaded as placeholders
+    bool usePlaceholders = false;
     /// The CLSID where this folder appears in registry for the Explorer navigation pane entry.
     QUuid navigationPaneClsid;
 
index 1f7d9608f8afb0b6a549faf979ef5fb8ada8d672..92008ff0824f14330a036ffb292a2c165eefbd0d 100644 (file)
@@ -249,9 +249,6 @@ public:
     // Check for the directEditing capability
     void fetchDirectEditors(const QUrl &directEditingURL, const QString &directEditingETag);
 
-    bool usePlaceholders() const { return _usePlaceholders; }
-    void setUsePlaceholders(bool use) { _usePlaceholders = use; }
-
 public slots:
     /// Used when forgetting credentials
     void clearQNAMCache();
@@ -348,8 +345,6 @@ private:
     private:
         bool _isRemoteWipeRequested_HACK = false;
     // <-- FIXME MS@2019-12-07
-
-    bool _usePlaceholders = false;
 };
 }
 
index 9bd03bc0cc9a78ee6f1a6e2823f1aaddf7e31204..69e7f7d25d6ee91b79c5a3593fb9d67f370b1703 100644 (file)
@@ -858,7 +858,7 @@ void SyncEngine::startSync()
         return shouldDiscoverLocally(path);
     };
 
-    _csync_ctx->new_files_are_placeholders = account()->usePlaceholders();
+    _csync_ctx->new_files_are_placeholders = _syncOptions._usePlaceholders;
 
     // If needed, make sure we have up to date E2E information before the
     // discovery phase, otherwise we start right away
index 676bfbeb7f660500dc4bb2cf745c56eedea527d7..e9e97efec3bda25a2cf8bd218f0c9360b5c3f8ec 100644 (file)
@@ -36,6 +36,9 @@ struct SyncOptions
     /** If remotely deleted files are needed to move to trash */
     bool _moveFilesToTrash = false;
 
+    /** Create a placeholder for new files instead of downloading */
+    bool _usePlaceholders = false;
+
     /** The initial un-adjusted chunk size in bytes for chunked uploads, both
      * for old and new chunking algorithm, which classifies the item to be chunked
      *
index 7d94ee8a5c2fe09dbf711064f54d2cd4eab750a5..038da9a5c512d2a724deed6c9765376ba2dcec81 100644 (file)
@@ -52,7 +52,9 @@ private slots:
         QFETCH(bool, doLocalDiscovery);
 
         FakeFolder fakeFolder{FileInfo()};
-        fakeFolder.syncEngine().account()->setUsePlaceholders(true);
+        SyncOptions syncOptions;
+        syncOptions._usePlaceholders = true;
+        fakeFolder.syncEngine().setSyncOptions(syncOptions);
         QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
         QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
 
@@ -132,7 +134,9 @@ private slots:
     void testWithNormalSync()
     {
         FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
-        fakeFolder.syncEngine().account()->setUsePlaceholders(true);
+        SyncOptions syncOptions;
+        syncOptions._usePlaceholders = true;
+        fakeFolder.syncEngine().setSyncOptions(syncOptions);
         QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
         QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
 
@@ -168,7 +172,9 @@ private slots:
     void testPlaceholderDownload()
     {
         FakeFolder fakeFolder{FileInfo()};
-        fakeFolder.syncEngine().account()->setUsePlaceholders(true);
+        SyncOptions syncOptions;
+        syncOptions._usePlaceholders = true;
+        fakeFolder.syncEngine().setSyncOptions(syncOptions);
         QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
         QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));