Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify buildPaths function #2162

Merged
merged 1 commit into from
Oct 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 19 additions & 32 deletions src/app/Fake.IO.FileSystem/Globbing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down