From: Christian Kamm Date: Fri, 8 Feb 2019 11:21:25 +0000 (+0100) Subject: Vfs: Improve sync protocol entries for actions X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~293 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=910ccaf6001d6e9bd728d09b9acbcd614556f8e0;p=nextcloud-desktop.git Vfs: Improve sync protocol entries for actions Creating a new virtual file and replacing a file with a virtual one now have their own text in the protocol, not just "Downloaded". To do this, the SyncFileItem type is kept as ItemTypeVirtualFileDehydration for these actions. Added new code to ensure the type isn't written to the database. While looking at this, I've also added documentation on SyncFileItem's _file, _renameTarget, _originalFile and destination() because some of the semantics weren't clear. --- diff --git a/src/libsync/progressdispatcher.cpp b/src/libsync/progressdispatcher.cpp index 135280173..3fbc6d361 100644 --- a/src/libsync/progressdispatcher.cpp +++ b/src/libsync/progressdispatcher.cpp @@ -29,7 +29,13 @@ QString Progress::asResultString(const SyncFileItem &item) case CSYNC_INSTRUCTION_NEW: case CSYNC_INSTRUCTION_TYPE_CHANGE: if (item._direction != SyncFileItem::Up) { - return QCoreApplication::translate("progress", "Downloaded"); + if (item._type == ItemTypeVirtualFile) { + return QCoreApplication::translate("progress", "Virtual file created"); + } else if (item._type == ItemTypeVirtualFileDehydration) { + return QCoreApplication::translate("progress", "Replaced by virtual file"); + } else { + return QCoreApplication::translate("progress", "Downloaded"); + } } else { return QCoreApplication::translate("progress", "Uploaded"); } diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 39bec7eae..e925c209d 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -427,11 +427,13 @@ void PropagateDownloadFile::startAfterIsEncryptedIsChecked() } qCDebug(lcPropagateDownload) << "dehydrating file" << _item->_file; - _item->_type = ItemTypeVirtualFile; // Needed? vfs->dehydratePlaceholder(*_item); propagator()->_journal->deleteFileRecord(_item->_originalFile); - if (!_item->_renameTarget.isEmpty()) - _item->_file = _item->_renameTarget; + // NOTE: This is only done because other rename-like ops also adjust _file, even though + // updateMetadata() will store at destination() anyway. Doing this may not be necessary + // but maybe it has an effect on reporting (destination() and moves aren't handled + // consistently everywhere) + _item->_file = _item->destination(); updateMetadata(false); return; } diff --git a/src/libsync/syncfileitem.cpp b/src/libsync/syncfileitem.cpp index 2d993ec11..c72cb1b46 100644 --- a/src/libsync/syncfileitem.cpp +++ b/src/libsync/syncfileitem.cpp @@ -29,7 +29,14 @@ SyncJournalFileRecord SyncFileItem::toSyncJournalFileRecordWithInode(const QStri SyncJournalFileRecord rec; rec._path = destination().toUtf8(); rec._modtime = _modtime; + + // Some types should never be written to the database when propagation completes rec._type = _type; + if (rec._type == ItemTypeVirtualFileDownload) + rec._type = ItemTypeFile; + if (rec._type == ItemTypeVirtualFileDehydration) + rec._type = ItemTypeVirtualFile; + rec._etag = _etag; rec._fileId = _fileId; rec._fileSize = _size; diff --git a/src/libsync/syncfileitem.h b/src/libsync/syncfileitem.h index 6e0fe86c4..b41024433 100644 --- a/src/libsync/syncfileitem.h +++ b/src/libsync/syncfileitem.h @@ -196,15 +196,30 @@ public: } // Variables useful for everybody + + /** The syncfolder-relative filesystem path that the operation is about + * + * For rename operation this is the rename source and the target is in _renameTarget. + */ QString _file; - // for renames: the name _file should be renamed to - // for dehydrations: the name _file should become after dehydration (like adding a suffix) + + /** for renames: the name _file should be renamed to + * for dehydrations: the name _file should become after dehydration (like adding a suffix) + * otherwise empty. Use destination() to find the sync target. + */ QString _renameTarget; + /** The db-path of this item. + * + * This can easily differ from _file and _renameTarget if parts of the path were renamed. + */ + QString _originalFile; + /// Whether there's end to end encryption on this file. /// If the file is encrypted, the _encryptedFilename is /// the encrypted name on the server. QString _encryptedFileName; + ItemType _type BITFIELD(3); Direction _direction BITFIELD(3); bool _serverHasIgnoredFiles BITFIELD(1); @@ -234,7 +249,6 @@ public: // Variables used by the propagator csync_instructions_e _instruction = CSYNC_INSTRUCTION_NONE; - QString _originalFile; // as it is in the csync tree time_t _modtime = 0; QByteArray _etag; quint64 _size = 0; diff --git a/test/testsyncvirtualfiles.cpp b/test/testsyncvirtualfiles.cpp index 3c461cad0..ce140c0b8 100644 --- a/test/testsyncvirtualfiles.cpp +++ b/test/testsyncvirtualfiles.cpp @@ -678,9 +678,11 @@ private slots: QVERIFY(isDehydrated("A/a1")); QVERIFY(hasDehydratedDbEntries("A/a1")); QVERIFY(itemInstruction(completeSpy, "A/a1.nextcloud", CSYNC_INSTRUCTION_SYNC)); + QCOMPARE(findItem(completeSpy, "A/a1.nextcloud")->_type, ItemTypeVirtualFileDehydration); QVERIFY(isDehydrated("A/a2")); QVERIFY(hasDehydratedDbEntries("A/a2")); QVERIFY(itemInstruction(completeSpy, "A/a2.nextcloud", CSYNC_INSTRUCTION_SYNC)); + QCOMPARE(findItem(completeSpy, "A/a2.nextcloud")->_type, ItemTypeVirtualFileDehydration); QVERIFY(!fakeFolder.currentLocalState().find("B/b1")); QVERIFY(!fakeFolder.currentRemoteState().find("B/b1"));