reapack

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

commit a913bc7607cb154319ff59b28a1aa13252255dac
parent 2156cf690ae00e165bd063811432055005b79912
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sat, 12 Dec 2015 19:16:30 -0800

wait until transactions are commited before writing to the registry

Diffstat:
Msrc/transaction.cpp | 31++++++++++++++++---------------
Msrc/transaction.hpp | 8+++++---
2 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -95,16 +95,15 @@ void Transaction::run() try { tr->install(entry.first->lastVersion()); - tr->onFinish([=] { + tr->onCommit([=] { if(regEntry.status == Registry::UpdateAvailable) m_updates.push_back(entry); else m_new.push_back(entry); m_registry->push(pkg); - - finish(); }); + tr->onFinish(bind(&Transaction::finish, this)); m_transactions.push_back(tr); } @@ -155,7 +154,7 @@ void Transaction::finish() if(!m_isCancelled) { for(PackageTransaction *tr : m_transactions) - tr->apply(); + tr->commit(); } m_onFinish(); @@ -213,7 +212,7 @@ void PackageTransaction::saveSource(Download *dl, Source *src) Path tmpPath = targetPath; tmpPath[tmpPath.size() - 1] += ".new"; - m_files.push({tmpPath, targetPath}); + m_files.push_back({tmpPath, targetPath}); const Path path = m_transaction->prefixPath(tmpPath); @@ -241,29 +240,31 @@ void PackageTransaction::cancel() rollback(); } -void PackageTransaction::apply() +void PackageTransaction::commit() { - while(!m_files.empty()) { - const PathPair paths = m_files.front(); - m_files.pop(); - + for(const PathPair &paths : m_files) { const string tempPath = m_transaction->prefixPath(paths.first).join(); const string targetPath = m_transaction->prefixPath(paths.second).join(); - if(rename(tempPath.c_str(), targetPath.c_str())) + if(rename(tempPath.c_str(), targetPath.c_str())) { m_transaction->addError(strerror(errno), targetPath); + rollback(); + return; + } } + + m_files.clear(); + m_onCommit(); } void PackageTransaction::rollback() { - while(!m_files.empty()) { - const PathPair paths = m_files.front(); - m_files.pop(); - + for(const PathPair &paths : m_files) { const string tempPath = m_transaction->prefixPath(paths.first).join(); if(remove(tempPath.c_str())) m_transaction->addError(strerror(errno), tempPath); } + + m_files.clear(); } diff --git a/src/transaction.hpp b/src/transaction.hpp @@ -8,7 +8,7 @@ #include "remote.hpp" #include <boost/signals2.hpp> -#include <queue> +#include <vector> class PackageTransaction; @@ -84,10 +84,11 @@ public: PackageTransaction(Transaction *parent); + void onCommit(const Callback &callback) { m_onCommit.connect(callback); } void onFinish(const Callback &callback) { m_onFinish.connect(callback); } void install(Version *ver); - void apply(); + void commit(); void cancel(); private: @@ -101,8 +102,9 @@ private: Transaction *m_transaction; bool m_isCancelled; std::vector<Download *> m_remaining; - std::queue<PathPair> m_files; + std::vector<PathPair> m_files; + Signal m_onCommit; Signal m_onFinish; };