reapack

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

commit 708a1adee8005c453f5ca0688959c1c76c99ce62
parent fe2ec8539504b7a548a3ed41ed3551a3a2002236
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun,  5 Jun 2016 22:40:32 -0400

about: annotate main files with an asterix

registry: read more data about files
and global refactoring

Diffstat:
Msrc/about.cpp | 12++++++++----
Msrc/database.hpp | 1+
Msrc/receipt.hpp | 1+
Msrc/registry.cpp | 44+++++++++++++++++++++-----------------------
Msrc/registry.hpp | 6++++--
Msrc/task.cpp | 9+++++----
Msrc/task.hpp | 8+++++---
Msrc/transaction.cpp | 22+++++++++++++---------
Mtest/registry.cpp | 8++++++--
9 files changed, 64 insertions(+), 47 deletions(-)

diff --git a/src/about.cpp b/src/about.cpp @@ -201,12 +201,12 @@ void About::updatePackages() void About::updateInstalledFiles() { - set<Path> allFiles; + set<Registry::File> allFiles; try { Registry reg(Path::prefixRoot(Path::REGISTRY)); for(const Registry::Entry &entry : reg.getEntries(m_index->name())) { - const set<Path> &files = reg.getFiles(entry); + const vector<Registry::File> &files = reg.getFiles(entry); allFiles.insert(files.begin(), files.end()); } } @@ -233,8 +233,12 @@ void About::updateInstalledFiles() else { stringstream stream; - for(const Path &path : allFiles) - stream << path.join() << "\r\n"; + for(const Registry::File &file : allFiles) { + stream << file.path.join(); + if(file.main) + stream << '*'; + stream << "\r\n"; + } SetWindowText(m_installedFiles, make_autostring(stream.str()).c_str()); } diff --git a/src/database.hpp b/src/database.hpp @@ -61,6 +61,7 @@ public: void exec(const ExecCallback &); int intColumn(int index) const; + bool boolColumn(int index) const { return intColumn(index) != 0; } std::string stringColumn(int index) const; private: diff --git a/src/receipt.hpp b/src/receipt.hpp @@ -53,6 +53,7 @@ public: const std::vector<InstallTicket> &installs() const { return m_installs; } const std::vector<InstallTicket> &updates() const { return m_updates; } + void addRemoval(const Path &p) { m_removals.insert(p); } void addRemovals(const std::set<Path> &); const std::set<Path> &removals() const { return m_removals; } diff --git a/src/registry.cpp b/src/registry.cpp @@ -56,9 +56,8 @@ Registry::Registry(const Path &path) m_forgetEntry = m_db.prepare("DELETE FROM entries WHERE id = ?"); // file queries - m_getFiles = m_db.prepare("SELECT path FROM files WHERE entry = ?"); - m_getMainFiles = m_db.prepare( - "SELECT path, type FROM files WHERE main = 1 AND entry = ?" + m_getFiles = m_db.prepare( + "SELECT path, main, type FROM files WHERE entry = ? ORDER BY path" ); m_insertFile = m_db.prepare("INSERT INTO files VALUES(NULL, ?, ?, ?, ?)"); m_clearFiles = m_db.prepare( @@ -97,7 +96,7 @@ void Registry::migrate() " entry INTEGER NOT NULL," " path TEXT UNIQUE NOT NULL," " main INTEGER NOT NULL," - " type INTEGER," + " type INTEGER NOT NULL," " FOREIGN KEY(entry) REFERENCES entries(id)" ");" ); @@ -222,7 +221,7 @@ auto Registry::getEntry(const Package *pkg) const -> Entry entry.type = static_cast<Package::Type>(m_findEntry->intColumn(col++)); entry.version.tryParse(m_findEntry->stringColumn(col++)); entry.version.setAuthor(m_findEntry->stringColumn(col++)); - entry.pinned = m_findEntry->intColumn(col++) != 0; + entry.pinned = m_findEntry->boolColumn(col++); return false; }); @@ -246,7 +245,7 @@ auto Registry::getEntries(const string &remoteName) const -> vector<Entry> entry.type = static_cast<Package::Type>(m_allEntries->intColumn(col++)); entry.version.tryParse(m_allEntries->stringColumn(col++)); entry.version.setAuthor(m_allEntries->stringColumn(col++)); - entry.pinned = m_allEntries->intColumn(col++) != 0; + entry.pinned = m_allEntries->boolColumn(col++); list.push_back(entry); @@ -256,20 +255,27 @@ auto Registry::getEntries(const string &remoteName) const -> vector<Entry> return list; } -set<Path> Registry::getFiles(const Entry &entry) const +auto Registry::getFiles(const Entry &entry) const -> vector<File> { if(!entry) // skip processing for new packages return {}; - set<Path> list; + vector<File> files; m_getFiles->bind(1, entry.id); m_getFiles->exec([&] { - list.insert(m_getFiles->stringColumn(0)); + File file{m_getFiles->stringColumn(0)}; + file.main = m_getFiles->boolColumn(1); + file.type = static_cast<Package::Type>(m_getFiles->intColumn(2)); + + if(!file.type) // < v1.0rc2 + file.type = entry.type; + + files.push_back(file); return true; }); - return list; + return files; } auto Registry::getMainFiles(const Entry &entry) const -> vector<File> @@ -277,21 +283,13 @@ auto Registry::getMainFiles(const Entry &entry) const -> vector<File> if(!entry) return {}; - vector<File> files; + const vector<File> &allFiles = getFiles(entry); - m_getMainFiles->bind(1, entry.id); - m_getMainFiles->exec([&] { - File file{m_getMainFiles->stringColumn(0)}; - file.type = static_cast<Package::Type>(m_getMainFiles->intColumn(1)); + vector<File> mainFiles; + copy_if(allFiles.begin(), allFiles.end(), + back_inserter(mainFiles), [&](const File &f) { return f.main; }); - if(!file.type) // < v1.0rc2 - file.type = entry.type; - - files.push_back(file); - return true; - }); - - return files; + return mainFiles; } void Registry::forget(const Entry &entry) diff --git a/src/registry.hpp b/src/registry.hpp @@ -46,14 +46,17 @@ public: struct File { Path path; + bool main; Package::Type type; + + bool operator<(const File &o) const { return path < o.path; } }; Registry(const Path &path = {}); Entry getEntry(const Package *) const; std::vector<Entry> getEntries(const std::string &) const; - std::set<Path> getFiles(const Entry &) const; + std::vector<File> getFiles(const Entry &) const; std::vector<File> getMainFiles(const Entry &) const; Entry push(const Version *, std::vector<Path> *conflicts = nullptr); void setPinned(const Entry &, bool pinned); @@ -75,7 +78,6 @@ private: Statement *m_forgetEntry; Statement *m_getFiles; - Statement *m_getMainFiles; Statement *m_insertFile; Statement *m_clearFiles; Statement *m_forgetFiles; diff --git a/src/task.cpp b/src/task.cpp @@ -53,7 +53,7 @@ void Task::rollback() } InstallTask::InstallTask(const Version *ver, - const set<Path> &oldFiles, Transaction *t) + const vector<Registry::File> &oldFiles, Transaction *t) : Task(t), m_version(ver), m_oldFiles(move(oldFiles)) { } @@ -88,7 +88,8 @@ void InstallTask::saveSource(Download *dl, const Source *src) m_newFiles.push_back({targetPath, tmpPath}); - const auto old = m_oldFiles.find(targetPath); + const auto old = find_if(m_oldFiles.begin(), m_oldFiles.end(), + [&](const Registry::File &f) { return f.path == targetPath; }); if(old != m_oldFiles.end()) m_oldFiles.erase(old); @@ -101,8 +102,8 @@ void InstallTask::saveSource(Download *dl, const Source *src) bool InstallTask::doCommit() { - for(const Path &path : m_oldFiles) - FS::remove(path); + for(const Registry::File &file : m_oldFiles) + FS::remove(file.path); for(const PathGroup &paths : m_newFiles) { #ifdef _WIN32 diff --git a/src/task.hpp b/src/task.hpp @@ -19,6 +19,7 @@ #define REAPACK_TASK_HPP #include "path.hpp" +#include "registry.hpp" #include <boost/signals2.hpp> #include <set> @@ -60,9 +61,10 @@ private: class InstallTask : public Task { public: - InstallTask(const Version *ver, const std::set<Path> &oldFiles, Transaction *); + InstallTask(const Version *ver, const std::vector<Registry::File> &oldFiles, + Transaction *); - const std::set<Path> &removedFiles() const { return m_oldFiles; } + const std::vector<Registry::File> &removedFiles() const { return m_oldFiles; } protected: void doStart() override; @@ -75,7 +77,7 @@ private: void saveSource(Download *, const Source *); const Version *m_version; - std::set<Path> m_oldFiles; + std::vector<Registry::File> m_oldFiles; std::vector<PathGroup> m_newFiles; }; diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -166,7 +166,7 @@ void Transaction::install(const Version *ver, type = InstallTicket::Install; // get current files before overwriting the entry - const set<Path> &currentFiles = m_registry->getFiles(regEntry); + const auto &currentFiles = m_registry->getFiles(regEntry); // prevent file conflicts (don't worry, the registry push is reverted in runTasks) try { @@ -198,7 +198,11 @@ void Transaction::install(const Version *ver, task->onCommit([=] { m_receipt.addTicket({type, ver, regEntry}); - m_receipt.addRemovals(task->removedFiles()); + + for(const Registry::File &file : task->removedFiles()) { + m_receipt.addRemoval(file.path); + // TODO: unregister file + } const Registry::Entry newEntry = m_registry->push(ver); @@ -270,13 +274,13 @@ void Transaction::uninstall(const Registry::Entry &entry) { vector<Path> files; - for(const Path &path : m_registry->getFiles(entry)) { - if(FS::exists(path)) - files.push_back(path); + for(const Registry::File &file : m_registry->getFiles(entry)) { + if(FS::exists(file.path)) + files.push_back(file.path); + if(file.main) + m_regQueue.push({false, entry, file}); } - registerInHost(false, entry); - RemoveTask *task = new RemoveTask(files, this); task->onCommit([=] { m_registry->forget(entry); @@ -366,8 +370,8 @@ bool Transaction::runTasks() void Transaction::registerInHost(const bool add, const Registry::Entry &entry) { // don't actually do anything until commit() – which will calls registerQueued - for(const Registry::File &mainFile : m_registry->getMainFiles(entry)) - m_regQueue.push({add, entry, mainFile}); + for(const Registry::File &file : m_registry->getMainFiles(entry)) + m_regQueue.push({add, entry, file}); } void Transaction::registerQueued() diff --git a/test/registry.cpp b/test/registry.cpp @@ -89,8 +89,11 @@ TEST_CASE("get file list", M) { reg.push(ver); - const set<Path> &files = reg.getFiles(reg.getEntry(&pkg)); - REQUIRE(files == ver->files()); + const vector<Registry::File> &files = reg.getFiles(reg.getEntry(&pkg)); + REQUIRE(files.size() == 1); + REQUIRE(files[0].path == src->targetPath()); + REQUIRE(files[0].main == false); + REQUIRE(files[0].type == pkg.type()); } TEST_CASE("query all packages", M) { @@ -182,6 +185,7 @@ TEST_CASE("get main files", M) { const vector<Registry::File> &current = reg.getMainFiles(entry); REQUIRE(current.size() == 1); REQUIRE(current[0].path == main1->targetPath()); + REQUIRE(current[0].main == true); REQUIRE(current[0].type == Package::EffectType); }