From 25616b791461608b082291dda431d8247fe8fb21 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 16 Jan 2018 12:21:37 +0200 Subject: Factor out bpkg repository fetching code used in rep-fetch and rep-info Note that now rep-info in the manifest mode does not dump any of the repository type-specific information. --- bpkg/rep-info.cxx | 87 +++++++++++++++---------------------------------------- 1 file changed, 24 insertions(+), 63 deletions(-) (limited to 'bpkg/rep-info.cxx') diff --git a/bpkg/rep-info.cxx b/bpkg/rep-info.cxx index 322ff6b..128951a 100644 --- a/bpkg/rep-info.cxx +++ b/bpkg/rep-info.cxx @@ -12,11 +12,12 @@ #include #include -#include #include #include #include +#include + using namespace std; using namespace butl; @@ -38,65 +39,14 @@ namespace bpkg : nullopt)); // Fetch everything we will need before printing anything. Ignore - // unknown manifest entries unless we are dumping them. First fetch - // the repositories list and authenticate the base's certificate. + // unknown manifest entries unless we are dumping them. // - pair rmc ( - fetch_repositories (o, rl, !o.manifest ())); - - repository_manifests& rms (rmc.first); - - bool a (o.auth () != auth::none && - (o.auth () == auth::all || rl.remote ())); - - const optional cert_pem (rms.back ().certificate); - shared_ptr cert; - - if (a) - { - dir_path d (o.directory ()); - cert = authenticate_certificate ( - o, - o.directory_specified () && d.empty () ? nullptr : &d, - cert_pem, - rl); - - a = !cert->dummy (); - } - - // Now fetch the packages list and make sure it matches the repositories - // we just fetched. - // - pair pmc ( - fetch_packages (o, rl, !o.manifest ())); - - package_manifests& pms (pmc.first); - - if (rmc.second != pms.sha256sum) - fail << "repositories manifest file checksum mismatch for " - << rl.canonical_name () << - info << "try again"; - - if (a) - { - signature_manifest sm (fetch_signature (o, rl, true)); - - if (sm.sha256sum != pmc.second) - fail << "packages manifest file checksum mismatch for " - << rl.canonical_name () << - info << "try again"; - - dir_path d (o.directory ()); - assert (cert != nullptr); - - authenticate_repository ( - o, - o.directory_specified () && d.empty () ? nullptr : &d, - cert_pem, - *cert, - sm, - rl); - } + dir_path d (o.directory ()); + rep_fetch_data rfd ( + rep_fetch (o, + o.directory_specified () && d.empty () ? nullptr : &d, + rl, + !o.manifest () /* ignore_unknow */)); // Now print. // @@ -121,6 +71,9 @@ namespace bpkg // if (all || cert_info) { + shared_ptr& cert (rfd.certificate); + const optional& cert_pem (rfd.repositories.back ().certificate); + if (cert_pem) { // Repository is signed. If we got the repository certificate as the @@ -192,12 +145,16 @@ namespace bpkg { if (o.manifest ()) { + // Note: serializing without any extra repository_manifests info. + // manifest_serializer s (cout, "STDOUT"); - rms.serialize (s); + for (const repository_manifest& rm: rfd.repositories) + rm.serialize (s); + s.next ("", ""); // End of stream. } else { - for (const repository_manifest& rm: rms) + for (const repository_manifest& rm: rfd.repositories) { repository_role rr (rm.effective_role ()); @@ -228,8 +185,12 @@ namespace bpkg { if (o.manifest ()) { + // Note: serializing without any extra package_manifests info. + // manifest_serializer s (cout, "STDOUT"); - pms.serialize (s); + for (const package_manifest& pm: rfd.packages) + pm.serialize (s); + s.next ("", ""); // End of stream. } else { @@ -237,7 +198,7 @@ namespace bpkg // cout << endl; - for (const package_manifest& pm: pms) + for (const package_manifest& pm: rfd.packages) cout << pm.name << "/" << pm.version << endl; } } -- cgit v1.1