vfs: Ensure local discovery is done on dehydration request
authorChristian Kamm <mail@ckamm.de>
Thu, 15 Nov 2018 09:14:26 +0000 (10:14 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:26 +0000 (10:58 +0100)
src/gui/folder.cpp
src/gui/folder.h
src/gui/socketapi.cpp

index 176510ce0f083966fbe431055224213660e871aa..f58e1e69969f77793b08503db1acd2cce3bb7354 100644 (file)
@@ -591,6 +591,34 @@ void Folder::downloadVirtualFile(const QString &_relativepath)
     slotScheduleThisFolder();
 }
 
+void Folder::dehydrateFile(const QString &_relativepath)
+{
+    qCInfo(lcFolder) << "Dehydrating file: " << _relativepath;
+    auto relativepath = _relativepath.toUtf8();
+
+    auto markForDehydration = [&](SyncJournalFileRecord rec) {
+        if (rec._type != ItemTypeFile)
+            return;
+        rec._type = ItemTypeVirtualFileDehydration;
+        _journal.setFileRecord(rec);
+        _localDiscoveryTracker->addTouchedPath(relativepath);
+    };
+
+    SyncJournalFileRecord record;
+    _journal.getFileRecord(relativepath, &record);
+    if (!record.isValid())
+        return;
+    if (record._type == ItemTypeFile) {
+        markForDehydration(record);
+    } else if (record._type == ItemTypeDirectory) {
+        _journal.getFilesBelowPath(relativepath, markForDehydration);
+    } else {
+        qCWarning(lcFolder) << "Invalid existing record " << record._type << " for file " << _relativepath;
+    }
+
+    // Schedule a sync (Folder man will start the sync in a few ms)
+    slotScheduleThisFolder();
+}
 
 void Folder::setUseVirtualFiles(bool enabled)
 {
index 507fd09f04d2f671e368e40307eca266a8598b92..2666c8f4e259fae4e7c1f9e51267e56813814982 100644 (file)
@@ -299,10 +299,18 @@ public slots:
 
     /**
      * Mark a virtual file as being ready for download, and start a sync.
-     * relativePath is the patch to the file (including the extension)
+     * relativepath is the path to the file (including the extension)
      */
     void downloadVirtualFile(const QString &relativepath);
 
+    /**
+     * Turn a regular file into a dehydrated placeholder.
+     *
+     * relativepath is the path to the file
+     * It's allowed to pass a path to a folder: all contained files will be dehydrated.
+     */
+    void dehydrateFile(const QString &relativepath);
+
 private slots:
     void slotSyncStarted();
     void slotSyncFinished(bool);
index 4952a133fb7ced412fba1368c42263e9bfd5b194..f1aa3fb54c3769ab518663cc01a537f1016aeaaa 100644 (file)
@@ -707,33 +707,11 @@ void SocketApi::command_REPLACE_VIRTUAL_FILE(const QString &filesArg, SocketList
 {
     QStringList files = filesArg.split(QLatin1Char('\x1e')); // Record Separator
 
-    QSet<Folder *> toSync;
     for (const auto &file : files) {
         auto data = FileData::get(file);
-        if (!data.folder)
-            continue;
-        auto journal = data.folder->journalDb();
-        auto markForDehydration = [&](SyncJournalFileRecord rec) {
-            if (rec._type != ItemTypeFile)
-                return;
-            rec._type = ItemTypeVirtualFileDehydration;
-            journal->setFileRecord(rec);
-            toSync.insert(data.folder);
-        };
-
-        QFileInfo fi(file);
-        if (fi.isDir()) {
-            journal->getFilesBelowPath(data.folderRelativePath.toUtf8(), markForDehydration);
-            continue;
-        }
-        auto record = data.journalRecord();
-        if (!record.isValid() || record._type != ItemTypeFile)
-            continue;
-        markForDehydration(record);
+        if (data.folder)
+            data.folder->dehydrateFile(data.folderRelativePath);
     }
-
-    for (const auto folder : toSync)
-        FolderMan::instance()->scheduleFolder(folder);
 }
 
 void SocketApi::copyUrlToClipboard(const QString &link)