Upload: Simplify 'finished' flag

* Sometimes there was 'finished' and '_finished'
* Make each done() call automatically set _finished to true
This commit is contained in:
Christian Kamm 2018-03-27 10:39:58 +02:00 committed by Camila San
parent 5e2270bd57
commit a2675b559b
No known key found for this signature in database
GPG key ID: 7A4A6121E88E2AD4
5 changed files with 22 additions and 31 deletions

View file

@ -156,7 +156,7 @@ class PropagateItemJob : public PropagatorJob
{
Q_OBJECT
protected:
void done(SyncFileItem::Status status, const QString &errorString = QString());
virtual void done(SyncFileItem::Status status, const QString &errorString = QString());
bool checkForProblemsWithShared(int httpStatusCode, const QString &msg);

View file

@ -529,7 +529,6 @@ void PropagateUploadFileCommon::slotPollFinished()
propagator()->_activeJobList.removeOne(this);
if (job->_item->_status != SyncFileItem::Success) {
_finished = true;
done(job->_item->_status, job->_item->_errorString);
return;
}
@ -537,6 +536,12 @@ void PropagateUploadFileCommon::slotPollFinished()
finalize();
}
void PropagateUploadFileCommon::done(SyncFileItem::Status status, const QString &errorString)
{
_finished = true;
PropagateItemJob::done(status, errorString);
}
void PropagateUploadFileCommon::checkResettingErrors()
{
if (_item->_httpErrorCode == 412
@ -622,7 +627,6 @@ void PropagateUploadFileCommon::abort(PropagatorJob::AbortType abortType)
// This function is used whenever there is an error occuring and jobs might be in progress
void PropagateUploadFileCommon::abortWithError(SyncFileItem::Status status, const QString &error)
{
_finished = true;
abort(AbortType::Synchronous);
done(status, error);
}
@ -671,9 +675,6 @@ QMap<QByteArray, QByteArray> PropagateUploadFileCommon::headers()
void PropagateUploadFileCommon::finalize()
{
qDebug() << "Finalizing the upload. Check later if this is encrypted";
_finished = true;
// Update the quota, if known
auto quotaIt = propagator()->_folderQuota.find(QFileInfo(_item->_file).path());
if (quotaIt != propagator()->_folderQuota.end())

View file

@ -279,6 +279,8 @@ private slots:
void slotPollFinished();
protected:
void done(SyncFileItem::Status status, const QString &errorString = QString()) override;
/**
* Prepares the abort e.g. connects proper signals and slots
* to the subjobs to abort asynchronously

View file

@ -276,6 +276,7 @@ void PropagateUploadFileNG::startNextChunk()
if (_currentChunkSize == 0) {
Q_ASSERT(_jobs.isEmpty()); // There should be no running job anymore
_finished = true;
// Finish with a MOVE
// If we changed the file name, we must store the changed filename in the remote folder, not the original one.
QString destination = QDir::cleanPath(propagator()->account()->url().path() + QLatin1Char('/')
@ -394,19 +395,12 @@ void PropagateUploadFileNG::slotPutFinished()
<< propagator()->_chunkSize << "bytes";
}
bool finished = _sent == _fileToUpload._size;
_finished = _sent == _item->_size;
// Check if the file still exists
/* Check if the file still exists,
* but we could be operating in a temporary file, so check both if
* the file to upload is different than the file on disk
*/
const QString fileToUploadPath = _fileToUpload._path;
const QString fullFilePath(propagator()->getFilePath(_item->_file));
bool fileExists = fileToUploadPath == fullFilePath ? FileSystem::fileExists(fullFilePath)
: (FileSystem::fileExists(fileToUploadPath) && FileSystem::fileExists(fullFilePath));
if (!fileExists) {
if (!finished) {
if (!FileSystem::fileExists(fullFilePath)) {
if (!_finished) {
abortWithError(SyncFileItem::SoftError, tr("The local file was removed during sync."));
return;
} else {
@ -417,13 +411,13 @@ void PropagateUploadFileNG::slotPutFinished()
// Check whether the file changed since discovery - this acts on the original file.
if (!FileSystem::verifyFileUnchanged(fullFilePath, _item->_size, _item->_modtime)) {
propagator()->_anotherSyncNeeded = true;
if (!finished) {
if (!_finished) {
abortWithError(SyncFileItem::SoftError, tr("Local file changed during sync."));
return;
}
}
if (!finished) {
if (!_finished) {
// Deletes an existing blacklist entry on successful chunk upload
if (_item->_hasBlacklistEntry) {
propagator()->_journal->wipeErrorBlacklistEntry(_item->_file);

View file

@ -213,12 +213,12 @@ void PropagateUploadFileV1::slotPutFinished()
_item->_httpErrorCode = job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
// The server needs some time to process the request and provide us with a poll URL
if (_item->_httpErrorCode == 202) {
_finished = true;
QString path = QString::fromUtf8(job->reply()->rawHeader("OC-Finish-Poll"));
if (path.isEmpty()) {
done(SyncFileItem::NormalError, tr("Poll URL missing"));
return;
}
_finished = true;
startPollJob(path);
return;
}
@ -233,19 +233,15 @@ void PropagateUploadFileV1::slotPutFinished()
// yet, the upload can be stopped and an error can be displayed, because
// the server hasn't registered the new file yet.
QByteArray etag = getEtagFromReply(job->reply());
bool finished = etag.length() > 0;
_finished = etag.length() > 0;
/* Check if the file still exists,
* but we could be operating in a temporary file, so check both if
* the file to upload is different than the file on disk
*/
const QString fileToUploadPath = _fileToUpload._path;
const QString fullFilePath(propagator()->getFilePath(_item->_file));
bool fileExists = fileToUploadPath == fullFilePath ? FileSystem::fileExists(fullFilePath)
: (FileSystem::fileExists(fileToUploadPath) && FileSystem::fileExists(fullFilePath));
if (!fileExists) {
if (!finished) {
if (!FileSystem::fileExists(fullFilePath)) {
if (!_finished) {
abortWithError(SyncFileItem::SoftError, tr("The local file was removed during sync."));
return;
} else {
@ -256,7 +252,7 @@ void PropagateUploadFileV1::slotPutFinished()
// Check whether the file changed since discovery. the file check here is the original and not the temprary.
if (!FileSystem::verifyFileUnchanged(fullFilePath, _item->_size, _item->_modtime)) {
propagator()->_anotherSyncNeeded = true;
if (!finished) {
if (!_finished) {
abortWithError(SyncFileItem::SoftError, tr("Local file changed during sync."));
// FIXME: the legacy code was retrying for a few seconds.
// and also checking that after the last chunk, and removed the file in case of INSTRUCTION_NEW
@ -264,14 +260,13 @@ void PropagateUploadFileV1::slotPutFinished()
}
}
if (!finished) {
if (!_finished) {
// Proceed to next chunk.
if (_currentChunk >= _chunkCount) {
if (!_jobs.empty()) {
// just wait for the other job to finish.
return;
}
_finished = true;
done(SyncFileItem::NormalError, tr("The server did not acknowledge the last chunk. (No e-tag was present)"));
return;
}
@ -301,9 +296,8 @@ void PropagateUploadFileV1::slotPutFinished()
startNextChunk();
return;
}
// the following code only happens after all chunks were uploaded.
_finished = true;
// the file id should only be empty for new files up- or downloaded
QByteArray fid = job->reply()->rawHeader("OC-FileID");
if (!fid.isEmpty()) {