diff options
author | Piotr Mrówczyński <mrow4a@yahoo.com> | 2017-01-26 12:03:22 +0300 |
---|---|---|
committer | Jocelyn Turcotte <jturcotte@woboq.com> | 2017-01-26 12:03:22 +0300 |
commit | c3ae5123cbaca1b40cd15486d145dd44b752f761 (patch) | |
tree | 3b7b43a0be4cf1bc5ec8c54f352ceecfc5ec769d /src/libsync/owncloudpropagator.cpp | |
parent | a1a5111a8ac36e600750803e11480719150068f8 (diff) |
Delete finished propagation jobs in PropagateDirectory #5269 (#5400)
Diffstat (limited to 'src/libsync/owncloudpropagator.cpp')
-rw-r--r-- | src/libsync/owncloudpropagator.cpp | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/libsync/owncloudpropagator.cpp b/src/libsync/owncloudpropagator.cpp index 22174df50..6a041d52d 100644 --- a/src/libsync/owncloudpropagator.cpp +++ b/src/libsync/owncloudpropagator.cpp @@ -588,17 +588,12 @@ OwncloudPropagator *PropagatorJob::propagator() const PropagatorJob::JobParallelism PropagateDirectory::parallelism() { // If any of the non-finished sub jobs is not parallel, we have to wait - - // FIXME! we should probably cache this result - - if (_firstJob && _firstJob->_state != Finished) { - if (_firstJob->parallelism() != FullParallelism) - return WaitForFinished; + if (_firstJob && _firstJob->parallelism() != FullParallelism) { + return WaitForFinished; } - // FIXME: use the cached value of finished job for (int i = 0; i < _subJobs.count(); ++i) { - if (_subJobs.at(i)->_state != Finished && _subJobs.at(i)->parallelism() != FullParallelism) { + if (_subJobs.at(i)->parallelism() != FullParallelism) { return WaitForFinished; } } @@ -629,15 +624,8 @@ bool PropagateDirectory::scheduleNextJob() return false; } - // cache the value of first unfinished subjob bool stopAtDirectory = false; - int i = _firstUnfinishedSubJob; - int subJobsCount = _subJobs.count(); - while (i < subJobsCount && _subJobs.at(i)->_state == Finished) { - _firstUnfinishedSubJob = ++i; - } - - for (int i = _firstUnfinishedSubJob; i < subJobsCount; ++i) { + for (int i = 0; i < _subJobs.size(); ++i) { if (_subJobs.at(i)->_state == Finished) { continue; } @@ -665,8 +653,22 @@ bool PropagateDirectory::scheduleNextJob() void PropagateDirectory::slotSubJobFinished(SyncFileItem::Status status) { + PropagatorJob *subJob = static_cast<PropagatorJob *>(sender()); + + // Delete the job and remove it from our list of jobs. + subJob->deleteLater(); + bool wasFirstJob = false; + if (subJob == _firstJob.data()) { + wasFirstJob = true; + _firstJob.reset(); + } else { + int i = _subJobs.indexOf(subJob); + Q_ASSERT(i >= 0); + _subJobs.remove(i); + } + if (status == SyncFileItem::FatalError || - (sender() == _firstJob.data() && status != SyncFileItem::Success && status != SyncFileItem::Restoration)) { + (wasFirstJob && status != SyncFileItem::Success && status != SyncFileItem::Restoration)) { abort(); _state = Finished; emit finished(status); @@ -675,16 +677,10 @@ void PropagateDirectory::slotSubJobFinished(SyncFileItem::Status status) _hasError = status; } _runningNow--; - _jobsFinished++; - - int totalJobs = _subJobs.count(); - if (_firstJob) { - totalJobs++; - } // We finished processing all the jobs // check if we finished - if (_jobsFinished >= totalJobs) { + if (!_firstJob && _subJobs.isEmpty()) { Q_ASSERT(!_runningNow); // how can we be finished if there are still jobs running now finalize(); } else { |