From: Christian Kamm Date: Thu, 15 Nov 2018 09:14:26 +0000 (+0100) Subject: vfs: Ensure local discovery is done on dehydration request X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~382 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d7ad7854c1df8e0eabd228936a5479763cd6f897;p=nextcloud-desktop.git vfs: Ensure local discovery is done on dehydration request --- diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 176510ce0..f58e1e699 100644 --- a/src/gui/folder.cpp +++ b/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) { diff --git a/src/gui/folder.h b/src/gui/folder.h index 507fd09f0..2666c8f4e 100644 --- a/src/gui/folder.h +++ b/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); diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp index 4952a133f..f1aa3fb54 100644 --- a/src/gui/socketapi.cpp +++ b/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 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)