diff options
Diffstat (limited to 'src/libstd/fs.rs')
| -rw-r--r-- | src/libstd/fs.rs | 11 |
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"); |
