Skip to content

Map EEXIST to PathAlreadyExists error, closes #20226 #20231

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

Merged
merged 1 commit into from
Dec 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/libstd/io/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,19 @@ mod test {
check!(rmdir_recursive(dir));
}

#[test]
fn mkdir_path_already_exists_error() {
use io::{IoError, PathAlreadyExists};

let tmpdir = tmpdir();
let dir = &tmpdir.join("mkdir_error_twice");
check!(mkdir(dir, io::USER_RWX));
match mkdir(dir, io::USER_RWX) {
Err(IoError{kind:PathAlreadyExists,..}) => (),
_ => assert!(false)
};
}

#[test]
fn recursive_mkdir() {
let tmpdir = tmpdir();
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ pub fn decode_error(errno: i32) -> IoError {
"file descriptor is not a TTY"),
libc::ETIMEDOUT => (io::TimedOut, "operation timed out"),
libc::ECANCELED => (io::TimedOut, "operation aborted"),
libc::consts::os::posix88::EEXIST =>
(io::PathAlreadyExists, "path already exists"),

// These two constants can have the same value on some systems,
// but different values on others, so we can't use a match
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ pub fn decode_error(errno: i32) -> IoError {
"invalid handle provided to function"),
libc::ERROR_NOTHING_TO_TERMINATE =>
(io::InvalidInput, "no process to kill"),
libc::ERROR_ALREADY_EXISTS =>
(io::PathAlreadyExists, "path already exists"),

// libuv maps this error code to EISDIR. we do too. if it is found
// to be incorrect, we can add in some more machinery to only
Expand Down