From 236ad71b105365bedf9d28a5606616fb9aed3168 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 16 Sep 2015 07:16:06 +0200 Subject: Implement pkg-unpack command --- bpkg/pkg-verify.cxx | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'bpkg/pkg-verify.cxx') diff --git a/bpkg/pkg-verify.cxx b/bpkg/pkg-verify.cxx index a1aa64b..a7d215e 100644 --- a/bpkg/pkg-verify.cxx +++ b/bpkg/pkg-verify.cxx @@ -4,6 +4,8 @@ #include +#include + #include #include @@ -142,6 +144,61 @@ namespace bpkg } } + package_manifest + pkg_verify (const dir_path& d, bool diag) + { + // Parse the manifest. + // + path mf (d / path ("manifest")); + + if (!exists (mf)) + { + if (diag) + error << "no manifest file in package directory " << d; + + throw failed (); + } + + try + { + ifstream ifs; + ifs.exceptions (ifstream::badbit | ifstream::failbit); + ifs.open (mf.string ()); + + manifest_parser mp (ifs, mf.string ()); + package_manifest m (mp); + + // Verify package directory is -. + // + dir_path ed (m.name + "-" + m.version.string ()); + + if (d.leaf () != ed) + { + if (diag) + error << "invalid package directory name '" << d.leaf () << "'" << + info << "expected from manifest '" << ed << "'"; + + throw failed (); + } + + return m; + } + catch (const manifest_parsing& e) + { + if (diag) + error (e.name, e.line, e.column) << e.description; + + throw failed (); + } + catch (const ifstream::failure&) + { + if (diag) + error << "unable to read from " << mf; + + throw failed (); + } + } + void pkg_verify (const pkg_verify_options& o, cli::scanner& args) { -- cgit v1.1