Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 371ed87

Browse files
committed
Swallow IO exceptions
If `DeleteHelper.DeleteGitRepository()` encounteres a `FileNotFoundException` or `DirectoryNotFoundException`, there's no reason for it to blow up.
1 parent 8b0a1da commit 371ed87

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/GitTools.Core/GitTools.Core.Shared/IO/Helpers/DeleteHelper.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@ public static void DeleteGitRepository(string directory)
1111
return;
1212
}
1313

14-
foreach (var fileName in Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories))
14+
try
15+
{
16+
foreach (var fileName in Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories))
17+
{
18+
var fileInfo = new FileInfo(fileName)
19+
{
20+
IsReadOnly = false
21+
};
22+
23+
try
24+
{
25+
fileInfo.Delete();
26+
}
27+
catch (FileNotFoundException)
28+
{
29+
}
30+
}
31+
32+
Directory.Delete(directory, true);
33+
}
34+
catch (DirectoryNotFoundException)
1535
{
16-
var fileInfo = new FileInfo(fileName)
17-
{
18-
IsReadOnly = false
19-
};
20-
21-
fileInfo.Delete();
2236
}
23-
24-
Directory.Delete(directory, true);
2537
}
2638
}
2739
}

0 commit comments

Comments
 (0)