rollup merge of #19016: gkoz/use_util_copy

This code is identical to io::util::copy()
This commit is contained in:
Jakub Bukaj 2014-11-18 00:24:03 +01:00
commit f1fd6b9407

View file

@ -381,16 +381,8 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> {
let mut reader = try!(File::open(from));
let mut writer = try!(File::create(to));
let mut buf = [0, ..io::DEFAULT_BUF_SIZE];
loop {
let amt = match reader.read(&mut buf) {
Ok(n) => n,
Err(ref e) if e.kind == io::EndOfFile => { break }
Err(e) => return update_err(Err(e), from, to)
};
try!(writer.write(buf[..amt]));
}
try!(update_err(super::util::copy(&mut reader, &mut writer), from, to));
chmod(to, try!(update_err(from.stat(), from, to)).perm)
}