]> 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?

1  2 
src/libstd/io/fs.rs

diff --combined src/libstd/io/fs.rs
index f2db2875ebf2ca44f1da07f55630ceba7cf813a5,10578fbb3fff0e00389293ae081d88605418b009..caa6590bb28212bd7cb8dc192d1c4bed0bbc0c56
@@@ -931,11 -931,11 +931,11 @@@ mod test 
          {
              let mut read_stream = File::open_mode(filename, Open, Read);
              {
 -                let read_buf = read_mem[mut 0..4];
 +                let read_buf = read_mem.slice_mut(0, 4);
                  check!(read_stream.read(read_buf));
              }
              {
 -                let read_buf = read_mem[mut 4..8];
 +                let read_buf = read_mem.slice_mut(4, 8);
                  check!(read_stream.read(read_buf));
              }
          }
          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();