aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bpkg/rep-fetch.cxx4
-rw-r--r--bpkg/rep-mask.cxx11
-rw-r--r--bpkg/rep-remove.cxx55
-rw-r--r--bpkg/rep-remove.hxx7
4 files changed, 57 insertions, 20 deletions
diff --git a/bpkg/rep-fetch.cxx b/bpkg/rep-fetch.cxx
index d02a064..fe25b86 100644
--- a/bpkg/rep-fetch.cxx
+++ b/bpkg/rep-fetch.cxx
@@ -1552,6 +1552,10 @@ namespace bpkg
}
}
+#ifndef NDEBUG
+ rep_remove_verify (db, t);
+#endif
+
// Make sure that the external packages are available from a single
// directory-based repository.
//
diff --git a/bpkg/rep-mask.cxx b/bpkg/rep-mask.cxx
index d7f9c6a..e670005 100644
--- a/bpkg/rep-mask.cxx
+++ b/bpkg/rep-mask.cxx
@@ -6,6 +6,7 @@
#include <bpkg/package.hxx>
#include <bpkg/package-odb.hxx>
#include <bpkg/database.hxx>
+#include <bpkg/rep-remove.hxx> // rep_remove_verify()
#include <bpkg/diagnostics.hxx>
#include <bpkg/package-query.hxx> // repo_configs
#include <bpkg/manifest-utility.hxx> // repository_name()
@@ -273,6 +274,16 @@ namespace bpkg
for (database& db: repo_configs)
{
+ // While at it, verify that the repository information has stayed
+ // consistent after the potential repository removals.
+ //
+ // Note that rep_remove() doesn't remove the available packages in the
+ // mask mode and thus we don't verify them.
+ //
+#ifndef NDEBUG
+ rep_remove_verify (db, t, false /* verify_packages */);
+#endif
+
// Add the repository location canonical name to the database-specific
// unmasked repositories or repository fragments lists. Note that
// repository location is used only for tracing.
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<repository_count> () == 0)
- assert (db.query_value<repository_fragment_count> () == 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<repository_fragment_count> () == 0)
- {
- assert (db.query_value<repository_count> () == 0);
- assert (mask || db.query_value<available_package_count> () == 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<repository_count> ());
+ size_t fn (db.query_value<repository_fragment_count> ());
+
+ // 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<fragment_repository_count> ("repository!=''") == 0);
+
+ if (verify_packages)
+ assert (db.query_value<available_package_count> () == 0);
+ }
+ }
}
diff --git a/bpkg/rep-remove.hxx b/bpkg/rep-remove.hxx
index 0fc82e8..94a38c6 100644
--- a/bpkg/rep-remove.hxx
+++ b/bpkg/rep-remove.hxx
@@ -57,6 +57,13 @@ namespace bpkg
rep_remove_package_locations (database&,
transaction&,
const string& fragment_name);
+
+ // Verify that after all the repository/fragment removals the repository
+ // information is consistent in the database (if no repositories stayed then
+ // no fragments stayed either, etc).
+ //
+ void
+ rep_remove_verify (database&, transaction&, bool verify_packages = true);
}
#endif // BPKG_REP_REMOVE_HXX