Boost logo

Boost :

From: Lars Gullik Bjønnes (larsbj_at_[hidden])
Date: 2005-01-28 06:44:24


Jonathan Wakely <cow_at_[hidden]> writes:

| Looking at the implementation of copy_file() I'm wondering why it isn't
| done like this (this provides noclobber support too):
>
| std::fstream out;
| if (noclobber)
| {
| out.open(to_file_ph.string().c_str(), std::ios::in);

wouldn't a exists work equally well?
(a bit less heavyweight perhaps)

| if (out.is_open())
| {
| // file exists
| boost::throw_exception( filesystem_error(
| "boost::filesystem::copy_file",
| from_file_ph, to_file_ph, fs::detail::system_error_code() ) );
| }
| }
| std::ifstream in(from_file_ph.string().c_str());
| out.open(to_file_ph.string().c_str(), std::ios::out);

Add std::ios::trunc here and we are in violent agreement.

| out << in.rdbuf();
>
| It may not be blindingly fast on all systems (though there's no reason
| it can't be, with a good filebuf)

Might be that the code could work directly on filebuf as well.

-- 
	Lgb

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk