about summary refs log tree commit diff
path: root/src/libstd/fs.rs
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2016-06-15 22:59:20 +0100
committerManish Goregaokar <manishsmail@gmail.com>2016-06-16 01:39:44 +0100
commite3d6bb1f71f372c37cb864d0f8f71cc256eae44b (patch)
tree0e6332f48ca979ef4f7279af9e3b202a2c456091 /src/libstd/fs.rs
parent2675a55a8fc9dcd13ed824c82fe7a921ae050d64 (diff)
parent552afd30d075f3c7ecc8918f088c3aa805f6cef7 (diff)
Rollup merge of #34270 - gkoz:error_file_exists, r=alexcrichton
Add ERROR_FILE_EXISTS to ErrorKind conversion on Windows

Bug report: https://users.rust-lang.org/t/detecting-error-kind-for-opening-file/6215
Reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx#error_file_exists
Diffstat (limited to 'src/libstd/fs.rs')
-rw-r--r--src/libstd/fs.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 0180c3118a5..668fa1fb303 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -512,7 +512,7 @@ impl OpenOptions {
     /// No file is allowed to exist at the target location, also no (dangling)
     /// symlink.
     ///
-    /// This option is useful because it as atomic. Otherwise between checking
+    /// This option is useful because it is atomic. Otherwise between checking
     /// whether a file exists and creating a new one, the file may have been
     /// created by another process (a TOCTOU race condition / attack).
     ///
@@ -1771,6 +1771,15 @@ mod tests {
     }
 
     #[test]
+    fn file_create_new_already_exists_error() {
+        let tmpdir = tmpdir();
+        let file = &tmpdir.join("file_create_new_error_exists");
+        check!(fs::File::create(file));
+        let e = fs::OpenOptions::new().write(true).create_new(true).open(file).unwrap_err();
+        assert_eq!(e.kind(), ErrorKind::AlreadyExists);
+    }
+
+    #[test]
     fn mkdir_path_already_exists_error() {
         let tmpdir = tmpdir();
         let dir = &tmpdir.join("mkdir_error_twice");