aboutsummaryrefslogtreecommitdiff
path: root/bpkg/rep-add.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-06-18 21:28:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-06-18 21:28:19 +0200
commita7328a438ed26dc0d74238a575c118ca82892b5e (patch)
tree472533629a63c9884808acbd01b75560e50158e9 /bpkg/rep-add.cxx
parent31421516334f8e41a04c75a1fed86b4cecd11526 (diff)
Rename cfg-{add,fetch} to rep-{add,fetch} (aliases stay same)
The rationale: we now need the 'add' command for certificates (i.e., add a trusted certificate to the configuration). In the old naming scheme we would have to call it cfg-add which is already taken. In the new scheme we will call it crt-add.
Diffstat (limited to 'bpkg/rep-add.cxx')
-rw-r--r--bpkg/rep-add.cxx66
1 files changed, 66 insertions, 0 deletions
diff --git a/bpkg/rep-add.cxx b/bpkg/rep-add.cxx
new file mode 100644
index 0000000..da5bd4b
--- /dev/null
+++ b/bpkg/rep-add.cxx
@@ -0,0 +1,66 @@
+// file : bpkg/rep-add.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <bpkg/rep-add>
+
+#include <bpkg/package>
+#include <bpkg/package-odb>
+#include <bpkg/database>
+#include <bpkg/diagnostics>
+#include <bpkg/manifest-utility>
+
+using namespace std;
+using namespace butl;
+
+namespace bpkg
+{
+ int
+ rep_add (const rep_add_options& o, cli::scanner& args)
+ {
+ tracer trace ("rep_add");
+
+ dir_path c (o.directory ());
+ l4 ([&]{trace << "configuration: " << c;});
+
+ if (!args.more ())
+ fail << "repository location argument expected" <<
+ info << "run 'bpkg help rep-add' for more information";
+
+ repository_location rl (parse_location (args.next ()));
+ const string& rn (rl.canonical_name ());
+
+ // Create the new repository and add is as a complement to the root.
+ //
+ database db (open (c, trace));
+ transaction t (db.begin ());
+ session s; // Repository dependencies can have cycles.
+
+ // It is possible that this repository is already in the database.
+ // For example, it might be a prerequisite of one of the already
+ // added repository.
+ //
+ shared_ptr<repository> r (db.find<repository> (rl.canonical_name ()));
+
+ if (r == nullptr)
+ {
+ r.reset (new repository (rl));
+ db.persist (r);
+ }
+
+ shared_ptr<repository> root (db.load<repository> (""));
+
+ if (!root->complements.insert (lazy_shared_ptr<repository> (db, r)).second)
+ {
+ fail << rn << " is already a repository of this configuration";
+ }
+
+ db.update (root);
+ t.commit ();
+
+ if (verb)
+ text << "added repository " << rn;
+
+ return 0;
+ }
+}