about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-06-15 19:25:45 -0700
committerGitHub <noreply@github.com>2016-06-15 19:25:45 -0700
commit58adb0760726bfb6f19c055caa58af51ef393b57 (patch)
tree0e6332f48ca979ef4f7279af9e3b202a2c456091 /src/libstd
parentbb4a79b087158f396b984bdf552d2c90890b12a3 (diff)
parente3d6bb1f71f372c37cb864d0f8f71cc256eae44b (diff)
downloadrust-58adb0760726bfb6f19c055caa58af51ef393b57.tar.gz
rust-58adb0760726bfb6f19c055caa58af51ef393b57.zip
Auto merge of #34291 - Manishearth:rollup, r=Manishearth
Rollup of 4 pull requests

- Successful merges: #34207, #34268, #34270, #34290
- Failed merges:
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/fs.rs11
-rw-r--r--src/libstd/sys/windows/c.rs1
-rw-r--r--src/libstd/sys/windows/mod.rs1
3 files changed, 12 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");
diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs
index 2acf6485eb3..ce563dc7b16 100644
--- a/src/libstd/sys/windows/c.rs
+++ b/src/libstd/sys/windows/c.rs
@@ -181,6 +181,7 @@ pub const ERROR_ACCESS_DENIED: DWORD = 5;
 pub const ERROR_INVALID_HANDLE: DWORD = 6;
 pub const ERROR_NO_MORE_FILES: DWORD = 18;
 pub const ERROR_HANDLE_EOF: DWORD = 38;
+pub const ERROR_FILE_EXISTS: DWORD = 80;
 pub const ERROR_BROKEN_PIPE: DWORD = 109;
 pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120;
 pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122;
diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs
index 384940e4dc4..6dd4f4c3e75 100644
--- a/src/libstd/sys/windows/mod.rs
+++ b/src/libstd/sys/windows/mod.rs
@@ -68,6 +68,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
     match errno as c::DWORD {
         c::ERROR_ACCESS_DENIED => return ErrorKind::PermissionDenied,
         c::ERROR_ALREADY_EXISTS => return ErrorKind::AlreadyExists,
+        c::ERROR_FILE_EXISTS => return ErrorKind::AlreadyExists,
         c::ERROR_BROKEN_PIPE => return ErrorKind::BrokenPipe,
         c::ERROR_FILE_NOT_FOUND => return ErrorKind::NotFound,
         c::ERROR_PATH_NOT_FOUND => return ErrorKind::NotFound,