Skip to content

Commit

Permalink
Merge pull request #574 from nounoursheureux/master
Browse files Browse the repository at this point in the history
Add fs::copy and fs::rename
  • Loading branch information
jackpot51 committed Mar 22, 2016
2 parents d3fd0db + c2baaba commit 46ff17a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion libstd/src/fs.rs
@@ -1,6 +1,6 @@
use core::ops::Deref;
use core_collections::borrow::ToOwned;
use io::{Read, Error, Result, Write, Seek, SeekFrom};
use io::{self, Read, Error, Result, Write, Seek, SeekFrom};
use os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use mem;
use path::{PathBuf, Path};
Expand Down Expand Up @@ -343,6 +343,17 @@ pub fn create_dir<P: AsRef<Path>>(path: P) -> Result<()> {
}
}

pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
let mut infile = try!(File::open(from));
let mut outfile = try!(File::create(to));
io::copy(&mut infile, &mut outfile)
}

pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<()> {
try!(copy(Path::new(from.as_ref()), to));
remove_file(from)
}

pub fn read_dir<P: AsRef<Path>>(path: P) -> Result<ReadDir> {
File::open(path).map(|file| ReadDir { file: file })
}
Expand Down

0 comments on commit 46ff17a

Please sign in to comment.