diff --git a/libs/linglong/src/linglong/package_manager/package_manager.cpp b/libs/linglong/src/linglong/package_manager/package_manager.cpp index 4e3c7f301..e56bd2244 100644 --- a/libs/linglong/src/linglong/package_manager/package_manager.cpp +++ b/libs/linglong/src/linglong/package_manager/package_manager.cpp @@ -124,10 +124,13 @@ PackageManager::PackageManager(linglong::repo::OSTreeRepo &repo, return; } - for (auto it = taskList.begin(); it != taskList.end(); ++it) { + for (auto it = taskList.begin(); it != taskList.end();) { auto *task = *it; if (!task->getJob().has_value() || task->state() != linglong::api::types::v1::State::Queued) { + qInfo() << "Remove" << task->taskID() + << "from task queue, it has no job or State is not Queued"; + it = this->taskList.erase(it); continue; } this->runningTaskObjectPath = task->taskObjectPath(); @@ -142,9 +145,9 @@ PackageManager::PackageManager(linglong::repo::OSTreeRepo &repo, task->message(), task->getPercentage()); this->runningTaskObjectPath = ""; - auto nextIt = this->taskList.erase(it); + it = this->taskList.erase(it); task->deleteLater(); - if (nextIt != taskList.end()) { + if (it != taskList.end()) { qInfo() << "Switch to next available task"; Q_EMIT this->TaskListChanged("", "TaskSwitch"); } diff --git a/libs/linglong/src/linglong/package_manager/package_task.h b/libs/linglong/src/linglong/package_manager/package_task.h index 4fa98db20..d0a85b19a 100644 --- a/libs/linglong/src/linglong/package_manager/package_task.h +++ b/libs/linglong/src/linglong/package_manager/package_task.h @@ -94,7 +94,11 @@ class PackageTask : public QObject, protected QDBusContext auto cancellable() noexcept { return m_cancelFlag; } - bool isRefExist(const QString &ref) const noexcept { return m_refs.contains(ref); } + bool isRefExist(const QString &ref) const noexcept + { + return m_refs.contains(ref) + && this->m_state != static_cast(linglong::api::types::v1::State::Canceled); + } auto getJob() { return m_job; }