Skip to content

Commit

Permalink
handle concurrent directory deletions, fixes #2203
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed Nov 18, 2018
1 parent ef694b9 commit 5ddbf76
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/app/Fake.IO.FileSystem/Globbing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ type private SearchOption =
| FilePattern of string

let private checkSubDirs absolute (dir : string) root =
if dir.Contains "*" then Directory.EnumerateDirectories(root, dir, SearchOption.TopDirectoryOnly) |> Seq.toList
if dir.Contains "*" then
try Directory.EnumerateDirectories(root, dir, SearchOption.TopDirectoryOnly) |> Seq.toList
with :? System.IO.DirectoryNotFoundException -> List.empty
else
let path = Path.Combine(root, dir)

Expand All @@ -40,10 +42,16 @@ let rec private buildPaths acc (input : SearchOption list) =
let subDirs = List.collect (checkSubDirs true name) acc
buildPaths subDirs t
| Recursive :: [] ->
let dirs = Seq.collect (fun dir -> Directory.EnumerateFileSystemEntries(dir, "*", SearchOption.AllDirectories)) acc
let dirs =
Seq.collect (fun dir ->
try Directory.EnumerateFileSystemEntries(dir, "*", SearchOption.AllDirectories)
with :? System.IO.DirectoryNotFoundException -> Seq.empty) acc
buildPaths (acc @ Seq.toList dirs) []
| Recursive :: t ->
let dirs = Seq.collect (fun dir -> Directory.EnumerateDirectories(dir, "*", SearchOption.AllDirectories)) acc
let dirs =
Seq.collect (fun dir ->
try Directory.EnumerateDirectories(dir, "*", SearchOption.AllDirectories)
with :? System.IO.DirectoryNotFoundException -> Seq.empty) acc
buildPaths (acc @ Seq.toList dirs) t
| FilePattern pattern :: _ ->
acc |> List.collect (fun dir ->
Expand All @@ -52,7 +60,8 @@ let rec private buildPaths acc (input : SearchOption list) =
try
Directory.EnumerateFiles (dir, pattern) |> Seq.toList
with
| :? System.IO.PathTooLongException -> [])
| :? System.IO.DirectoryNotFoundException
| :? System.IO.PathTooLongException -> [])

let private driveRegex = Regex(@"^[A-Za-z]:$", RegexOptions.Compiled)

Expand Down

0 comments on commit 5ddbf76

Please sign in to comment.