This repository was archived by the owner on Dec 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +17
-10
lines changed
Expand file tree Collapse file tree 1 file changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -688,20 +688,27 @@ public void Delete(DeleteMode deleteMode = DeleteMode.Normal)
688688 if ( IsRoot )
689689 throw new NotSupportedException ( "Delete is not supported on a root level directory because it would be dangerous:" + ToString ( ) ) ;
690690
691- if ( FileExists ( ) )
692- FileSystem . FileDelete ( ToString ( ) ) ;
693- else if ( DirectoryExists ( ) )
694- try
691+ var isFile = FileExists ( ) ;
692+ var isDir = DirectoryExists ( ) ;
693+ if ( ! isFile && ! isDir )
694+ throw new InvalidOperationException ( "Trying to delete a path that does not exist: " + ToString ( ) ) ;
695+
696+ try
697+ {
698+ if ( isFile )
695699 {
696- FileSystem . DirectoryDelete ( ToString ( ) , true ) ;
700+ FileSystem . FileDelete ( ToString ( ) ) ;
697701 }
698- catch ( IOException )
702+ else
699703 {
700- if ( deleteMode == DeleteMode . Normal )
701- throw ;
704+ FileSystem . DirectoryDelete ( ToString ( ) , true ) ;
702705 }
703- else
704- throw new InvalidOperationException ( "Trying to delete a path that does not exist: " + ToString ( ) ) ;
706+ }
707+ catch ( IOException )
708+ {
709+ if ( deleteMode == DeleteMode . Normal )
710+ throw ;
711+ }
705712 }
706713
707714 public void DeleteIfExists ( DeleteMode deleteMode = DeleteMode . Normal )
You can’t perform that action at this time.
0 commit comments