From 915988225227ba3f300739b3655a6b4c01c3c46c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 22 Jul 2016 23:02:37 +0300 Subject: Adapt to fdstream extension --- load/load.cxx | 70 +++++++++++++++++++++++++---------------------------------- 1 file changed, 29 insertions(+), 41 deletions(-) (limited to 'load') diff --git a/load/load.cxx b/load/load.cxx index 1f925db..2e06644 100644 --- a/load/load.cxx +++ b/load/load.cxx @@ -3,7 +3,6 @@ // license : MIT; see accompanying LICENSE file #include // strncmp() -#include #include #include // find(), find_if() @@ -18,6 +17,7 @@ #include #include #include +#include #include #include // manifest_parsing @@ -76,17 +76,10 @@ load_repositories (path p) if (p.relative ()) p.complete (); - ifstream ifs (p.string ()); - if (!ifs.is_open ()) - { - cerr << "error: unable to open " << p << " in read mode" << endl; - throw failed (); - } - - ifs.exceptions (ifstream::badbit); - try { + ifdstream ifs (p, ifdstream::in, ifdstream::badbit); + string s; for (uint64_t l (1); getline (ifs, s); ++l) { @@ -237,9 +230,9 @@ load_repositories (path p) bad_line ("junk after filesystem path"); } } - catch (const ifstream::failure&) + catch (const ifdstream::failure& e) { - cerr << "error: unable to read " << p << endl; + cerr << "error: unable to read " << p << ": " << e.what () << endl; throw failed (); } @@ -314,20 +307,6 @@ repository_info (const options& lo, const string& rl, const cstrings& options) } } -static timestamp -manifest_stream (const path& p, ifstream& f) -{ - f.open (p.string ()); - if (!f.is_open ()) - { - cerr << "error: unable to open " << p << " in read mode" << endl; - throw failed (); - } - - f.exceptions (ifstream::badbit | ifstream::failbit); - return file_mtime (p); -} - // Load the repository packages from the 'packages' file and persist the // repository. Should be called once per repository. // @@ -345,15 +324,21 @@ load_packages (const shared_ptr& rp, database& db) assert (!rp->cache_location.empty ()); package_manifests pkm; + path p (rp->cache_location.path () / path ("packages")); + try { - ifstream ifs; - path p (rp->cache_location.path () / path ("packages")); - rp->packages_timestamp = manifest_stream (p, ifs); + ifdstream ifs (p); + rp->packages_timestamp = file_mtime (p); manifest_parser mp (ifs, p.string ()); pkm = package_manifests (mp); } + catch (const ifdstream::failure& e) + { + cerr << "error: unable to read " << p << ": " << e.what () << endl; + throw failed (); + } for (auto& pm: pkm) { @@ -484,14 +469,21 @@ load_repositories (const shared_ptr& rp, database& db) repository_manifests rpm; + path p (rp->cache_location.path () / path ("repositories")); + + try { - ifstream ifs; - path p (rp->cache_location.path () / path ("repositories")); - rp->repositories_timestamp = manifest_stream (p, ifs); + ifdstream ifs (p); + rp->repositories_timestamp = file_mtime (p); manifest_parser mp (ifs, p.string ()); rpm = repository_manifests (mp); } + catch (const ifdstream::failure& e) + { + cerr << "error: unable to read " << p << ": " << e.what () << endl; + throw failed (); + } for (auto& rm: rpm) { @@ -868,11 +860,11 @@ certificate_info (const options& lo, process pr (repository_info (lo, rl.string (), args)); - ifdstream is (pr.in_ofd); - is.exceptions (ifdstream::failbit | ifdstream::badbit | ifdstream::eofbit); - try { + ifdstream is ( + pr.in_ofd, ifdstream::failbit | ifdstream::badbit | ifdstream::eofbit); + optional cert; string fingerprint; @@ -900,7 +892,7 @@ certificate_info (const options& lo, // is.exceptions (ifdstream::failbit | ifdstream::badbit); if (is.peek () != ifdstream::traits_type::eof ()) - throw system_error (EIO, system_category ()); + throw ifdstream::failure (""); is.close (); @@ -910,12 +902,8 @@ certificate_info (const options& lo, // Fall through. // } - catch (const system_error&) + catch (const ifdstream::failure&) { - // Child input reading error. - // - is.close (); - // Child exit status doesn't matter. Just wait for the process // completion and fall through. // -- cgit v1.1