commit 7e07ce80fc7fd879be8f6a7cdf6f86f0b4513e65
parent 26c20e6b3e57d5c85cff6927c7d74049898a9f05
Author: cfillion <cfillion@users.noreply.github.com>
Date: Wed, 13 Jan 2016 17:34:23 -0500
install versions, not packages
Diffstat:
8 files changed, 50 insertions(+), 31 deletions(-)
diff --git a/src/registry.cpp b/src/registry.cpp
@@ -23,18 +23,18 @@
using namespace std;
-void Registry::push(Package *pkg)
+void Registry::push(Version *ver)
{
- Version *lastVer = pkg->lastVersion();
+ Package *pkg = ver->package();
- if(!lastVer)
+ if(!pkg)
return;
const Path id = pkg->targetPath() + pkg->name();
- push(id.join('/'), lastVer->name());
+ push(id.join('/'), ver->name());
}
-void Registry::push(const std::string &key, const std::string &value)
+void Registry::push(const string &key, const string &value)
{
m_map[key] = value;
}
diff --git a/src/registry.hpp b/src/registry.hpp
@@ -23,6 +23,7 @@
#include <string>
class Package;
+class Version;
class Registry {
public:
@@ -39,11 +40,11 @@ public:
uint64_t versionCode;
};
- void push(Package *pkg);
+ void push(Version *);
void push(const std::string &key, const std::string &value);
size_t size() const { return m_map.size(); }
- QueryResult query(Package *pkg) const;
+ QueryResult query(Package *) const;
Map::const_iterator begin() const { return m_map.begin(); }
Map::const_iterator end() const { return m_map.end(); }
diff --git a/src/report.cpp b/src/report.cpp
@@ -76,8 +76,10 @@ void Report::formatNewPackages(ostringstream &text)
{
text << NL << SEP << " New packages: " << SEP << NL;
- for(const Transaction::PackageEntry &entry : m_transaction->newPackages())
- text << NL << entry.first->lastVersion()->fullName() << NL;
+ for(const Transaction::PackageEntry &entry : m_transaction->newPackages()) {
+ Version *ver = entry.first;
+ text << NL << ver->fullName() << NL;
+ }
}
void Report::formatUpdates(ostringstream &text)
@@ -85,7 +87,7 @@ void Report::formatUpdates(ostringstream &text)
text << NL << SEP << " Updates: " << SEP << NL;
for(const Transaction::PackageEntry &entry : m_transaction->updates()) {
- Package *pkg = entry.first;
+ Package *pkg = entry.first->package();
const Registry::QueryResult ®Entry = entry.second;
const VersionSet &versions = pkg->versions();
diff --git a/src/source.hpp b/src/source.hpp
@@ -52,6 +52,8 @@ public:
const std::string &url, Version * = nullptr);
Platform platform() const { return m_platform; }
+
+ bool isMain() const { return m_file.empty(); }
const std::string &file() const;
const std::string &url() const { return m_url; }
diff --git a/src/transaction.cpp b/src/transaction.cpp
@@ -82,7 +82,9 @@ void Transaction::prepare()
for(Package *pkg : db->packages()) {
Registry::QueryResult entry = m_registry->query(pkg);
- set<Path> files = pkg->lastVersion()->files();
+ Version *ver = pkg->lastVersion();
+
+ set<Path> files = ver->files();
registerFiles(files);
if(entry.status == Registry::UpToDate) {
@@ -92,7 +94,7 @@ void Transaction::prepare()
entry.status = Registry::Uninstalled;
}
- m_packages.push_back({pkg, entry});
+ m_packages.push_back({ver, entry});
}
}
@@ -105,27 +107,27 @@ void Transaction::prepare()
void Transaction::run()
{
for(const PackageEntry &entry : m_packages) {
- Package *pkg = entry.first;
+ Version *ver = entry.first;
const Registry::QueryResult regEntry = entry.second;
Task *task = new Task(this);
try {
- task->install(entry.first->lastVersion());
+ task->install(ver);
task->onCommit([=] {
if(regEntry.status == Registry::UpdateAvailable)
m_updates.push_back(entry);
else
m_new.push_back(entry);
- m_registry->push(pkg);
+ m_registry->push(ver);
});
task->onFinish(bind(&Transaction::finish, this));
m_tasks.push_back(task);
}
catch(const reapack_error &e) {
- addError(e.what(), pkg->fullName());
+ addError(e.what(), ver->fullName());
delete task;
}
}
diff --git a/src/transaction.hpp b/src/transaction.hpp
@@ -33,7 +33,7 @@ public:
typedef boost::signals2::signal<void ()> Signal;
typedef Signal::slot_type Callback;
- typedef std::pair<Package *, const Registry::QueryResult> PackageEntry;
+ typedef std::pair<Version *, const Registry::QueryResult> PackageEntry;
typedef std::vector<PackageEntry> PackageEntryList;
struct Error {
diff --git a/test/registry.cpp b/test/registry.cpp
@@ -31,7 +31,7 @@ TEST_CASE("query up to date pacakge", M) {
MAKE_PACKAGE
Registry reg;
- reg.push(&pkg);
+ reg.push(ver);
const Registry::QueryResult res = reg.query(&pkg);
REQUIRE(res.status == Registry::UpToDate);
@@ -45,14 +45,14 @@ TEST_CASE("bump version", M) {
ver2->addSource(new Source(Source::GenericPlatform, "file", "url", ver2));
Registry reg;
- reg.push(&pkg);
+ reg.push(ver);
pkg.addVersion(ver2);
const Registry::QueryResult res1 = reg.query(&pkg);
REQUIRE(res1.status == Registry::UpdateAvailable);
REQUIRE(res1.versionCode == Version("1.0").code());
- reg.push(&pkg);
+ reg.push(ver2);
const Registry::QueryResult res2 = reg.query(&pkg);
REQUIRE(res2.status == Registry::UpToDate);
REQUIRE(res2.versionCode == Version("2.0").code());
diff --git a/test/source.cpp b/test/source.cpp
@@ -45,7 +45,7 @@ TEST_CASE("convert platforms", M) {
}
TEST_CASE("empty file name and no package", M) {
- Source source(Source::UnknownPlatform, string(), "b");
+ const Source source(Source::UnknownPlatform, string(), "b");
try {
(void)source.file();
@@ -56,9 +56,21 @@ TEST_CASE("empty file name and no package", M) {
}
}
+TEST_CASE("main source", M) {
+ SECTION("with file name") {
+ const Source source(Source::UnknownPlatform, "a", "b");
+ REQUIRE_FALSE(source.isMain());
+ }
+
+ SECTION("without file name") {
+ const Source source(Source::UnknownPlatform, string(), "b");
+ REQUIRE(source.isMain());
+ }
+}
+
TEST_CASE("empty source url", M) {
try {
- Source source(Source::UnknownPlatform, "a", string());
+ const Source source(Source::UnknownPlatform, "a", string());
FAIL();
}
catch(const reapack_error &e) {
@@ -67,14 +79,14 @@ TEST_CASE("empty source url", M) {
}
TEST_CASE("full name without version", M) {
- SECTION("source name") {
- Source source(Source::UnknownPlatform, "a", "b");
+ SECTION("with source name") {
+ const Source source(Source::UnknownPlatform, "a", "b");
REQUIRE(source.fullName() == "a");
}
- SECTION("package name") {
+ SECTION("without source name") {
try {
- Source source(Source::UnknownPlatform, string(), "b");
+ const Source source(Source::UnknownPlatform, string(), "b");
(void)source.fullName();
FAIL();
}
@@ -87,14 +99,14 @@ TEST_CASE("full name without version", M) {
TEST_CASE("full name with version", M) {
SECTION("with source name") {
Version ver("1.0");
- Source source(Source::UnknownPlatform, "a", "b", &ver);
+ const Source source(Source::UnknownPlatform, "a", "b", &ver);
REQUIRE(source.fullName() == "v1.0 (a)");
}
- SECTION("with source name") {
+ SECTION("without source name") {
Version ver("1.0");
- Source source(Source::UnknownPlatform, string(), "b", &ver);
+ const Source source(Source::UnknownPlatform, string(), "b", &ver);
REQUIRE(source.fullName() == ver.fullName());
}
@@ -106,7 +118,7 @@ TEST_CASE("source target path", M) {
Package pack(Package::ScriptType, "package name", &cat);
Version ver("1.0", &pack);
- Source source(Source::GenericPlatform, "file.name", "url", &ver);
+ const Source source(Source::GenericPlatform, "file.name", "url", &ver);
Path expected;
expected.append("Scripts");
@@ -119,7 +131,7 @@ TEST_CASE("source target path", M) {
TEST_CASE("source target path without package", M) {
try {
- Source source(Source::GenericPlatform, "a", "b");
+ const Source source(Source::GenericPlatform, "a", "b");
(void)source.targetPath();
FAIL();
}