From 7490948f27d70df1f88ed161a2b758755d0a7929 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 29 Jul 2021 18:32:14 +0300 Subject: Add support for checked out repository fragments caching --- bpkg/pkg-checkout.hxx | 64 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'bpkg/pkg-checkout.hxx') diff --git a/bpkg/pkg-checkout.hxx b/bpkg/pkg-checkout.hxx index 3a058b5..d910509 100644 --- a/bpkg/pkg-checkout.hxx +++ b/bpkg/pkg-checkout.hxx @@ -4,6 +4,8 @@ #ifndef BPKG_PKG_CHECKOUT_HXX #define BPKG_PKG_CHECKOUT_HXX +#include + #include // version #include @@ -18,13 +20,70 @@ namespace bpkg int pkg_checkout (const pkg_checkout_options&, cli::scanner& args); + // Checked out repository fragments cache. + // + // Needs to be passed to pkg_checkout() calls. + // + class pkg_checkout_cache + { + public: + // The options reference is assumed to be valid till the end of the cache + // object lifetime. + // + pkg_checkout_cache (const common_options& o): options_ (o) {} + + // Restore the cached repositories in their permanent locations (move back + // from the temporary directory, fixup, etc) and erase the entries. + // + // Note that the destructor will clear the cache but will ignore any + // errors. To detect such errors, call clear() explicitly. + // + bool + clear (bool ignore_errors = false); + + // Call clear() in the ignore errors mode and issue the "repository is now + // broken" warning on failure. + // + ~pkg_checkout_cache (); + + // pkg_checkout () implementation details. + // + public: + struct state + { + auto_rmdir rmt; // The repository temporary directory. + repository_location rl; // The repository location. + + // nullopt if the repository fragment checkout failed in the middle and + // the repository cannot be restored in its permanent location (we will + // call such entry incomplete). True if the repository directory was + // fixed up. + // + optional fixedup; + }; + + using state_map = std::map; + + state_map map_; + const common_options& options_; + + // Restore the repository in its permanent location and erase the cache + // entry. On error issue diagnostics and return false in the ignore errors + // mode and throw failed otherwise. Note that erasing an incomplete entry + // is an error. + // + bool + erase (state_map::iterator, bool ignore_errors = false); + }; + // Check out the package from a version control-based repository into a // directory other than the configuration directory and commit the // transaction. Return the selected package object which may replace the // existing one. // shared_ptr - pkg_checkout (const common_options&, + pkg_checkout (pkg_checkout_cache&, + const common_options&, database&, transaction&, package_name, @@ -39,7 +98,8 @@ namespace bpkg // existing one. // shared_ptr - pkg_checkout (const common_options&, + pkg_checkout (pkg_checkout_cache&, + const common_options&, database&, transaction&, package_name, -- cgit v1.1