Skip to content

Commit 3801c26

Browse files
committed
rollup merge of #20231: fhahn/issue-20226-eexist
I've created a patch for #20226, which maps `EEXIST` to the `PathAlreadyExists` error on Unix. To test this, I use `mkdir`, which raises `EEXIST` if the directory already exists. On Windows, I map `ERROR_ALREADY_EXISTS` to `PathAlreadyExist`, but I am note sure if `mkdir` on Windows raises `ERROR_ALREADY_EXISTS` and do not have a Windows installation handy for testing. And I noticed another thing. No error seems to map to `IoErrorKind::PathDoesntExist` and I am wondering what the difference to `FileNotFound` is?
2 parents bcd3b16 + eb4b202 commit 3801c26

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)