bool PollJob::finished() { QNetworkReply::NetworkError err = reply()->error(); if (err != QNetworkReply::NoError) { _item->_httpErrorCode = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); _item->_status = classifyError(err, _item->_httpErrorCode); _item->_errorString = reply()->errorString(); if (reply()->hasRawHeader("OC-ErrorString")) { _item->_errorString = reply()->rawHeader("OC-ErrorString"); } if (_item->_status == SyncFileItem::FatalError || _item->_httpErrorCode >= 400) { if (_item->_status != SyncFileItem::FatalError && _item->_httpErrorCode != 503) { SyncJournalDb::PollInfo info; info._file = _item->_file; // no info._url removes it from the database _journal->setPollInfo(info); _journal->commit("remove poll info"); } emit finishedSignal(); return true; } start(); return false; } bool ok = false; QByteArray jsonData = reply()->readAll().trimmed(); qDebug() << Q_FUNC_INFO << ">" << jsonData << "<" << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); QVariantMap status = QtJson::parse(QString::fromUtf8(jsonData), ok).toMap(); if (!ok || status.isEmpty()) { _item->_errorString = tr("Invalid JSON reply from the poll URL"); _item->_status = SyncFileItem::NormalError; emit finishedSignal(); return true; } if (status["unfinished"].isValid()) { start(); return false; } _item->_errorString = status["error"].toString(); _item->_status = _item->_errorString.isEmpty() ? SyncFileItem::Success : SyncFileItem::NormalError; _item->_fileId = status["fileid"].toByteArray(); _item->_etag = status["etag"].toByteArray(); _item->_responseTimeStamp = responseTimestamp(); SyncJournalDb::PollInfo info; info._file = _item->_file; // no info._url removes it from the database _journal->setPollInfo(info); _journal->commit("remove poll info"); emit finishedSignal(); return true; }
void PropagateUploadFileNG::slotMoveJobFinished() { propagator()->_activeJobList.removeOne(this); auto job = qobject_cast<MoveJob *>(sender()); slotJobDestroyed(job); // remove it from the _jobs list QNetworkReply::NetworkError err = job->reply()->error(); _item->_httpErrorCode = job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (err != QNetworkReply::NoError) { commonErrorHandling(job); return; } if (_item->_httpErrorCode != 201 && _item->_httpErrorCode != 204) { abortWithError(SyncFileItem::NormalError, tr("Unexpected return code from server (%1)").arg(_item->_httpErrorCode)); return; } QByteArray fid = job->reply()->rawHeader("OC-FileID"); if (fid.isEmpty()) { qCWarning(lcPropagateUpload) << "Server did not return a OC-FileID" << _item->_file; abortWithError(SyncFileItem::NormalError, tr("Missing File ID from server")); return; } else { // the old file id should only be empty for new files uploaded if (!_item->_fileId.isEmpty() && _item->_fileId != fid) { qCWarning(lcPropagateUpload) << "File ID changed!" << _item->_fileId << fid; } _item->_fileId = fid; } _item->_etag = getEtagFromReply(job->reply()); ; if (_item->_etag.isEmpty()) { qCWarning(lcPropagateUpload) << "Server did not return an ETAG" << _item->_file; abortWithError(SyncFileItem::NormalError, tr("Missing ETag from server")); return; } _item->_responseTimeStamp = job->responseTimestamp(); finalize(); }