diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-09-16 07:16:06 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-09-16 07:16:06 +0200 |
commit | 236ad71b105365bedf9d28a5606616fb9aed3168 (patch) | |
tree | 3e9c4943c6ea854ed1c931033f7f62916585cd81 /bpkg/pkg-verify.cxx | |
parent | fbe0716682ad4fd64df670978785db372cbe2ed2 (diff) |
Implement pkg-unpack command
Diffstat (limited to 'bpkg/pkg-verify.cxx')
-rw-r--r-- | bpkg/pkg-verify.cxx | 57 |
1 files changed, 57 insertions, 0 deletions
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 <bpkg/pkg-verify> +#include <fstream> + #include <butl/process> #include <butl/fdstream> @@ -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 <name>-<version>. + // + 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) { |