From 2a362e8f024c032e14cff13cbca2a27a47c79448 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 30 Aug 2018 23:17:15 +0300 Subject: Add package manifest flags --- libbpkg/manifest.cxx | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'libbpkg/manifest.cxx') diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx index 31c5ce0..9751e12 100644 --- a/libbpkg/manifest.cxx +++ b/libbpkg/manifest.cxx @@ -893,8 +893,8 @@ namespace bpkg static void parse_package_manifest (parser& p, name_value nv, - bool il, bool iu, + package_manifest_flags fl, package_manifest& m) { auto bad_name ([&p, &nv](const string& d) { @@ -954,6 +954,11 @@ namespace bpkg return email (move (p.first), move (p.second)); }; + auto flag = [fl] (package_manifest_flags f) + { + return (fl & f) != package_manifest_flags::none; + }; + for (nv = p.next (); !nv.empty (); nv = p.next ()) { string& n (nv.name); @@ -1052,7 +1057,7 @@ namespace bpkg } else if (n == "description-file") { - if (il) + if (flag (package_manifest_flags::forbid_file)) bad_name ("package description-file not allowed"); if (m.description) @@ -1084,7 +1089,7 @@ namespace bpkg } else if (n == "changes-file") { - if (il) + if (flag (package_manifest_flags::forbid_file)) bad_name ("package changes-file not allowed"); auto vc (parser::split_comment (v)); @@ -1294,7 +1299,7 @@ namespace bpkg } else if (n == "location") { - if (!il) + if (flag (package_manifest_flags::forbid_location)) bad_name ("package location not allowed"); if (m.location) @@ -1319,7 +1324,7 @@ namespace bpkg } else if (n == "sha256sum") { - if (!il) + if (flag (package_manifest_flags::forbid_sha256sum)) bad_name ("package sha256sum not allowed"); if (m.sha256sum) @@ -1332,7 +1337,7 @@ namespace bpkg } else if (n == "fragment") { - if (!il) + if (flag (package_manifest_flags::forbid_fragment)) bad_name ("package repository fragment not allowed"); if (m.fragment) @@ -1358,30 +1363,30 @@ namespace bpkg else if (m.license_alternatives.empty ()) bad_value ("no project license specified"); - if (il) - { - if (!m.location) - bad_name ("no package location specified"); + if (!m.location && flag (package_manifest_flags::require_location)) + bad_name ("no package location specified"); - if (!m.sha256sum) - bad_name ("no package sha256sum specified"); - } + if (!m.sha256sum && flag (package_manifest_flags::require_sha256sum)) + bad_name ("no package sha256sum specified"); } package_manifest pkg_package_manifest (parser& p, name_value nv, bool iu) { - package_manifest r; - parse_package_manifest (p, nv, true, iu, r); - return r; + return package_manifest (p, + move (nv), + iu, + package_manifest_flags::forbid_file | + package_manifest_flags::require_location | + package_manifest_flags::forbid_fragment); } // package_manifest // package_manifest:: - package_manifest (manifest_parser& p, bool iu) + package_manifest (manifest_parser& p, bool iu, package_manifest_flags fl) { - parse_package_manifest (p, p.next (), false, iu, *this); + parse_package_manifest (p, p.next (), iu, fl, *this); // Make sure this is the end. // @@ -1391,6 +1396,15 @@ namespace bpkg "single package manifest expected"); } + package_manifest:: + package_manifest (manifest_parser& p, + name_value nv, + bool iu, + package_manifest_flags fl) + { + parse_package_manifest (p, move (nv), iu, fl, *this); + } + static void serialize_package_manifest (manifest_serializer& s, const package_manifest& m, -- cgit v1.1