File tree 2 files changed +12
-2
lines changed
2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -1239,8 +1239,10 @@ pub fn unlink(p: &Path) -> io::Result<()> {
1239
1239
let mut opts = OpenOptions :: new ( ) ;
1240
1240
opts. access_mode ( c:: DELETE ) ;
1241
1241
opts. custom_flags ( c:: FILE_FLAG_OPEN_REPARSE_POINT ) ;
1242
- if File :: open_native ( & p_u16s, & opts) . map ( |f| f. posix_delete ( ) ) . is_ok ( ) {
1243
- return Ok ( ( ) ) ;
1242
+ if let Ok ( f) = File :: open_native ( & p_u16s, & opts) {
1243
+ if f. posix_delete ( ) . is_ok ( ) {
1244
+ return Ok ( ( ) ) ;
1245
+ }
1244
1246
}
1245
1247
}
1246
1248
// return the original error if any of the above fails.
Original file line number Diff line number Diff line change
1
+ #![ cfg( windows) ]
2
+
3
+ /// Attempting to delete a running binary should return an error on Windows.
4
+ #[ test]
5
+ fn win_delete_self ( ) {
6
+ let path = std:: env:: current_exe ( ) . unwrap ( ) ;
7
+ assert ! ( std:: fs:: remove_file( path) . is_err( ) ) ;
8
+ }
You can’t perform that action at this time.
0 commit comments