commit 6e18d7a69ce4a2322a50a1ca2a4f1b5a023b275b
parent 3449d6106f42b6ed763e1c2b32da76092a117db5
Author: cfillion <cfillion@users.noreply.github.com>
Date: Fri, 15 Sep 2017 00:43:40 -0400
don't unregister scripts when disabling a repository – synchronize repository when enabling only if autoinstall setting is on
Diffstat:
12 files changed, 71 insertions(+), 91 deletions(-)
diff --git a/src/about.cpp b/src/about.cpp
@@ -490,15 +490,15 @@ void AboutIndexDelegate::install()
}
}
- Transaction *tx = g_reapack->setupTransaction();
+ if(Transaction *tx = g_reapack->setupTransaction())
+ tx->synchronize(remote, choice == INSTALL_ALL);
- if(!tx)
- return;
-
- g_reapack->setRemoteEnabled(remote);
+ if(!remote.isEnabled()) {
+ remote.setEnabled(true);
+ g_reapack->addSetRemote(remote);
+ }
- tx->synchronize(remote, choice == INSTALL_ALL);
- tx->runTasks();
+ g_reapack->commitConfig();
}
AboutPackageDelegate::AboutPackageDelegate(
diff --git a/src/api_repo.cpp b/src/api_repo.cpp
@@ -47,20 +47,13 @@ R"(Add or modify a repository. Set url to nullptr (or empty string in Lua) to ke
autoInstall: usually set to 2 (obey user setting).)",
{
try {
- const Remote &existing = g_reapack->remote(name);
-
- Remote remote(existing);
+ Remote remote = g_reapack->remote(name);
remote.setName(name);
- remote.setUrl(url && strlen(url) > 0 ? url : existing.url());
+ if(url && strlen(url) > 0)
+ remote.setUrl(url);
+ remote.setEnabled(enable);
remote.setAutoInstall(boost::lexical_cast<tribool>(autoInstall));
-
- if(existing.isProtected() && remote.url() != existing.url()) {
- if(errorOut)
- snprintf(errorOut, errorOut_sz, "cannot change the URL of a protected repository");
- return false;
- }
- if(!g_reapack->addSetRemote(remote, enable))
- return false;
+ g_reapack->addSetRemote(remote);
}
catch(const reapack_error &e) {
if(errorOut)
diff --git a/src/import.cpp b/src/import.cpp
@@ -228,8 +228,7 @@ void Import::processQueue()
bool Import::import(const ImportData &data)
{
- if(!g_reapack->addSetRemote(data.remote))
- return false;
+ g_reapack->addSetRemote(data.remote);
FS::write(Index::pathFor(data.remote.name()), data.contents);
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -617,6 +617,8 @@ bool Manager::apply()
if(!tx)
return false;
+ // syncList is the list of repos to synchronize for autoinstall
+ // (global or local setting)
set<Remote> syncList;
if(m_autoInstall) {
@@ -642,22 +644,20 @@ bool Manager::apply()
continue;
if(mods.enable) {
- g_reapack->setRemoteEnabled(remote, *mods.enable);
-
- if(*mods.enable)
- syncList.insert(remote);
- else
- syncList.erase(remote);
+ remote.setEnabled(*mods.enable);
+ syncList.erase(remote);
}
+
if(mods.autoInstall) {
remote.setAutoInstall(*mods.autoInstall);
- g_reapack->config()->remotes.add(remote);
const bool isEnabled = mods.enable.value_or(remote.isEnabled());
if(isEnabled && *mods.autoInstall)
syncList.insert(remote);
}
+
+ g_reapack->addSetRemote(remote);
}
for(const Remote &remote : m_uninstall) {
@@ -668,10 +668,10 @@ bool Manager::apply()
for(const Remote &remote : syncList)
tx->synchronize(remote);
- tx->onFinish(bind(&Config::write, g_reapack->config()));
- tx->runTasks();
reset();
+ g_reapack->commitConfig();
+
return true;
}
diff --git a/src/manager.hpp b/src/manager.hpp
@@ -23,7 +23,6 @@
#include <boost/logic/tribool.hpp>
#include <boost/optional.hpp>
#include <map>
-#include <set>
class ListView;
class Menu;
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -173,48 +173,18 @@ void ReaPack::synchronizeAll()
tx->runTasks();
}
-bool ReaPack::addSetRemote(const Remote &remote, const bool enable)
+void ReaPack::addSetRemote(const Remote &remote)
{
- if(remote.isEnabled() != enable) {
- if(Transaction *tx = setupTransaction()) {
- setRemoteEnabled(remote, enable); // adds the new remote to the list
+ if(remote.isEnabled() && remote.autoInstall(m_config->install.autoInstall)) {
+ const Remote &previous = m_config->remotes.get(remote.name());
- if(enable)
+ if(!previous || !previous.isEnabled()) {
+ if(Transaction *tx = setupTransaction())
tx->synchronize(remote);
-
- return true;
}
- else
- return false;
}
m_config->remotes.add(remote);
-
- if(m_config->install.autoInstall) {
- if(Transaction *tx = setupTransaction()) {
- tx->synchronize(remote);
- return true;
- }
- }
-
- return true;
-}
-
-void ReaPack::setRemoteEnabled(const Remote &remote, const bool enable)
-{
- assert(m_tx);
-
- Remote copy(remote);
- copy.setEnabled(enable);
-
- m_tx->registerAll(copy);
-
- m_tx->onFinish([=] {
- if(m_tx->isCancelled())
- return;
-
- m_config->remotes.add(copy);
- });
}
void ReaPack::uninstall(const Remote &remote)
@@ -385,6 +355,7 @@ void ReaPack::teardownTransaction()
void ReaPack::commitConfig()
{
if(m_tx) {
+ m_tx->receipt()->setIndexChanged(); // force browser refresh
m_tx->onFinish(bind(&ReaPack::refreshManager, this));
m_tx->onFinish(bind(&Config::write, m_config));
m_tx->runTasks();
diff --git a/src/reapack.hpp b/src/reapack.hpp
@@ -65,8 +65,6 @@ public:
void setupAPI(const APIFunc *func);
void synchronizeAll();
- bool addSetRemote(const Remote &, bool enable = true);
- void setRemoteEnabled(const Remote &, bool enable = true);
void uninstall(const Remote &);
void importRemote();
@@ -78,6 +76,7 @@ public:
void refreshManager();
void refreshBrowser();
+ void addSetRemote(const Remote &);
Remote remote(const std::string &name) const;
Transaction *setupTransaction();
diff --git a/src/remote.cpp b/src/remote.cpp
@@ -114,10 +114,20 @@ void Remote::setUrl(const string &url)
{
if(!validateUrl(url))
throw reapack_error("invalid url");
+ else if(m_protected)
+ throw reapack_error("cannot change the URL of a protected repository");
else
m_url = url;
}
+bool Remote::autoInstall(bool fallback) const
+{
+ if(boost::logic::indeterminate(m_autoInstall))
+ return fallback;
+ else
+ return m_autoInstall;
+}
+
string Remote::toString() const
{
ostringstream out;
diff --git a/src/remote.hpp b/src/remote.hpp
@@ -50,6 +50,7 @@ public:
void setAutoInstall(const tribool &autoInstall) { m_autoInstall = autoInstall; }
tribool autoInstall() const { return m_autoInstall; }
+ bool autoInstall(bool fallback) const;
void protect() { m_protected = true; }
bool isProtected() const { return m_protected; }
diff --git a/src/transaction.cpp b/src/transaction.cpp
@@ -59,11 +59,7 @@ void Transaction::synchronize(const Remote &remote,
m_syncedRemotes.insert(remote.name());
InstallOpts opts = g_reapack->config()->install;
-
- if(forceAutoInstall)
- opts.autoInstall = *forceAutoInstall;
- else if(!boost::logic::indeterminate(remote.autoInstall()))
- opts.autoInstall = remote.autoInstall();
+ opts.autoInstall = remote.autoInstall(forceAutoInstall.value_or(opts.autoInstall));
fetchIndex(remote, true, [=] (const IndexPtr &ri) {
for(const Package *pkg : ri->packages())
@@ -183,17 +179,6 @@ void Transaction::install(const Version *ver,
m_nextQueue.push(make_shared<InstallTask>(ver, pin, oldEntry, reader, this));
}
-void Transaction::registerAll(const Remote &remote)
-{
- const vector<Registry::Entry> &entries = m_registry.getEntries(remote.name());
-
- for(const auto &entry : entries)
- registerAll(remote.isEnabled(), entry);
-
- if(!remote.isEnabled())
- inhibit(remote);
-}
-
void Transaction::setPinned(const Registry::Entry &entry, const bool pinned)
{
m_nextQueue.push(make_shared<PinTask>(entry, pinned, this));
@@ -261,11 +246,7 @@ bool Transaction::runTasks()
return false;
}
- // we're done!
- m_registry.commit();
- registerQueued();
-
- finish();
+ finish(); // we're done!
return true;
}
@@ -291,6 +272,9 @@ bool Transaction::commitTasks()
void Transaction::finish()
{
+ m_registry.commit();
+ registerQueued();
+
m_onFinish();
m_cleanupHandler();
}
diff --git a/src/transaction.hpp b/src/transaction.hpp
@@ -59,7 +59,6 @@ public:
void setPinned(const Registry::Entry &, bool pinned);
void uninstall(const Remote &);
void uninstall(const Registry::Entry &);
- void registerAll(const Remote &);
void exportArchive(const std::string &path);
bool runTasks();
diff --git a/test/remote.cpp b/test/remote.cpp
@@ -112,7 +112,7 @@ TEST_CASE("set invalid values", M) {
}
}
-TEST_CASE("valide remote urls", M) {
+TEST_CASE("valid remote urls", M) {
Remote remote;
SECTION("uppercase")
@@ -157,6 +157,31 @@ TEST_CASE("protect remote", M) {
remote.protect();
REQUIRE(remote.isProtected());
+
+ try {
+ remote.setUrl("https://google.com");
+ FAIL();
+ }
+ catch(const reapack_error &e) {
+ REQUIRE(string(e.what()) == "cannot change the URL of a protected repository");
+ }
+}
+
+TEST_CASE("autoinstall remote", M) {
+ Remote remote;
+ REQUIRE_FALSE(remote.autoInstall());
+ REQUIRE(remote.autoInstall(true));
+ REQUIRE_FALSE(remote.autoInstall(false));
+
+ remote.setAutoInstall(true);
+ REQUIRE(remote.autoInstall());
+ REQUIRE(remote.autoInstall(true));
+ REQUIRE(remote.autoInstall(false));
+
+ remote.setAutoInstall(false);
+ REQUIRE_FALSE(remote.autoInstall());
+ REQUIRE_FALSE(remote.autoInstall(true));
+ REQUIRE_FALSE(remote.autoInstall(false));
}
TEST_CASE("add remotes to list", M) {