Skip to content

Commit

Permalink
Vfs: Improve sync protocol entries for actions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ckamm committed Feb 11, 2019
1 parent 9b7eba0 commit f786ef1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/libsync/progressdispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
8 changes: 5 additions & 3 deletions src/libsync/propagatedownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,13 @@ void PropagateDownloadFile::start()
}

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;
}
Expand Down
7 changes: 7 additions & 0 deletions src/libsync/syncfileitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 17 additions & 3 deletions src/libsync/syncfileitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,25 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem
}

// 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;

ItemType _type BITFIELD(3);
Direction _direction BITFIELD(3);
bool _serverHasIgnoredFiles BITFIELD(1);
Expand Down Expand Up @@ -236,7 +251,6 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem

// Variables used by the propagator
csync_instructions_e _instruction;
QString _originalFile; // as it is in the csync tree
time_t _modtime;
QByteArray _etag;
quint64 _size;
Expand Down
2 changes: 2 additions & 0 deletions test/testsyncvirtualfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,11 @@ private slots:
QVERIFY(isDehydrated("A/a1"));
QVERIFY(hasDehydratedDbEntries("A/a1"));
QVERIFY(itemInstruction(completeSpy, "A/a1.owncloud", CSYNC_INSTRUCTION_SYNC));
QCOMPARE(findItem(completeSpy, "A/a1.owncloud")->_type, ItemTypeVirtualFileDehydration);
QVERIFY(isDehydrated("A/a2"));
QVERIFY(hasDehydratedDbEntries("A/a2"));
QVERIFY(itemInstruction(completeSpy, "A/a2.owncloud", CSYNC_INSTRUCTION_SYNC));
QCOMPARE(findItem(completeSpy, "A/a2.owncloud")->_type, ItemTypeVirtualFileDehydration);

QVERIFY(!fakeFolder.currentLocalState().find("B/b1"));
QVERIFY(!fakeFolder.currentRemoteState().find("B/b1"));
Expand Down

0 comments on commit f786ef1

Please sign in to comment.