Skip to content

Commit 22187f2

Browse files
authored
Remove invalid assert, add documentation, and fix uses (owncloud#12095)
A response timestamp can be missing for multiple reasons: aborted job before a header came in, many possible network errors, and just missing in a response. So instead of an assert over all these cases, handle the absence when it is about to be used. This was already done in some cases.
1 parent f5536c6 commit 22187f2

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/gui/scheduling/etagwatcher.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ void ETagWatcher::startOC10EtagJob(Folder *f)
105105
connect(requestEtagJob, &RequestEtagJob::finishedSignal, this, [requestEtagJob, f, this] {
106106
if (requestEtagJob->httpStatusCode() == 207) {
107107
if (OC_ENSURE_NOT(requestEtagJob->etag().isEmpty())) {
108-
f->accountState()->tagLastSuccessfullETagRequest(requestEtagJob->responseQTimeStamp());
108+
auto lastResponse = requestEtagJob->responseQTimeStamp();
109+
if (!lastResponse.isValid()) {
110+
// If the responose had no valid "Date" header, use "now", as the job just finished.
111+
lastResponse = QDateTime::currentDateTimeUtc();
112+
}
113+
f->accountState()->tagLastSuccessfullETagRequest(lastResponse);
109114
updateEtag(f, requestEtagJob->etag());
110115
} else {
111116
qCWarning(lcEtagWatcher) << "Invalid empty etag received for" << f->displayName() << f->path() << requestEtagJob;

src/libsync/abstractnetworkjob.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ void AbstractNetworkJob::slotFinished()
238238

239239
QByteArray AbstractNetworkJob::responseTimestamp() const
240240
{
241-
OC_ASSERT(!_responseTimestamp.isEmpty() || _aborted || (reply() && reply()->error() == QNetworkReply::RemoteHostClosedError));
242241
return _responseTimestamp;
243242
}
244243

src/libsync/abstractnetworkjob.h

+11
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,18 @@ class OWNCLOUDSYNC_EXPORT AbstractNetworkJob : public QObject
7474
void setForceIgnoreCredentialFailure(bool ignore);
7575
bool ignoreCredentialFailure() const;
7676

77+
/**
78+
* @brief Returns the timestamp from the reply
79+
*
80+
* @return Empty if the job was aborted, or an error occurred and no response was received.
81+
* Otherwise the timestamp from the reply header. Note that the timestamp might be
82+
* absent if the reply didn't contain one.
83+
*/
7784
QByteArray responseTimestamp() const;
85+
/**
86+
* See responseTimestamp(), now converted to a QDateTime. If there was no response timestamp,
87+
* return an invalid `QDateTime`.
88+
*/
7889
QDateTime responseQTimeStamp() const;
7990

8091
int httpStatusCode() const;

src/libsync/discoveryphase.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,14 @@ void DiscoverySingleDirectoryJob::lsJobFinishedWithoutErrorSlot()
422422
deleteLater();
423423
return;
424424
}
425-
Q_EMIT etag(_firstEtag, _proFindJob->responseQTimeStamp());
425+
426+
auto lastResponse = _proFindJob->responseQTimeStamp();
427+
if (!lastResponse.isValid()) {
428+
// If the responose had no valid "Date" header, use "now", as the job just finished.
429+
lastResponse = QDateTime::currentDateTimeUtc();
430+
}
431+
432+
Q_EMIT etag(_firstEtag, lastResponse);
426433
Q_EMIT finished(_results);
427434
deleteLater();
428435
}

0 commit comments

Comments
 (0)