From a6ea97b9844c9b78c7e9b24c241fc16be22e4176 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sun, 13 Jun 2021 00:05:20 +0300 Subject: Skip/remove dangling implicit associations --- bpkg/database.cxx | 95 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 39 deletions(-) (limited to 'bpkg/database.cxx') diff --git a/bpkg/database.cxx b/bpkg/database.cxx index 45f4b29..1b7612f 100644 --- a/bpkg/database.cxx +++ b/bpkg/database.cxx @@ -339,7 +339,22 @@ namespace bpkg schema_catalog::migrate (*this); for (auto& c: query (odb::query::id != 0)) - attach (c.make_effective_path (config)).migrate (); + { + dir_path d (c.effective_path (config)); + + // Remove the dangling implicit association. + // + if (!c.expl && !exists (d)) + { + warn << "implicit association " << c.path << " of configuration " + << config_orig << " does not exist, removing"; + + erase (c); + continue; + } + + attach (d).migrate (); + } } } @@ -516,54 +531,56 @@ namespace bpkg // if (implicit_associations_.empty () && ath) { + implicit_associations_.push_back (*this); + using q = odb::query; - // Make sure the self-association (zero id) comes first. - // - for (const auto& ac: query ("ORDER BY" + q::id)) + for (const auto& ac: query (q::id != 0)) { - database& db (attach (ac.effective_path (config), sys_rep)); + dir_path d (ac.effective_path (config)); - // Verify the association integrity and pre-attach its explicit - // associations, if required. + // Skip the dangling implicit association. // - if (*ac.id != 0) + if (!ac.expl && !exists (d)) + continue; + + database& db (attach (d, sys_rep)); + + // Verify the association integrity. + // + verify_association (ac, db); + + // If the association is explicit, also check if it is also implicit + // (see cfg_add() for details) and skip if it is not. + // + if (ac.expl) { - verify_association (ac, db); + shared_ptr cf ( + db.query_one (q::uuid == uuid.string ())); - // If the association is explicit, also check if it is also implicit - // (see cfg_add() for details) and skip if it is not. - // - if (ac.expl) - { - shared_ptr cf ( - db.query_one (q::uuid == uuid.string ())); - - if (cf == nullptr) - fail << "configuration " << db.config_orig << " is associated " - << "with " << config_orig << " but latter is not " - << "implicitly associated with former"; - - // While at it, verify the integrity of the other end of the - // association. - // - db.verify_association (*cf, *this); - - if (!cf->expl) - continue; - } - - // If the explicitly associated databases are pre-attached, normally - // to make the selected packages loadable, then we also pre-attach - // explicit associations of the database being attached implicitly, - // by the same reason. Indeed, think of loading the package - // dependent from the implicitly associated database as a selected - // package. + if (cf == nullptr) + fail << "configuration " << db.config_orig << " is associated " + << "with " << config_orig << " but latter is not " + << "implicitly associated with former"; + + // While at it, verify the integrity of the other end of the + // association. // - if (!explicit_associations_.empty ()) - db.attach_explicit (sys_rep); + db.verify_association (*cf, *this); + + if (!cf->expl) + continue; } + // If the explicitly associated databases are pre-attached, normally + // to make the selected packages loadable, then we also pre-attach + // explicit associations of the database being attached implicitly, by + // the same reason. Indeed, think of loading the package dependent + // from the implicitly associated database as a selected package. + // + if (!explicit_associations_.empty ()) + db.attach_explicit (sys_rep); + implicit_associations_.push_back (db); } } -- cgit v1.1