File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 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<()> {
12391239 let mut opts = OpenOptions :: new ( ) ;
12401240 opts. access_mode ( c:: DELETE ) ;
12411241 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+ }
12441246 }
12451247 }
12461248 // 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