commit 342a718340bcfd2d71e87767c8ca8e458c3377e2
parent a2b0c114d7687f1d1acc8a313aad901f4dc86fda
Author: cfillion <cfillion@users.noreply.github.com>
Date: Thu, 14 Jan 2016 14:33:37 -0800
clear up the download finish/destroy event mess a little bit
Diffstat:
3 files changed, 33 insertions(+), 25 deletions(-)
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -109,7 +109,7 @@ void ReaPack::synchronize()
return;
for(const Remote &remote : remotes)
- t->fetch(remote);
+ t->synchronize(remote);
}
void ReaPack::importRemote()
@@ -173,7 +173,7 @@ void ReaPack::importRemote()
Transaction *t = createTransaction();
if(t)
- t->fetch(remote);
+ t->synchronize(remote);
}
void ReaPack::manageRemotes()
@@ -196,11 +196,6 @@ Transaction *ReaPack::createTransaction()
m_progress->setTransaction(m_transaction);
m_progress->show();
- m_transaction->onReady([=] {
- // TODO: display the package list with the changelogs
- m_transaction->run();
- });
-
m_transaction->onFinish([=] {
if(m_transaction->isCancelled())
return;
diff --git a/src/transaction.cpp b/src/transaction.cpp
@@ -28,11 +28,21 @@
using namespace std;
Transaction::Transaction(Registry *reg, const Path &root)
- : m_registry(reg), m_root(root), m_isCancelled(false), m_hasConflicts(false)
+ : m_registry(reg), m_root(root), m_step(Unknown),
+ m_isCancelled(false), m_hasConflicts(false)
{
m_dbPath = m_root + "ReaPack";
- m_queue.onDone(bind(&Transaction::finish, this));
+ m_queue.onDone([=](void *) {
+ switch(m_step) {
+ case Synchronize:
+ updateAll();
+ break;
+ default:
+ finish();
+ break;
+ }
+ });
RecursiveCreateDirectory(m_dbPath.join().c_str(), 0);
}
@@ -46,16 +56,14 @@ Transaction::~Transaction()
delete db;
}
-void Transaction::fetch(const Remote &remote)
+void Transaction::synchronize(const Remote &remote)
{
+ m_step = Synchronize;
+
Download *dl = new Download(remote.name(), remote.url());
dl->onFinish(bind(&Transaction::saveDatabase, this, dl));
m_queue.push(dl);
-
- // execute prepare after the download is deleted, in case finish is called
- // the queue will also not contain the download anymore
- dl->onFinish(bind(&Transaction::prepare, this));
}
void Transaction::saveDatabase(Download *dl)
@@ -75,11 +83,8 @@ void Transaction::saveDatabase(Download *dl)
}
}
-void Transaction::prepare()
+void Transaction::updateAll()
{
- if(!m_queue.idle())
- return;
-
for(Database *db : m_databases) {
for(Package *pkg : db->packages()) {
Registry::QueryResult entry = m_registry->query(pkg);
@@ -103,11 +108,13 @@ void Transaction::prepare()
if(m_packages.empty() || m_hasConflicts)
finish();
else
- m_onReady();
+ install();
}
-void Transaction::run()
+void Transaction::install()
{
+ m_step = Install;
+
for(const PackageEntry &entry : m_packages) {
Version *ver = entry.first;
const Registry::QueryResult regEntry = entry.second;
diff --git a/src/transaction.hpp b/src/transaction.hpp
@@ -46,12 +46,11 @@ public:
Transaction(Registry *reg, const Path &root);
~Transaction();
- void onReady(const Callback &callback) { m_onReady.connect(callback); }
void onFinish(const Callback &callback) { m_onFinish.connect(callback); }
void onDestroy(const Callback &callback) { m_onDestroy.connect(callback); }
- void fetch(const Remote &);
- void run();
+ void synchronize(const Remote &);
+ void install();
void cancel();
bool isCancelled() const { return m_isCancelled; }
@@ -62,9 +61,16 @@ public:
const ErrorList &errors() const { return m_errors; }
private:
+ enum Step
+ {
+ Unknown,
+ Synchronize,
+ Install,
+ };
+
friend Task;
- void prepare();
+ void updateAll();
void finish();
void saveDatabase(Download *);
@@ -78,6 +84,7 @@ private:
Path m_root;
Path m_dbPath;
+ Step m_step;
bool m_isCancelled;
DatabaseList m_databases;
@@ -91,7 +98,6 @@ private:
std::set<Path> m_files;
bool m_hasConflicts;
- Signal m_onReady;
Signal m_onFinish;
Signal m_onDestroy;
};