-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exclude unreadable directories from File_tree.t
Signed-off-by: Rudi Grinberg <[email protected]>
- Loading branch information
Showing
1 changed file
with
24 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ module Dir = struct | |
type t = | ||
{ path : Path.t | ||
; ignored : bool | ||
; contents : (contents, string) Result.t Lazy.t | ||
; contents : contents Lazy.t | ||
; project : Dune_project.t | ||
} | ||
|
||
|
@@ -109,20 +109,9 @@ module Dir = struct | |
let path t = t.path | ||
let ignored t = t.ignored | ||
|
||
let files t = | ||
match contents t with | ||
| Ok t -> t.files | ||
| Error _ -> String.Set.empty | ||
|
||
let sub_dirs t = | ||
match contents t with | ||
| Ok t -> t.sub_dirs | ||
| Error _ -> String.Map.empty | ||
|
||
let dune_file t = | ||
match contents t with | ||
| Ok t -> t.dune_file | ||
| Error _ -> None | ||
let files t = (contents t).files | ||
let sub_dirs t = (contents t).sub_dirs | ||
let dune_file t = (contents t).dune_file | ||
|
||
let project t = t.project | ||
|
||
|
@@ -159,11 +148,7 @@ module Dir = struct | |
Record | ||
[ "path", Path.to_dyn path | ||
; "ignored", Bool ignored | ||
; "contents", | ||
Result.to_dyn | ||
dyn_of_contents | ||
(fun e -> String e) | ||
contents | ||
; "contents", dyn_of_contents contents | ||
] | ||
|
||
let to_sexp t = Dyn.to_sexp (to_dyn t) | ||
|
@@ -227,24 +212,17 @@ let readdir path = | |
|
||
let load ?(warn_when_seeing_jbuild_file=true) path = | ||
let open Result.O in | ||
let rec walk path ~dirs_visited ~project:parent_project ~data_only = | ||
let dir_listing = lazy (readdir path) in | ||
let rec walk path ~dirs_visited ~project:parent_project ~data_only : (_, _) Result.t = | ||
let+ { dirs; files } = readdir path in | ||
let project = | ||
if data_only then | ||
Lazy.force parent_project | ||
else | ||
let dir_listing = Lazy.force dir_listing in | ||
match dir_listing with | ||
| Error _ -> Lazy.force parent_project | ||
| Ok dir_listing -> | ||
let files = dir_listing.files in | ||
match Dune_project.load ~dir:path ~files with | ||
| Some p -> p | ||
| None -> Lazy.force parent_project | ||
match Dune_project.load ~dir:path ~files with | ||
| Some p -> p | ||
| None -> Lazy.force parent_project | ||
in | ||
let contents = lazy ( | ||
let+ dir_listing = Lazy.force dir_listing in | ||
let files = dir_listing.files in | ||
let dune_file, sub_dirs = | ||
if data_only then | ||
(None, Sub_dirs.default) | ||
|
@@ -285,9 +263,9 @@ let load ?(warn_when_seeing_jbuild_file=true) path = | |
in | ||
let sub_dirs = | ||
Sub_dirs.eval sub_dirs | ||
~dirs:(List.map ~f:(fun (a, _, _) -> a) dir_listing.dirs) in | ||
~dirs:(List.map ~f:(fun (a, _, _) -> a) dirs) in | ||
let sub_dirs = | ||
dir_listing.dirs | ||
dirs | ||
|> List.fold_left ~init:String.Map.empty ~f:(fun acc (fn, path, file) -> | ||
let status = | ||
if Bootstrap.data_only_path path then | ||
|
@@ -311,17 +289,26 @@ let load ?(warn_when_seeing_jbuild_file=true) path = | |
(Path.to_string_maybe_quoted first_path) | ||
(Path.to_string_maybe_quoted path) | ||
in | ||
walk path ~dirs_visited ~project:(lazy project) ~data_only | ||
|> String.Map.add acc fn) | ||
match | ||
walk path ~dirs_visited ~project:(lazy project) ~data_only | ||
with | ||
| Ok dir -> String.Map.add acc fn dir | ||
| Error _ -> acc) | ||
in | ||
{ Dir. files; sub_dirs; dune_file }) | ||
in | ||
Dir.create ~path ~contents ~ignored:data_only ~project | ||
in | ||
walk path | ||
match | ||
walk path | ||
~dirs_visited:(File.Map.singleton (File.of_path path) path) | ||
~data_only:false | ||
~project:Dune_project.anonymous | ||
with | ||
| Ok dir -> dir | ||
| Error m -> | ||
die "Unable to load source %[email protected]:%s@." | ||
(Path.to_string_maybe_quoted path) m | ||
|
||
let fold = Dir.fold | ||
|
||
|