From 8ef38d425ecfce63ced49aeec8e45c85f07cc44b Mon Sep 17 00:00:00 2001 From: Gustavo Leon <1261319+gusty@users.noreply.github.com> Date: Wed, 17 Oct 2018 12:25:34 +0100 Subject: [PATCH] Simplify buildPaths function --- src/app/Fake.IO.FileSystem/Globbing.fs | 51 ++++++++++---------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/src/app/Fake.IO.FileSystem/Globbing.fs b/src/app/Fake.IO.FileSystem/Globbing.fs index 59769c8514d..fb99b7873dc 100644 --- a/src/app/Fake.IO.FileSystem/Globbing.fs +++ b/src/app/Fake.IO.FileSystem/Globbing.fs @@ -30,42 +30,29 @@ let private checkSubDirs absolute (dir : string) root = if di.Exists then [ di.FullName ] else [] -let rec private buildPaths acc (input : SearchOption list) = +let rec private buildPaths acc (input : SearchOption list) = match input with | [] -> acc - | Directory(name) :: t -> - let subDirs = - acc - |> List.map (checkSubDirs false name) - |> List.concat + | Directory name :: t -> + let subDirs = List.collect (checkSubDirs false name) acc buildPaths subDirs t - | Drive(name) :: t -> - let subDirs = - acc - |> List.map (checkSubDirs true name) - |> List.concat + | Drive name :: t -> + let subDirs = List.collect (checkSubDirs true name) acc buildPaths subDirs t - | Recursive :: [] -> - let dirs = - Seq.collect (fun dir -> Directory.EnumerateFileSystemEntries(dir, "*", SearchOption.AllDirectories)) acc - |> Seq.toList - buildPaths (acc @ dirs) [] - | Recursive :: t -> - let dirs = - Seq.collect (fun dir -> Directory.EnumerateDirectories(dir, "*", SearchOption.AllDirectories)) acc - |> Seq.toList - buildPaths (acc @ dirs) t - | FilePattern(pattern) :: t -> - Seq.collect (fun dir -> - if Directory.Exists(Path.Combine(dir, pattern)) - then seq { yield Path.Combine(dir, pattern) } - else - try - Directory.EnumerateFiles(dir, pattern) - with - | :? System.IO.PathTooLongException as ex -> - Array.toSeq [| |] - ) acc |> Seq.toList + | Recursive :: [] -> + let dirs = Seq.collect (fun dir -> Directory.EnumerateFileSystemEntries(dir, "*", SearchOption.AllDirectories)) acc + buildPaths (acc @ Seq.toList dirs) [] + | Recursive :: t -> + let dirs = Seq.collect (fun dir -> Directory.EnumerateDirectories(dir, "*", SearchOption.AllDirectories)) acc + buildPaths (acc @ Seq.toList dirs) t + | FilePattern pattern :: _ -> + acc |> List.collect (fun dir -> + if Directory.Exists (Path.Combine (dir, pattern)) then [Path.Combine (dir, pattern)] + else + try + Directory.EnumerateFiles (dir, pattern) |> Seq.toList + with + | :? System.IO.PathTooLongException -> []) let private driveRegex = Regex(@"^[A-Za-z]:$", RegexOptions.Compiled)