From 11bfc20a0b6c5c90d6e2efab5b871bf3c76f733f Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 31 Oct 2019 16:19:23 +0300 Subject: Fix pkg-build crash for multiple repos with same location URL --- bpkg/pkg-build.cxx | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'bpkg') diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx index 6c218d5..fa788e2 100644 --- a/bpkg/pkg-build.cxx +++ b/bpkg/pkg-build.cxx @@ -2678,10 +2678,33 @@ namespace bpkg // to parse it. Note that the straight parsing could otherwise fail, // being unable to properly guess the repository type. // - using query = query; + // Also note that the repository location URL is not unique and we + // can potentially end up with multiple repositories. For example: + // + // $ bpkg add git+file:/path/to/git/repo dir+file:/path/to/git/repo + // $ bpkg build @/path/to/git/repo + // + // That's why we pick the repository only if there is exactly one + // match. + // + shared_ptr r; + { + using query = query; + + auto q (db.query (query::location.url == l)); + auto i (q.begin ()); - shared_ptr r ( - db.query_one (query::location.url == l)); + if (i != q.end ()) + { + r = i.load (); + + // Fallback to parsing the location if several repositories + // match. + // + if (++i != q.end ()) + r = nullptr; + } + } ps.location = r != nullptr ? r->location -- cgit v1.1