33
44#include " hydrationjob.h"
55
6+ #include " common/syncjournaldb.h"
67#include " common/vfs.h"
8+ #include " propagatedownload.h"
79
810using namespace OCC ;
911
@@ -27,50 +29,53 @@ QString HydrationJob::targetFileName() const
2729
2830void 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
7681void HydrationJob::abort ()
0 commit comments