From 333c5953151d6324d83d279a7ac3c53cd1af54b9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 15 Sep 2015 10:58:17 +0200 Subject: Implement pkg-verify, pkg-fetch commands --- bpkg/pkg-fetch.cxx | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 bpkg/pkg-fetch.cxx (limited to 'bpkg/pkg-fetch.cxx') diff --git a/bpkg/pkg-fetch.cxx b/bpkg/pkg-fetch.cxx new file mode 100644 index 0000000..89283c6 --- /dev/null +++ b/bpkg/pkg-fetch.cxx @@ -0,0 +1,114 @@ +// file : bpkg/pkg-fetch.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include // shared_ptr + +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace butl; + +namespace bpkg +{ + void + pkg_fetch (const pkg_fetch_options& o, cli::scanner& args) + { + tracer trace ("pkg_fetch"); + + dir_path d (o.directory ()); + level4 ([&]{trace << "configuration: " << d;}); + + database db (open (d)); + + path a; + bool purge; + + if (o.archive ()) + { + if (!args.more ()) + fail << "archive path argument expected" << + info << "run 'bpkg help pkg-fetch' for more information"; + + a = path (args.next ()); + + if (!exists (a)) + fail << "archive file '" << a << "' does not exist"; + + purge = false; + } + else + { + if (!args.more ()) + fail << "package name argument expected" << + info << "run 'bpkg help pkg-fetch' for more information"; + + string name (args.next ()); + + if (!args.more ()) + fail << "package version argument expected" << + info << "run 'bpkg help pkg-fetch' for more information"; + + string ver (args.next ()); + + // TODO: + // + // - Will need to use some kind or auto_rm/exception guard on + // fetched file. + // + + fail << "pkg-fetch " << name << " " << ver << " not yet implemented"; + purge = true; + } + + level4 ([&]{trace << "package archive: " << a << ", purge: " << purge;}); + + // Verify archive is a package and get its manifest. + // + package_manifest m (pkg_verify (a)); + level4 ([&]{trace << m.name << " " << m.version;}); + + const auto& n (m.name); + + // Database time. + // + transaction t (db.begin ()); + + // See if this package already exists in this configuration. + // + if (shared_ptr p = db.find (n)) + fail << "package " << n << " already exists in configuration " << d << + info << "existing version: " << p->version << ", state: " << p->state; + + // Make the archive and configuration paths absolute and normalized. + // If the archive is inside the configuration, use the relative path. + // This way we can move configuration around. + // + d.complete ().normalize (); + a.complete ().normalize (); + + if (a.sub (d)) + a = a.leaf (d); + + // Add the package to the configuration. + // + package p {move (m.name), + move (m.version), + state::fetched, + move (a), + purge}; + + db.persist (p); + t.commit (); + } +} -- cgit v1.1