reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit bb18915c9a765b3ad6db79cd62944d26701c9614
parent ae39774f819e7493acee31f777fa03a533164a54
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 26 Feb 2017 20:54:17 -0500

task: abort download of subsequent files after a single failure

Diffstat:
Msrc/task.cpp | 20++++++++++++--------
Msrc/task.hpp | 2++
2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/task.cpp b/src/task.cpp @@ -66,6 +66,7 @@ bool InstallTask::start() Download *dl = new Download(src->fullName(), src->url(), opts); dl->onFinish(bind(&InstallTask::saveSource, this, dl, src)); + m_waiting.insert(dl); tx()->threadPool()->push(dl); } @@ -74,12 +75,9 @@ bool InstallTask::start() void InstallTask::saveSource(Download *dl, const Source *src) { - const Path &targetPath = src->targetPath(); - - Path tmpPath(targetPath); - tmpPath[tmpPath.size() - 1] += ".new"; + m_waiting.erase(dl); - m_newFiles.push_back({targetPath, tmpPath}); + const Path &targetPath = src->targetPath(); const auto old = find_if(m_oldFiles.begin(), m_oldFiles.end(), [&](const Registry::File &f) { return f.path == targetPath; }); @@ -87,10 +85,13 @@ void InstallTask::saveSource(Download *dl, const Source *src) if(old != m_oldFiles.end()) m_oldFiles.erase(old); - if(!tx()->saveFile(dl, tmpPath)) { + Path tmpPath(targetPath); + tmpPath[tmpPath.size() - 1] += ".new"; + + if(tx()->saveFile(dl, tmpPath)) + m_newFiles.push_back({targetPath, tmpPath}); + else rollback(); - return; - } } void InstallTask::commit() @@ -147,6 +148,9 @@ void InstallTask::rollback() for(const PathGroup &paths : m_newFiles) FS::removeRecursive(paths.temp); + for(Download *dl : m_waiting) + dl->abort(); + m_fail = true; } diff --git a/src/task.hpp b/src/task.hpp @@ -22,6 +22,7 @@ #include "registry.hpp" #include <set> +#include <unordered_set> #include <vector> class Download; @@ -69,6 +70,7 @@ private: Registry::Entry m_oldEntry; bool m_fail; IndexPtr m_index; // keep in memory + std::unordered_set<Download *> m_waiting; std::vector<Registry::File> m_oldFiles; std::vector<PathGroup> m_newFiles; };