Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fs::copy and fs::rename #574

Merged
merged 1 commit into from Mar 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not how rename should work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, we need a sys_rename, but it is ok for now

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