reapack

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

commit c030cfca4d4dd6b952f5d679bfe537dee0054ae3
parent a9dcadc26d33fc871431d30a8ecdbafaa814acb7
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon, 14 Dec 2015 18:08:49 -0500

check for conficts between packages

Diffstat:
Msrc/pkgtransaction.cpp | 12------------
Msrc/pkgtransaction.hpp | 2--
Msrc/transaction.cpp | 26+++++++++++++++++++++++++-
Msrc/version.cpp | 12++++++++++++
Msrc/version.hpp | 2++
Mtest/version.cpp | 26++++++++++++++++++++++++++
6 files changed, 65 insertions(+), 15 deletions(-)

diff --git a/src/pkgtransaction.cpp b/src/pkgtransaction.cpp @@ -6,20 +6,8 @@ #include <cerrno> #include <cstdio> -#include <reaper_plugin_functions.h> - using namespace std; -bool PackageTransaction::isInstalled(Version *ver, Transaction *tr) -{ - for(Source *src : ver->sources()) { - if(!file_exists(tr->prefixPath(src->targetPath()).join().c_str())) - return false; - } - - return true; -} - PackageTransaction::PackageTransaction(Transaction *transaction) : m_transaction(transaction), m_isCancelled(false) { diff --git a/src/pkgtransaction.hpp b/src/pkgtransaction.hpp @@ -12,8 +12,6 @@ class Version; class PackageTransaction { public: - static bool isInstalled(Version *, Transaction *); - typedef boost::signals2::signal<void ()> Signal; typedef Signal::slot_type Callback; diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -67,10 +67,34 @@ void Transaction::prepare() if(!m_queue.idle()) return; + vector<Path> allFiles; + for(Database *db : m_databases) { for(Package *pkg : db->packages()) { + vector<Path> files = pkg->lastVersion()->files(); + allFiles.insert(allFiles.end(), files.begin(), files.end()); + + const auto uniqueIt = unique(allFiles.begin(), allFiles.end()); + if(uniqueIt != allFiles.end()) { + for(auto it = uniqueIt; it != allFiles.end(); it++) { + addError("Conflict: This file is created by more than one package", + it->join()); + } + + finish(); + return; + } + + bool exists = true; + + for(const Path &path : files) { + if(!file_exists(prefixPath(path).join().c_str())) { + exists = false; + break; + } + } + Registry::QueryResult entry = m_registry->query(pkg); - bool exists = PackageTransaction::isInstalled(pkg->lastVersion(), this); if(entry.status == Registry::UpToDate && exists) continue; diff --git a/src/version.cpp b/src/version.cpp @@ -85,6 +85,18 @@ void Version::setChangelog(const std::string &changelog) m_changelog = changelog; } +vector<Path> Version::files() const +{ + const size_t size = m_sources.size(); + + vector<Path> list(size); + + for(size_t i = 0; i < size; i++) + list[i] = m_sources[i]->targetPath(); + + return list; +} + bool Version::operator<(const Version &o) const { return m_code < o.code(); diff --git a/src/version.hpp b/src/version.hpp @@ -27,6 +27,8 @@ public: const SourceList &sources() const { return m_sources; } Source *source(const size_t i) const { return m_sources[i]; } + std::vector<Path> files() const; + bool operator<(const Version &) const; private: diff --git a/test/version.cpp b/test/version.cpp @@ -107,6 +107,32 @@ TEST_CASE("add source", M) { REQUIRE(ver.source(0) == src); } +TEST_CASE("list files", M) { + Source *src1 = new Source(Source::GenericPlatform, "file", "url"); + + Version ver("1"); + ver.addSource(src1); + + Package pkg(Package::ScriptType, "name"); + ver.setPackage(&pkg); + + Category cat("Category Name"); + pkg.setCategory(&cat); + + Database db; + db.setName("Database Name"); + cat.setDatabase(&db); + + Path path1; + path1.append("Scripts"); + path1.append("Database Name"); + path1.append("Category Name"); + path1.append("file"); + + const vector<Path> expected{path1}; + REQUIRE(ver.files() == expected); +} + TEST_CASE("drop sources for unknown platforms", M) { Version ver("1"); ver.addSource(new Source(Source::UnknownPlatform, "a", "b"));