Skip to content

Commit ba87a35

Browse files
authored
Merge pull request #8338 from brettfo/safe-delete
safely delete test files and directories
2 parents 5e89847 + a0cf13d commit ba87a35

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

vsintegration/tests/UnitTests/ProjectOptionsBuilder.fs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ open System.IO
55
open System.Xml.Linq
66
open FSharp.Compiler.SourceCodeServices
77

8+
module FileSystemHelpers =
9+
let safeDeleteFile (path: string) =
10+
try
11+
File.Delete(path)
12+
with
13+
| _ -> ()
14+
15+
let safeDeleteDirectory (path: string) =
16+
try
17+
Directory.Delete(path)
18+
with
19+
| _ -> ()
20+
821
type FSharpProject =
922
{
1023
Directory: string
@@ -29,9 +42,10 @@ type FSharpProject =
2942
member this.Dispose() =
3043
// delete each source file
3144
this.Files
32-
|> List.iter (fun (path, _contents) -> File.Delete(path))
45+
|> List.map fst
46+
|> List.iter FileSystemHelpers.safeDeleteFile
3347
// delete the directory
34-
Directory.Delete(this.Directory)
48+
FileSystemHelpers.safeDeleteDirectory (this.Directory)
3549
// project file doesn't really exist, nothing to delete
3650
()
3751

0 commit comments

Comments
 (0)