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/rep-create.cxx | 114 ++++++++-------------------------------------------- 1 file changed, 17 insertions(+), 97 deletions(-) (limited to 'bpkg/rep-create.cxx') diff --git a/bpkg/rep-create.cxx b/bpkg/rep-create.cxx index 42e7d55..9ea24c7 100644 --- a/bpkg/rep-create.cxx +++ b/bpkg/rep-create.cxx @@ -11,9 +11,7 @@ #include #include -#include -#include -#include +#include // dir_iterator #include #include @@ -21,6 +19,7 @@ #include #include +#include #include using namespace std; @@ -72,108 +71,29 @@ namespace bpkg continue; } - path fp (d / p); - - // Figure out the package directory. Strip the top-level extension - // and, as a special case, if the second-level extension is .tar, - // strip that as well (e.g., .tar.bz2). + // Verify archive is a package and get its manifest. // - p = p.base (); - if (const char* e = p.extension ()) - { - if (e == string ("tar")) - p = p.base (); - } + path a (d / p); + package_manifest m (pkg_verify (a)); - level4 ([&]{trace << "found package " << p << " in " << fp;}); + level4 ([&]{trace << m.name << " " << m.version << " in " << a;}); - // Extract the manifest. + // Add package archive location relative to the repository root. // - path mf (p / path ("manifest")); - - const char* args[] { - "tar", - "-xOf", // -O/--to-stdout -- extract to STDOUT. - fp.string ().c_str (), - mf.string ().c_str (), - nullptr}; - - if (verb >= 2) - print_process (args); + m.location = a.leaf (root); - try - { - process pr (args, 0, -1); // Open pipe to stdout. - - try - { - ifdstream is (pr.in_ofd); - is.exceptions (ifdstream::badbit | ifdstream::failbit); - - manifest_parser mp (is, mf.string ()); - package_manifest m (mp); - - // Verify package archive/directory is -. - // - { - path ep (m.name + "-" + m.version.string ()); - - if (p != ep) - fail << "package archive/directory name mismatch in " << fp << - info << "extracted from archive '" << p << "'" << - info << "expected from manifest '" << ep << "'"; - } - - // Add package archive location relative to the repository root. - // - m.location = fp.leaf (root); - - package_key k (m.name, m.version); // Argument evaluation order. - auto r (map.emplace (move (k), package_data (fp, move (m)))); - - // Diagnose duplicates. - // - if (!r.second) - { - const package_manifest& m (r.first->second.second); - - fail << "duplicate package " << m.name << " " << m.version << - info << "first package archive is " << r.first->second.first << - info << "second package archive is " << fp; - } - } - // Ignore these exceptions if the child process exited with - // an error status since that's the source of the failure. - // - catch (const manifest_parsing& e) - { - if (pr.wait ()) - fail (e.name, e.line, e.column) << e.description << - info << "package archive " << fp; - } - catch (const ifdstream::failure&) - { - if (pr.wait ()) - fail << "unable to extract " << mf << " from " << fp; - } + package_key k (m.name, m.version); // Argument evaluation order. + auto r (map.emplace (move (k), package_data (a, move (m)))); - if (!pr.wait ()) - { - // While it is reasonable to assuming the child process issued - // diagnostics, tar, specifically, doesn't mention the archive - // name. - // - fail << fp << " does not appear to be a bpkg package"; - } - } - catch (const process_error& e) + // Diagnose duplicates. + // + if (!r.second) { - error << "unable to execute " << args[0] << ": " << e.what (); - - if (e.child ()) - exit (1); + const package_manifest& m (r.first->second.second); - throw failed (); + fail << "duplicate package " << m.name << " " << m.version << + info << "first package archive is " << r.first->second.first << + info << "second package archive is " << a; } } } -- cgit v1.1