]> git.lizzy.rs Git - rust.git/commitdiff
rollup merge of #20231: fhahn/issue-20226-eexist
authorAlex Crichton <alex@alexcrichton.com>
Tue, 30 Dec 2014 00:36:12 +0000 (16:36 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 30 Dec 2014 00:36:12 +0000 (16:36 -0800)
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?

src/libstd/io/fs.rs
src/libstd/sys/unix/mod.rs
src/libstd/sys/windows/mod.rs

index f2db2875ebf2ca44f1da07f55630ceba7cf813a5..caa6590bb28212bd7cb8dc192d1c4bed0bbc0c56 100644 (file)
@@ -1148,6 +1148,19 @@ fn file_test_walk_dir() {
         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();
index f3babca32871ae86d8b36da38c2ac4c899a63522..4b7ac8ff4d3a962e3f3c33dce1e784f0cd1e93d6 100644 (file)
@@ -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
index 6924687d8c470235bed45caa3f5384fd07fe70db..aee98e22836be89280114a9260ebb6376e8955c3 100644 (file)
@@ -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