From 3271ee28840ff1ab905943649acbcea262cd9b2b Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 14 May 2024 18:50:55 +0300 Subject: Fix rep-remove assertions --- bpkg/rep-remove.cxx | 55 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'bpkg/rep-remove.cxx') diff --git a/bpkg/rep-remove.cxx b/bpkg/rep-remove.cxx index ad10f56..22702a5 100644 --- a/bpkg/rep-remove.cxx +++ b/bpkg/rep-remove.cxx @@ -178,12 +178,6 @@ namespace bpkg for (const repository::fragment_type& fr: r->fragments) rep_remove_fragment (db, t, fr.fragment.load (), mask); - // If there are no repositories stayed in the database then no repository - // fragments should stay either. - // - if (db.query_value () == 0) - assert (db.query_value () == 0); - // Unless in the mask repositories mode, cleanup the repository state if // present and there are no more repositories referring this state. // @@ -272,20 +266,6 @@ namespace bpkg // db.erase (rf); - // If there are no repository fragments stayed in the database then no - // repositories nor packages should stay either. - // - // Note that a repository is removed prior to the removal of fragments it - // contains (see rep_remove()). Also note that the packages contained in a - // repository fragment are removed, if this is the only containing - // fragment, prior to the fragment removal (see above). - // - if (db.query_value () == 0) - { - assert (db.query_value () == 0); - assert (mask || db.query_value () == 0); - } - // Remove dangling complements and prerequisites. // // Prior to removing a prerequisite/complement we need to make sure it @@ -521,6 +501,10 @@ namespace bpkg text << "removed " << r.object_id (); } +#ifndef NDEBUG + rep_remove_verify (db, t); +#endif + // If the --all option is specified then no user-added repositories should // remain. // @@ -538,4 +522,35 @@ namespace bpkg return 0; } + + void + rep_remove_verify (database& db, transaction&, bool verify_packages) + { + size_t rn (db.query_value ()); + size_t fn (db.query_value ()); + + // If there are no repositories stayed in the database then no repository + // fragments should stay either. + // + assert (rn != 0 || fn == 0); + + // If there are no repository fragments stayed in the database then no + // repositories with fragments nor packages should stay either. + // + // Note that repositories may not have any fragments if they are not + // fetched yet or due to the refname exclusions in the repository URL + // fragments (see repository-types(1) for details). + // + if (fn == 0) + { + // If there are some repositories have stayed, then make sure that none + // of them have any fragments. + // + assert (rn == 0 || + db.query_value ("repository!=''") == 0); + + if (verify_packages) + assert (db.query_value () == 0); + } + } } -- cgit v1.1