From 67a0e8d70f0caf8b85e0cf2031333236b2a3dcdf Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 24 Jan 2016 14:46:19 +0200 Subject: Add checksum verification --- bpkg/rep-create.cxx | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'bpkg/rep-create.cxx') diff --git a/bpkg/rep-create.cxx b/bpkg/rep-create.cxx index c6d07ec..cc2ade1 100644 --- a/bpkg/rep-create.cxx +++ b/bpkg/rep-create.cxx @@ -14,9 +14,11 @@ #include #include -#include #include #include + +#include +#include #include #include @@ -51,6 +53,9 @@ namespace bpkg using package_map = map; + static const path repositories ("repositories"); + static const path packages ("packages"); + static void collect (const rep_create_options& o, package_map& map, @@ -89,8 +94,7 @@ namespace bpkg // if (d == root) { - if (p == path ("repositories") || - p == path ("packages")) + if (p == repositories || p == packages) continue; } @@ -99,7 +103,12 @@ namespace bpkg path a (d / p); package_manifest m (pkg_verify (o, a, o.ignore_unknown ())); - level4 ([&]{trace << m.name << " " << m.version << " in " << a;}); + // Calculate its checksum. + // + m.sha256sum = sha256 (o, a); + + level4 ([&]{trace << m.name << " " << m.version << " in " << a + << " sha256sum " << *m.sha256sum;}); // Add package archive location relative to the repository root. // @@ -156,9 +165,22 @@ namespace bpkg package_map pm; collect (o, pm, d, d); + package_manifests manifests; + manifests.sha256sum = sha256 (o, path (d / repositories)); + + for (auto& p: pm) + { + package_manifest& m (p.second.manifest); + + if (verb) + text << "adding " << m.name << " " << m.version; + + manifests.emplace_back (move (m)); + } + // Serialize. // - path p (d / path ("packages")); + path p (d / packages); try { @@ -167,18 +189,7 @@ namespace bpkg ofs.open (p.string ()); manifest_serializer s (ofs, p.string ()); - - for (const auto& p: pm) - { - const package_manifest& m (p.second.manifest); - - if (verb) - text << "adding " << m.name << " " << m.version; - - m.serialize (s); - } - - s.next ("", ""); // The end. + manifests.serialize (s); } catch (const manifest_serialization& e) { -- cgit v1.1