Skip to content

Commit b8143cb

Browse files
committed
Small readability refactor
1 parent d2aa6e4 commit b8143cb

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

analysis/src/Files.ml

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ let relpath base path =
3838
loop (split Filename.dir_sep base) (split Filename.dir_sep path)
3939
in
4040
String.concat Filename.dir_sep
41-
( ( match base = [] with
42-
| true -> ["."]
43-
| false -> List.map (fun _ -> "..") base )
44-
@ path )
41+
((match base = [] with
42+
| true -> ["."]
43+
| false -> List.map (fun _ -> "..") base)
44+
@ path)
4545
|> removeExtraDots
4646

4747
let maybeStat path =
@@ -57,40 +57,36 @@ let readFile ~filename =
5757
let content = really_input_string chan (in_channel_length chan) in
5858
close_in_noerr chan;
5959
Some content
60-
with
61-
| _ -> None
60+
with _ -> None
6261

6362
let exists path = match maybeStat path with None -> false | Some _ -> true
6463

6564
let ifExists path = match exists path with true -> Some path | false -> None
6665

6766
let readDirectory dir =
68-
let maybeGet handle =
69-
try Some (Unix.readdir handle) with End_of_file -> None
70-
in
71-
let rec loop handle =
72-
match maybeGet handle with
73-
| None ->
74-
Unix.closedir handle;
75-
[]
76-
| Some name
77-
when name = Filename.current_dir_name || name = Filename.parent_dir_name
78-
->
79-
loop handle
80-
| Some name -> name :: loop handle
81-
in
8267
match Unix.opendir dir with
8368
| exception Unix.Unix_error (Unix.ENOENT, "opendir", _dir) -> []
84-
| handle -> loop handle
69+
| handle ->
70+
let rec loop handle =
71+
try
72+
let name = Unix.readdir handle in
73+
if name = Filename.current_dir_name || name = Filename.parent_dir_name
74+
then loop handle
75+
else name :: loop handle
76+
with End_of_file ->
77+
Unix.closedir handle;
78+
[]
79+
in
80+
loop handle
8581

8682
let rec collectDirs path =
8783
match maybeStat path with
8884
| None -> []
8985
| Some {Unix.st_kind = Unix.S_DIR} ->
9086
path
91-
:: ( readDirectory path
87+
:: (readDirectory path
9288
|> List.map (fun name -> collectDirs (Filename.concat path name))
93-
|> List.concat )
89+
|> List.concat)
9490
| _ -> []
9591

9692
let rec collect ?(checkDir = fun _ -> true) path test =
@@ -100,10 +96,10 @@ let rec collect ?(checkDir = fun _ -> true) path test =
10096
if checkDir path then
10197
readDirectory path
10298
|> List.map (fun name ->
103-
collect ~checkDir (Filename.concat path name) test)
99+
collect ~checkDir (Filename.concat path name) test)
104100
|> List.concat
105101
else []
106-
| _ -> ( match test path with true -> [path] | false -> [] )
102+
| _ -> ( match test path with true -> [path] | false -> [])
107103
108104
let fileConcat a b =
109105
if

0 commit comments

Comments
 (0)