소스 검색

vfs: Ensure local discovery is done on dehydration request

Christian Kamm 7 년 전
부모
커밋
d7ad7854c1
3개의 변경된 파일39개의 추가작업 그리고 25개의 파일을 삭제
  1. 28 0
      src/gui/folder.cpp
  2. 9 1
      src/gui/folder.h
  3. 2 24
      src/gui/socketapi.cpp

+ 28 - 0
src/gui/folder.cpp

@@ -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)
 {

+ 9 - 1
src/gui/folder.h

@@ -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);

+ 2 - 24
src/gui/socketapi.cpp

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