diff options
-rw-r--r-- | bpkg/rep-add.cxx | 5 | ||||
-rw-r--r-- | bpkg/rep-add.hxx | 4 | ||||
-rw-r--r-- | bpkg/rep-fetch.cxx | 19 | ||||
-rw-r--r-- | bpkg/rep-fetch.hxx | 3 | ||||
-rw-r--r-- | bpkg/rep-remove.cxx | 18 | ||||
-rw-r--r-- | bpkg/rep-remove.hxx | 11 |
6 files changed, 33 insertions, 27 deletions
diff --git a/bpkg/rep-add.cxx b/bpkg/rep-add.cxx index 2dcce9a..6db2c92 100644 --- a/bpkg/rep-add.cxx +++ b/bpkg/rep-add.cxx @@ -16,10 +16,11 @@ using namespace butl; namespace bpkg { shared_ptr<repository> - rep_add (database& db, const repository_location& rl) + rep_add (transaction& t, const repository_location& rl) { const string& rn (rl.canonical_name ()); + database& db (t.database ()); shared_ptr<repository> r (db.find<repository> (rn)); bool updated (false); @@ -75,7 +76,7 @@ namespace bpkg ? optional<repository_type> (o.type ()) : nullopt)); - rep_add (db, rl); + rep_add (t, rl); } t.commit (); diff --git a/bpkg/rep-add.hxx b/bpkg/rep-add.hxx index 192df05..226f0e2 100644 --- a/bpkg/rep-add.hxx +++ b/bpkg/rep-add.hxx @@ -8,7 +8,7 @@ #include <libbpkg/manifest.hxx> #include <bpkg/types.hxx> -#include <bpkg/forward.hxx> // database, repository +#include <bpkg/forward.hxx> // transaction, repository #include <bpkg/utility.hxx> #include <bpkg/rep-add-options.hxx> @@ -23,7 +23,7 @@ namespace bpkg // repository if it is not already. // shared_ptr<repository> - rep_add (database&, const repository_location&); + rep_add (transaction&, const repository_location&); } #endif // BPKG_REP_ADD_HXX diff --git a/bpkg/rep-fetch.cxx b/bpkg/rep-fetch.cxx index ab7ce55..31e7b11 100644 --- a/bpkg/rep-fetch.cxx +++ b/bpkg/rep-fetch.cxx @@ -423,7 +423,7 @@ namespace bpkg static void rep_fetch (const common_options& co, const dir_path& conf, - database& db, + transaction& t, const shared_ptr<repository>& r, repositories& fetched, repositories& removed, @@ -431,6 +431,7 @@ namespace bpkg { tracer trace ("rep_fetch(rep)"); + database& db (t.database ()); tracer_guard tg (db, trace); // Check that the repository is not fetched yet and register it as fetched @@ -494,7 +495,7 @@ namespace bpkg // Remove this repository from locations of the available packages it // contains. // - rep_remove_package_locations (db, r->name); + rep_remove_package_locations (t, r->name); // Load the repository and package manifests and use them to populate the // prerequisite and complement repository sets as well as available @@ -555,7 +556,7 @@ namespace bpkg } reason += r->name; - rep_fetch (co, conf, db, pr, fetched, removed, reason); + rep_fetch (co, conf, t, pr, fetched, removed, reason); // @@ What if we have duplicated? Ideally, we would like to check // this once and as early as possible. The original idea was to @@ -685,8 +686,6 @@ namespace bpkg transaction& t, const vector<lazy_shared_ptr<repository>>& repos) { - database& db (t.database ()); - // As a fist step we fetch repositories recursively building the list of // the former prerequisites and complements to be considered for removal. // @@ -705,12 +704,12 @@ namespace bpkg repositories removed; for (const lazy_shared_ptr<repository>& r: repos) - rep_fetch (o, conf, db, r.load (), fetched, removed); + rep_fetch (o, conf, t, r.load (), fetched, removed); // Finally, remove dangling repositories. // for (const shared_ptr<repository>& r: removed) - rep_remove (conf, db, r); + rep_remove (conf, t, r); } catch (const failed&) { @@ -724,7 +723,7 @@ namespace bpkg warn << "repository state is now broken and will be cleaned up" << info << "run 'bpkg rep-fetch' to update"; - rep_remove_clean (conf, db); + rep_remove_clean (conf, t.database ()); } throw; @@ -753,7 +752,7 @@ namespace bpkg // same location. // if (ua.find (r) == ua.end () || r.load ()->location.url () != rl.url ()) - rep_add (db, rl); + rep_add (t, rl); repos.emplace_back (r); } @@ -819,7 +818,7 @@ namespace bpkg // calling rep_add. Get rid of quiet mode. // r = lazy_shared_ptr<repository> ( - db, rep_add (db, parse_location (a, nullopt /* type */))); + db, rep_add (t, parse_location (a, nullopt /* type */))); repos.emplace_back (move (r)); } diff --git a/bpkg/rep-fetch.hxx b/bpkg/rep-fetch.hxx index b26971c..030b192 100644 --- a/bpkg/rep-fetch.hxx +++ b/bpkg/rep-fetch.hxx @@ -52,8 +52,7 @@ namespace bpkg // Add (or update) repository locations to the configuration and fetch // them. On failure clean up the configuration (see rep_remove_clean() for - // details). Note that it starts a new transaction and should be called in - // session. + // details). Note that it should be called in session. // void rep_fetch (const common_options&, diff --git a/bpkg/rep-remove.cxx b/bpkg/rep-remove.cxx index df9acde..eadb63f 100644 --- a/bpkg/rep-remove.cxx +++ b/bpkg/rep-remove.cxx @@ -72,8 +72,10 @@ namespace bpkg } void - rep_remove_package_locations (database& db, const string& name) + rep_remove_package_locations (transaction& t, const string& name) { + database& db (t.database ()); + for (const auto& rp: db.query<repository_package> ( query<repository_package>::repository::name == name)) { @@ -112,15 +114,19 @@ namespace bpkg } void - rep_remove (const dir_path& c, database& db, const shared_ptr<repository>& r) + rep_remove (const dir_path& c, + transaction& t, + const shared_ptr<repository>& r) { const string& nm (r->name); assert (!nm.empty ()); // Can't be the root repository. + database& db (t.database ()); + if (reachable (db, r)) return; - rep_remove_package_locations (db, nm); + rep_remove_package_locations (t, nm); // Cleanup the repository state if present. // @@ -154,12 +160,12 @@ namespace bpkg // Prior to removing a prerequisite/complement we need to make sure it // still exists, which may not be the case due to the dependency cycle. // - auto remove = [&c, &db] (const lazy_shared_ptr<repository>& rp) + auto remove = [&c, &db, &t] (const lazy_shared_ptr<repository>& rp) { shared_ptr<repository> r (db.find<repository> (rp.object_id ())); if (r) - rep_remove (c, db, r); + rep_remove (c, t, r); }; for (const lazy_shared_ptr<repository>& cr: r->complements) @@ -375,7 +381,7 @@ namespace bpkg // for (const lazy_shared_ptr<repository>& r: repos) { - rep_remove (c, db, r.load ()); + rep_remove (c, t, r.load ()); if (verb) text << "removed " << r.object_id (); diff --git a/bpkg/rep-remove.hxx b/bpkg/rep-remove.hxx index a7a6418..a8d4908 100644 --- a/bpkg/rep-remove.hxx +++ b/bpkg/rep-remove.hxx @@ -6,7 +6,7 @@ #define BPKG_REP_REMOVE_HXX #include <bpkg/types.hxx> -#include <bpkg/forward.hxx> // database, repository +#include <bpkg/forward.hxx> // database, transaction, repository #include <bpkg/utility.hxx> #include <bpkg/rep-remove-options.hxx> @@ -20,11 +20,12 @@ namespace bpkg // required by any user-added repository). // void - rep_remove (const dir_path& conf, database&, const shared_ptr<repository>&); + rep_remove (const dir_path& conf, + transaction&, + const shared_ptr<repository>&); // Bring the configuration to the clean state as if repositories were added - // but never fetched. Leave selected packages intact. Note that it should be - // called out of the database transaction. + // but never fetched. Leave selected packages intact. // // Specifically: // @@ -45,7 +46,7 @@ namespace bpkg // contains. Remove packages that come from only this repository. // void - rep_remove_package_locations (database&, const string& repository_name); + rep_remove_package_locations (transaction&, const string& repository_name); } #endif // BPKG_REP_REMOVE_HXX |