aboutsummaryrefslogtreecommitdiff
path: root/bpkg/pkg-fetch.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-25 15:19:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-25 15:19:16 +0200
commit8049a4de3a5d77d28f9dbc6b2d712b280548a08a (patch)
tree2ade1611947f617120380f22647cdf4d3df1c0ff /bpkg/pkg-fetch.cxx
parent8aa9fd02fdbe7b2de9cbd02564431d74b620b1d9 (diff)
Implement archive fetching, complete pkg-fetch
Diffstat (limited to 'bpkg/pkg-fetch.cxx')
-rw-r--r--bpkg/pkg-fetch.cxx62
1 files changed, 50 insertions, 12 deletions
diff --git a/bpkg/pkg-fetch.cxx b/bpkg/pkg-fetch.cxx
index 63dd31f..bfa6e54 100644
--- a/bpkg/pkg-fetch.cxx
+++ b/bpkg/pkg-fetch.cxx
@@ -6,6 +6,7 @@
#include <bpkg/manifest>
+#include <bpkg/fetch>
#include <bpkg/types>
#include <bpkg/package>
#include <bpkg/package-odb>
@@ -29,6 +30,8 @@ namespace bpkg
level4 ([&]{trace << "configuration: " << c;});
database db (open (c, trace));
+ transaction t (db.begin ());
+ session s;
path a;
bool purge;
@@ -52,21 +55,60 @@ namespace bpkg
fail << "package name argument expected" <<
info << "run 'bpkg help pkg-fetch' for more information";
- string name (args.next ());
+ string n (args.next ());
if (!args.more ())
fail << "package version argument expected" <<
info << "run 'bpkg help pkg-fetch' for more information";
- string ver (args.next ());
-
- // TODO:
+ //@@ Same code as in pkg-status. Similar problem to repo_location;
+ // need a place for such utilities.
//
- // - Will need to use some kind or auto_rm/exception guard on
- // fetched file.
+ version v;
+ {
+ const char* s (args.next ());
+ try
+ {
+ v = version (s);
+ }
+ catch (const invalid_argument& e)
+ {
+ fail << "invalid package version '" << s << "': " << e.what ();
+ }
+ }
+
+ if (db.query_value<repository_count> () == 0)
+ fail << "configuration " << c << " has no repositories" <<
+ info << "use 'bpkg rep-add' to add a repository";
+
+ if (db.query_value<available_package_count> () == 0)
+ fail << "configuration " << c << " has no available packages" <<
+ info << "use 'bpkg rep-fetch' to fetch available packages list";
+
+ shared_ptr<available_package> p (
+ db.find<available_package> (package_version_id (n, v)));
+
+ if (p == nullptr)
+ fail << "package " << n << " " << v << " is not available";
+
+ // Pick a repository. Prefer local ones over the remote.
//
-
- fail << "pkg-fetch " << name << " " << ver << " not yet implemented";
+ const package_location* pl (&p->locations.front ());
+
+ for (const package_location& l: p->locations)
+ {
+ if (!l.repository.load ()->location.remote ())
+ {
+ pl = &l;
+ break;
+ }
+ }
+
+ if (verb > 1)
+ text << "fetching " << pl->location.leaf () << " "
+ << "from " << pl->repository->name ();
+
+ a = fetch_archive (o, pl->repository->location, pl->location, c);
purge = true;
}
@@ -79,10 +121,6 @@ namespace bpkg
const auto& n (m.name);
- // Database time.
- //
- transaction t (db.begin ());
-
// See if this package already exists in this configuration.
//
if (shared_ptr<package> p = db.find<package> (n))