File tree 3 files changed +12
-1
lines changed
3 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -512,7 +512,7 @@ impl OpenOptions {
512
512
/// No file is allowed to exist at the target location, also no (dangling)
513
513
/// symlink.
514
514
///
515
- /// This option is useful because it as atomic. Otherwise between checking
515
+ /// This option is useful because it is atomic. Otherwise between checking
516
516
/// whether a file exists and creating a new one, the file may have been
517
517
/// created by another process (a TOCTOU race condition / attack).
518
518
///
@@ -1770,6 +1770,15 @@ mod tests {
1770
1770
check ! ( fs:: remove_dir( dir) ) ;
1771
1771
}
1772
1772
1773
+ #[ test]
1774
+ fn file_create_new_already_exists_error ( ) {
1775
+ let tmpdir = tmpdir ( ) ;
1776
+ let file = & tmpdir. join ( "file_create_new_error_exists" ) ;
1777
+ check ! ( fs:: File :: create( file) ) ;
1778
+ let e = fs:: OpenOptions :: new ( ) . write ( true ) . create_new ( true ) . open ( file) . unwrap_err ( ) ;
1779
+ assert_eq ! ( e. kind( ) , ErrorKind :: AlreadyExists ) ;
1780
+ }
1781
+
1773
1782
#[ test]
1774
1783
fn mkdir_path_already_exists_error ( ) {
1775
1784
let tmpdir = tmpdir ( ) ;
Original file line number Diff line number Diff line change @@ -181,6 +181,7 @@ pub const ERROR_ACCESS_DENIED: DWORD = 5;
181
181
pub const ERROR_INVALID_HANDLE : DWORD = 6 ;
182
182
pub const ERROR_NO_MORE_FILES : DWORD = 18 ;
183
183
pub const ERROR_HANDLE_EOF : DWORD = 38 ;
184
+ pub const ERROR_FILE_EXISTS : DWORD = 80 ;
184
185
pub const ERROR_BROKEN_PIPE : DWORD = 109 ;
185
186
pub const ERROR_CALL_NOT_IMPLEMENTED : DWORD = 120 ;
186
187
pub const ERROR_INSUFFICIENT_BUFFER : DWORD = 122 ;
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
68
68
match errno as c:: DWORD {
69
69
c:: ERROR_ACCESS_DENIED => return ErrorKind :: PermissionDenied ,
70
70
c:: ERROR_ALREADY_EXISTS => return ErrorKind :: AlreadyExists ,
71
+ c:: ERROR_FILE_EXISTS => return ErrorKind :: AlreadyExists ,
71
72
c:: ERROR_BROKEN_PIPE => return ErrorKind :: BrokenPipe ,
72
73
c:: ERROR_FILE_NOT_FOUND => return ErrorKind :: NotFound ,
73
74
c:: ERROR_PATH_NOT_FOUND => return ErrorKind :: NotFound ,
You can’t perform that action at this time.
0 commit comments