reapack

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

commit e9f705b3708b48b997ba0d8ea86e2890395fdbf5
parent ff5e96a417e690cef132603e2cb5a2bcb2b9c36f
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Tue,  8 Mar 2016 04:17:01 -0500

transaction: free unused repo indexes immediately

Diffstat:
Msrc/index.hpp | 2+-
Msrc/transaction.cpp | 13++++++++-----
Msrc/transaction.hpp | 5+++--
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/index.hpp b/src/index.hpp @@ -38,7 +38,7 @@ struct Link { std::string name; std::string url; }; typedef std::shared_ptr<const Index> IndexPtr; -class Index { +class Index : public std::enable_shared_from_this<const Index> { public: enum LinkType { WebsiteLink, DonationLink }; typedef std::multimap<LinkType, Link> LinkMap; diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -72,7 +72,6 @@ void Transaction::synchronize(const Remote &remote, const bool isUserAction) try { ri = Index::load(remote.name()); - m_indexes.push_back(ri); } catch(const reapack_error &e) { // index file is invalid (load error) @@ -88,7 +87,7 @@ void Transaction::synchronize(const Remote &remote, const bool isUserAction) m_registry->savepoint(); for(const Package *pkg : ri->packages()) - upgrade(pkg); + install(pkg->lastVersion()); m_registry->restore(); }); @@ -126,9 +125,9 @@ void Transaction::saveIndex(Download *dl, const string &name) it->second(); } -void Transaction::upgrade(const Package *pkg) +void Transaction::install(const Version *ver) { - const Version *ver = pkg->lastVersion(); + const Package *pkg = ver->package(); const Registry::Entry &regEntry = m_registry->getEntry(pkg); InstallTicket::Type type = InstallTicket::Install; @@ -142,7 +141,7 @@ void Transaction::upgrade(const Package *pkg) type = InstallTicket::Upgrade; } - // prevent file conflicts – pushes to the registry will be reverted! + // prevent file conflicts (don't worry, the registry push is reverted later) try { vector<Path> conflicts; m_registry->push(ver, &conflicts); @@ -164,6 +163,10 @@ void Transaction::upgrade(const Package *pkg) } // all green! (pronounce with a japanese accent) + IndexPtr ri = pkg->category()->index()->shared_from_this(); + if(!m_indexes.count(ri)) + m_indexes.insert(ri); + m_installQueue.push({type, ver, regEntry}); } diff --git a/src/transaction.hpp b/src/transaction.hpp @@ -26,6 +26,7 @@ #include <functional> #include <memory> #include <set> +#include <unordered_set> class Index; class Path; @@ -56,6 +57,7 @@ public: void setCleanupHandler(const CleanupHandler &cb) { m_cleanupHandler = cb; } void synchronize(const Remote &, bool userAction = true); + void install(const Version *); void uninstall(const Remote &); void registerAll(const Remote &); void unregisterAll(const Remote &); @@ -76,7 +78,6 @@ private: void fetchIndex(const Remote &, const IndexCallback &cb); void saveIndex(Download *, const std::string &remoteName); - void upgrade(const Package *pkg); void installQueued(); void installTicket(const InstallTicket &); void addTask(Task *); @@ -95,7 +96,7 @@ private: Receipt m_receipt; std::multimap<std::string, IndexCallback> m_remotes; - std::vector<IndexPtr> m_indexes; + std::unordered_set<IndexPtr> m_indexes; std::vector<Task *> m_tasks; DownloadQueue m_downloadQueue;