Skip to content

Commit

Permalink
Exclude unreadable directories from File_tree.t
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Apr 9, 2019
1 parent c458c7b commit a2b62d4
Showing 1 changed file with 24 additions and 37 deletions.
61 changes: 24 additions & 37 deletions src/file_tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit a2b62d4

Please sign in to comment.