Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 4cc3169

Browse files
committed
Obey the DeleteMode flag when deleting files too
1 parent 0aa40cb commit 4cc3169

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/GitHub.Api/IO/NiceIO.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)