Skip to content

Commit af01969

Browse files
committed
fix(linux/vfs): makes sure the hydration job can do something useful
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
1 parent a5fbfb3 commit af01969

3 files changed

Lines changed: 56 additions & 40 deletions

File tree

src/common/vfs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ public Q_SLOTS:
326326
/// start complete
327327
void started();
328328

329+
/// The vfs plugin detected that the meta data are out of sync and requests a sync with the server
330+
void needSync();
331+
329332
protected:
330333
/** Setup the plugin for the folder.
331334
*

src/gui/folder.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,14 @@ void Folder::startVfs()
599599
connect(&_engine->syncFileStatusTracker(), &SyncFileStatusTracker::fileStatusChanged,
600600
_vfs.data(), &Vfs::fileStatusChanged);
601601

602+
connect(_vfs.get(), &Vfs::needSync, this, [this] {
603+
if (canSync()) {
604+
// the vfs plugin detected that its metadata is out of sync and requests a new sync
605+
// the request has a hight priority as it is probably issued after a user request
606+
FolderMan::instance()->scheduleFolder(this);
607+
}
608+
});
609+
602610
_vfs->start(vfsParams);
603611

604612
// Immediately mark the sqlite temporaries as excluded. They get recreated

src/libsync/hydrationjob.cpp

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#include "hydrationjob.h"
55

6+
#include "common/syncjournaldb.h"
67
#include "common/vfs.h"
8+
#include "propagatedownload.h"
79

810
using namespace OCC;
911

@@ -27,50 +29,53 @@ QString HydrationJob::targetFileName() const
2729

2830
void HydrationJob::start()
2931
{
30-
// _vfs->params().journal->getFileRecordsByFileId(_fileId, [this](const SyncJournalFileRecord &record) {
31-
// Q_ASSERT(!_record.isValid());
32-
// _record = record;
33-
// });
34-
// if (!_record.isValid()) {
35-
// Q_EMIT error(tr("Failed to find fileId: %1 in db").arg(QString::fromUtf8(_fileId)));
36-
// Q_EMIT _vfs->needSync();
37-
// return;
38-
// }
39-
// if (!OC_ENSURE(_device->open(QIODevice::WriteOnly))) {
40-
// Q_EMIT error(_device->errorString());
41-
// return;
42-
// }
32+
const auto dbQueryResult = _vfs->params().journal->getFileRecordsByFileId(_fileId, [this](const SyncJournalFileRecord &record) {
33+
Q_ASSERT(!_record.isValid());
34+
_record = record;
35+
});
36+
if (!dbQueryResult || !_record.isValid()) {
37+
Q_EMIT error(tr("Failed to find fileId: %1 in db").arg(QString::fromUtf8(_fileId)));
38+
Q_EMIT _vfs->needSync();
39+
return;
40+
}
41+
if (!_device->open(QIODevice::WriteOnly)) {
42+
Q_EMIT error(_device->errorString());
43+
return;
44+
}
4345

44-
// Q_ASSERT(!_job);
45-
// _job = new GETFileJob(_vfs->params().account, _vfs->params().baseUrl(), _record.path(), _device.get(), {}, {}, 0, this);
46-
// _job->setExpectedContentLength(_record.size());
47-
// _job->setPriority(QNetworkRequest::HighPriority);
48-
// connect(_job, &GETFileJob::finishedSignal, this, [this] {
49-
// QString errorMsg;
50-
// if (_job->reply()->error() != 0 || (_job->httpStatusCode() != 200 && _job->httpStatusCode() != 204)) {
51-
// errorMsg = _job->reply()->errorString();
52-
// }
46+
Q_ASSERT(!_job);
47+
// propagator()->account(),
48+
// propagator()->fullRemotePath(isEncrypted() ? _item->_encryptedFileName : _item->_file),
49+
// &_tmpFile, headers, expectedEtagForResume, _resumeStart, this
50+
_job = new GETFileJob(_vfs->params().account, _vfs->params().remotePath + _record.path(), _device.get(), {}, {}, 0, this);
51+
_job->setExpectedContentLength(_record._fileSize);
52+
//_job->setPriority(QNetworkRequest::HighPriority);
53+
connect(_job, &GETFileJob::finishedSignal, this, [this] {
54+
QString errorMsg;
55+
if (_job->reply()->error() != 0 /*|| (_job->httpStatusCode() != 200 && _job->httpStatusCode() != 204)*/) {
56+
errorMsg = _job->reply()->errorString();
57+
}
5358

54-
// if (_job->contentLength() != -1) {
55-
// const auto size = _job->resumeStart() + _job->contentLength();
56-
// if (size != _record.size()) {
57-
// errorMsg = tr("Unexpected file size transferred. Expected %1 received %2").arg(QString::number(_record.size()), QString::number(size));
58-
// // assume that the local and the remote metadata are out of sync
59-
// Q_EMIT _vfs->needSync();
60-
// }
61-
// }
62-
// if (_job->aborted()) {
63-
// errorMsg = tr("Aborted.");
64-
// }
59+
if (_job->contentLength() != -1) {
60+
const auto size = _job->resumeStart() + _job->contentLength();
61+
if (size != _record._fileSize) {
62+
errorMsg = tr("Unexpected file size transferred. Expected %1 received %2").arg(QString::number(_record._fileSize), QString::number(size));
63+
// assume that the local and the remote metadata are out of sync
64+
Q_EMIT _vfs->needSync();
65+
}
66+
}
67+
// if (_job->aborted()) {
68+
// errorMsg = tr("Aborted.");
69+
// }
6570

66-
// if (!errorMsg.isEmpty()) {
67-
// Q_EMIT error(errorMsg);
68-
// return;
69-
// }
71+
if (!errorMsg.isEmpty()) {
72+
Q_EMIT error(errorMsg);
73+
return;
74+
}
7075

71-
// Q_EMIT finished();
72-
// });
73-
// _job->start();
76+
Q_EMIT finished();
77+
});
78+
_job->start();
7479
}
7580

7681
void HydrationJob::abort()

0 commit comments

Comments
 (0)