From 04ea94103db92d6d27230794e14606547aacf670 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 24 Sep 2015 08:08:23 +0200 Subject: Factor and reuse manifest fetching code --- bpkg/rep-fetch.cxx | 60 ++++-------------------------------------------------- 1 file changed, 4 insertions(+), 56 deletions(-) (limited to 'bpkg/rep-fetch.cxx') diff --git a/bpkg/rep-fetch.cxx b/bpkg/rep-fetch.cxx index 7bb5652..89107aa 100644 --- a/bpkg/rep-fetch.cxx +++ b/bpkg/rep-fetch.cxx @@ -8,8 +8,8 @@ #include #include -#include +#include #include #include #include @@ -35,42 +35,14 @@ namespace bpkg const repository_location& rl (r->location); level4 ([&]{trace << r->name () << " " << rl;}); - - assert (rl.absolute () /*|| rl.remote ()*/); + assert (rl.absolute () || rl.remote ()); r->fetched = true; // Mark as being fetched. - //@@ The same code as in rep-create. - // - // Load the 'repositories' file and use it to populate the // prerequisite and complement repository sets. // - repository_manifests rms; - { - path f (rl.path () / path ("repositories")); - - if (!exists (f)) - fail << "file " << f << " does not exist"; - - try - { - ifstream ifs; - ifs.exceptions (ofstream::badbit | ofstream::failbit); - ifs.open (f.string ()); - - manifest_parser mp (ifs, f.string ()); - rms = repository_manifests (mp); - } - catch (const manifest_parsing& e) - { - fail (e.name, e.line, e.column) << e.description; - } - catch (const ifstream::failure&) - { - fail << "unable to read from " << f; - } - } + repository_manifests rms (fetch_repositories (rl)); for (repository_manifest& rm: rms) { @@ -126,31 +98,7 @@ namespace bpkg // @@ We need to check that that 'repositories' file hasn't // changed since. // - package_manifests pms; - { - path f (rl.path () / path ("packages")); - - if (!exists (f)) - fail << "file " << f << " does not exist"; - - try - { - ifstream ifs; - ifs.exceptions (ofstream::badbit | ofstream::failbit); - ifs.open (f.string ()); - - manifest_parser mp (ifs, f.string ()); - pms = package_manifests (mp); - } - catch (const manifest_parsing& e) - { - fail (e.name, e.line, e.column) << e.description; - } - catch (const ifstream::failure&) - { - fail << "unable to read from " << f; - } - } + package_manifests pms (fetch_packages (rl)); // "Suspend" session while persisting packages to reduce memory // consumption. -- cgit v1.1