aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-07-24 16:56:58 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-07-24 16:56:58 +0300
commitb89c31a331a4e465e5ce69194c02833924bf5678 (patch)
treeedccd5c445ee8caff7f3e8b0a3dfd04f95abf2c0
parent1d9f410810de6fbb9c974735e5e14dbebe1c0718 (diff)
Use cpfile() for file fetching
-rw-r--r--bpkg/fetch.cxx27
1 files changed, 2 insertions, 25 deletions
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 ();
}