aboutsummaryrefslogtreecommitdiff
path: root/bpkg/pkg-build.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-10-31 16:19:23 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-10-31 17:50:03 +0300
commit11bfc20a0b6c5c90d6e2efab5b871bf3c76f733f (patch)
tree95b812040c06bd9a9bbb6c82e9b0518ed017d800 /bpkg/pkg-build.cxx
parent7d03940f6816329fa9ae131591717749bc76be5a (diff)
Fix pkg-build crash for multiple repos with same location URL
Diffstat (limited to 'bpkg/pkg-build.cxx')
-rw-r--r--bpkg/pkg-build.cxx29
1 files changed, 26 insertions, 3 deletions
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<repository>;
+ // 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<repository> r;
+ {
+ using query = query<repository>;
+
+ auto q (db.query<repository> (query::location.url == l));
+ auto i (q.begin ());
- shared_ptr<repository> r (
- db.query_one<repository> (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