commit 1a8f38daeb43a773b26cff2ca993d166f0226450
parent cff915aabbecacf52b99c3b09a2c33c1fca264f1
Author: cfillion <cfillion@users.noreply.github.com>
Date: Mon, 14 Dec 2015 20:15:57 -0500
fix registry keys and use portable names for them
Diffstat:
5 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/src/path.cpp b/src/path.cpp
@@ -33,7 +33,7 @@ string Path::basename() const
return m_parts.back();
}
-string Path::join(const bool skipLast) const
+string Path::join(const bool skipLast, const char sep) const
{
string path;
@@ -46,7 +46,7 @@ string Path::join(const bool skipLast) const
const string &part = *it;
if(!path.empty())
- path.insert(path.end(), SEPARATOR);
+ path.insert(path.end(), sep ? sep : SEPARATOR);
path.append(part);
}
diff --git a/src/path.hpp b/src/path.hpp
@@ -14,8 +14,8 @@ public:
size_t size() const { return m_parts.size(); }
std::string basename() const;
- std::string dirname() const { return join(true); }
- std::string join() const { return join(false); }
+ std::string dirname() const { return join(true, 0); }
+ std::string join(const char sep = 0) const { return join(false, sep); }
bool operator==(const Path &) const;
bool operator!=(const Path &) const;
@@ -24,7 +24,7 @@ public:
std::string &operator[](const size_t index);
private:
- std::string join(const bool) const;
+ std::string join(const bool, const char) const;
std::list<std::string> m_parts;
};
diff --git a/src/registry.cpp b/src/registry.cpp
@@ -13,7 +13,8 @@ void Registry::push(Package *pkg)
if(!lastVer)
return;
- push(pkg->targetPath().join(), lastVer->name());
+ const Path id = pkg->targetPath() + pkg->name();
+ push(id.join('/'), lastVer->name());
}
void Registry::push(const std::string &key, const std::string &value)
@@ -23,8 +24,8 @@ void Registry::push(const std::string &key, const std::string &value)
Registry::QueryResult Registry::query(Package *pkg) const
{
- const string key = pkg->targetPath().join();
- const auto it = m_map.find(key);
+ const Path id = pkg->targetPath() + pkg->name();
+ const auto it = m_map.find(id.join('/'));
if(it == m_map.end())
return {Uninstalled, 0};
diff --git a/src/transaction.cpp b/src/transaction.cpp
@@ -91,7 +91,7 @@ void Transaction::run()
{
for(const PackageEntry &entry : m_packages) {
Package *pkg = entry.first;
- Registry::QueryResult regEntry = entry.second;
+ const Registry::QueryResult regEntry = entry.second;
PackageTransaction *tr = new PackageTransaction(this);
diff --git a/test/path.cpp b/test/path.cpp
@@ -95,3 +95,11 @@ TEST_CASE("modify path", M) {
a[0] = "world";
REQUIRE(a.join() == "world");
}
+
+TEST_CASE("custom separator", M) {
+ Path a;
+ a.append("hello");
+ a.append("world");
+
+ REQUIRE(a.join('-') == "hello-world");
+}