From b89c31a331a4e465e5ce69194c02833924bf5678 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sun, 24 Jul 2016 16:56:58 +0300 Subject: Use cpfile() for file fetching --- bpkg/fetch.cxx | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'bpkg') diff --git a/bpkg/fetch.cxx b/bpkg/fetch.cxx index e095785..85d6583 100644 --- a/bpkg/fetch.cxx +++ b/bpkg/fetch.cxx @@ -624,36 +624,13 @@ namespace bpkg static path fetch_file (const path& f, const dir_path& d) { - if (!exists (f)) - fail << "file " << f << " does not exist"; - path r (d / f.leaf ()); - if (exists (r)) - fail << "file " << r << " already exists"; - try { - // @@ Shouldn't we use cpfile() instead? - // - // @@ Yes, definitely. - // - ifdstream ifs (f, ios::binary); - - auto_rm arm; - ofdstream ofs (r, ios::binary); - arm = auto_rm (r); - - ofs << ifs.rdbuf (); - - // In case they throw. - // - ifs.close (); - ofs.close (); - - arm.cancel (); + cpfile (f, r); } - catch (const ifdstream::failure& e) + catch (const system_error& e) { fail << "unable to copy " << f << " to " << r << ": " << e.what (); } -- cgit v1.1