Use CopyFileEx for fs::copy on Windows
Adds a couple more tests for fs::copy Signed-off-by: Peter Atashian <retep998@gmail.com>
This commit is contained in:
parent
e6a9be10bc
commit
1d202692ec
4 changed files with 93 additions and 16 deletions
|
@ -14,7 +14,7 @@ use os::unix::prelude::*;
|
|||
|
||||
use ffi::{CString, CStr, OsString, OsStr};
|
||||
use fmt;
|
||||
use io::{self, Error, SeekFrom};
|
||||
use io::{self, Error, ErrorKind, SeekFrom};
|
||||
use libc::{self, c_int, size_t, off_t, c_char, mode_t};
|
||||
use mem;
|
||||
use path::{Path, PathBuf};
|
||||
|
@ -516,3 +516,19 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
|
|||
buf.truncate(p);
|
||||
Ok(PathBuf::from(OsString::from_vec(buf)))
|
||||
}
|
||||
|
||||
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
|
||||
use fs::{File, PathExt, set_permissions};
|
||||
if !from.is_file() {
|
||||
return Err(Error::new(ErrorKind::InvalidInput,
|
||||
"the source path is not an existing file"))
|
||||
}
|
||||
|
||||
let mut reader = try!(File::open(from));
|
||||
let mut writer = try!(File::create(to));
|
||||
let perm = try!(reader.metadata()).permissions();
|
||||
|
||||
let ret = try!(io::copy(&mut reader, &mut writer));
|
||||
try!(set_permissions(to, perm));
|
||||
Ok(ret)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue