Skip to content

Commit eb4b202

Browse files
committed
Map EEXIST to PathAlreadyExists error, closes #20226
1 parent f673e98 commit eb4b202

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/libstd/io/fs.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,19 @@ mod test {
11481148
check!(rmdir_recursive(dir));
11491149
}
11501150

1151+
#[test]
1152+
fn mkdir_path_already_exists_error() {
1153+
use io::{IoError, PathAlreadyExists};
1154+
1155+
let tmpdir = tmpdir();
1156+
let dir = &tmpdir.join("mkdir_error_twice");
1157+
check!(mkdir(dir, io::USER_RWX));
1158+
match mkdir(dir, io::USER_RWX) {
1159+
Err(IoError{kind:PathAlreadyExists,..}) => (),
1160+
_ => assert!(false)
1161+
};
1162+
}
1163+
11511164
#[test]
11521165
fn recursive_mkdir() {
11531166
let tmpdir = tmpdir();

src/libstd/sys/unix/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ pub fn decode_error(errno: i32) -> IoError {
109109
"file descriptor is not a TTY"),
110110
libc::ETIMEDOUT => (io::TimedOut, "operation timed out"),
111111
libc::ECANCELED => (io::TimedOut, "operation aborted"),
112+
libc::consts::os::posix88::EEXIST =>
113+
(io::PathAlreadyExists, "path already exists"),
112114

113115
// These two constants can have the same value on some systems,
114116
// but different values on others, so we can't use a match

src/libstd/sys/windows/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ pub fn decode_error(errno: i32) -> IoError {
121121
"invalid handle provided to function"),
122122
libc::ERROR_NOTHING_TO_TERMINATE =>
123123
(io::InvalidInput, "no process to kill"),
124+
libc::ERROR_ALREADY_EXISTS =>
125+
(io::PathAlreadyExists, "path already exists"),
124126

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

0 commit comments

Comments
 (0)