11open Core
22open Camlzip
3- open Polymorphic_compare
3+ open Poly
44open Comby_kernel
55
6- let debug = Sys. getenv " DEBUG_COMBY" |> Option. is_some
6+ let debug = Stdlib.Sys. getenv_opt " DEBUG_COMBY" |> Option. is_some
7+
8+ let ls_dir path = Stdlib.Sys. readdir path |> Array. to_list
9+
10+ let is_directory path =
11+ try Stdlib.Sys. is_directory path with
12+ | Sys_error _ -> false
13+
14+ let is_file path = Stdlib.Sys. file_exists path && not (is_directory path)
715
816(* skip or continue directory descent *)
917type 'a next =
@@ -12,18 +20,18 @@ type 'a next =
1220
1321let fold_directory ?(sorted = false ) root ~init ~f =
1422 let rec aux acc absolute_path depth =
15- if Sys. is_file absolute_path = `Yes then (
23+ if is_file absolute_path then (
1624 match f acc ~depth ~absolute_path ~is_file: true with
1725 | Continue acc | Skip acc -> acc)
18- else if Sys. is_directory absolute_path = `Yes then (
26+ else if is_directory absolute_path then (
1927 match f acc ~depth ~absolute_path ~is_file: false with
2028 | Skip acc -> acc
2129 | Continue acc ->
2230 let dir_contents =
2331 if Option. is_some (Sys. getenv " COMBY_TEST" ) || sorted then
24- Sys. ls_dir absolute_path |> List. sort ~compare: String. compare |> List. rev
32+ ls_dir absolute_path |> List. sort ~compare: String. compare |> List. rev
2533 else
26- Sys. ls_dir absolute_path
34+ ls_dir absolute_path
2735 in
2836 List. fold dir_contents ~init: acc ~f: (fun acc subdir ->
2937 aux acc (Filename. concat absolute_path subdir) (depth + 1 )))
@@ -44,7 +52,7 @@ let parse_source_directories
4452 let exact_file_paths, file_patterns =
4553 List. partition_map file_filters ~f: (fun path ->
4654 let is_exact path =
47- (String. contains path '/' && Sys. is_file path = `Yes ) || Sys. is_file (" ." ^/ path) = `Yes
55+ (String. contains path '/' && is_file path) || is_file (" ." ^/ path)
4856 (* See if it matches something in the current directory *)
4957 in
5058 if is_exact path then Either. First path else Either. Second path)
@@ -161,8 +169,8 @@ let parse_templates ?metasyntax ?(warn_for_missing_file_in_dir = false) paths =
161169 let f acc ~depth :_ ~absolute_path ~is_file =
162170 let is_leaf_directory absolute_path =
163171 (not is_file)
164- && Sys. ls_dir absolute_path
165- |> List. for_all ~f: (fun path -> Sys. is_directory (absolute_path ^/ path) = `No )
172+ && ls_dir absolute_path
173+ |> List. for_all ~f: (fun path -> not ( is_directory (absolute_path ^/ path)) )
166174 in
167175 if is_leaf_directory absolute_path then (
168176 match parse_directory absolute_path with
@@ -172,7 +180,7 @@ let parse_templates ?metasyntax ?(warn_for_missing_file_in_dir = false) paths =
172180 Continue acc
173181 in
174182 List. concat_map paths ~f: (fun path ->
175- if Sys. is_directory path = `Yes then
183+ if is_directory path then
176184 fold_directory path ~sorted: true ~init: [] ~f
177185 else
178186 parse_toml ?metasyntax path)
@@ -223,7 +231,6 @@ type user_input_options =
223231
224232type compute_mode =
225233 [ `Sequential
226- | `Hack_parallel of int
227234 | `Parany of int
228235 ]
229236
@@ -411,11 +418,11 @@ let parse_metasyntax metasyntax_path =
411418 match metasyntax_path with
412419 | None -> Matchers.Metasyntax. default_metasyntax
413420 | Some metasyntax_path ->
414- (match Sys. file_exists metasyntax_path with
415- | `No | `Unknown ->
421+ (match Stdlib. Sys. file_exists metasyntax_path with
422+ | false ->
416423 Format. eprintf " Could not open file: %s@." metasyntax_path;
417424 exit 1
418- | `Yes ->
425+ | true ->
419426 Yojson.Safe. from_file metasyntax_path
420427 |> Matchers.Metasyntax. of_yojson
421428 |> (function
@@ -462,26 +469,26 @@ let emit_errors { input_options; output_options; _ } =
462469 ; ( Option. is_some input_options.directory_depth
463470 && Option. value_exn input_options.directory_depth < 0
464471 , " -depth must be 0 or greater." )
465- ; ( Sys. is_directory input_options.target_directory = `No
472+ ; ( not ( is_directory input_options.target_directory)
466473 , " Directory specified with -d or -directory is not a directory." )
467474 ; ( output_options.json_only_diff && not output_options.json_lines
468475 , " -json-only-diff can only be supplied with -json-lines." )
469476 ; ( Option. is_some output_options.chunk_matches && Option. is_some input_options.zip_file
470477 , " chunk-matches output format is not supported for zip files." )
471478 ; ( Option. is_some output_options.interactive_review
472- && not (String. equal input_options.target_directory (Sys. getcwd () ))
479+ && not (String. equal input_options.target_directory (Stdlib. Sys. getcwd () ))
473480 , " Please remove the -d option and `cd` to the directory where you want to review from. The \
474481 -review, -editor, or -default-no options should only be run at the root directory of the \
475482 project files to patch." )
476483 ; (let message =
477484 match input_options.templates with
478485 | Some inputs ->
479486 List. find_map inputs ~f: (fun input ->
480- if Sys. is_file input = `Yes then (
487+ if is_file input then (
481488 match Toml.Parser. from_filename input with
482489 | `Error (s , _ ) -> Some s
483490 | _ -> None )
484- else if not (Sys. is_directory input = `Yes ) then
491+ else if not (is_directory input) then
485492 Some
486493 (Format. sprintf " Directory %S specified with -templates is not a directory." input)
487494 else
@@ -598,11 +605,11 @@ let filter_zip_entries file_filters exclude_directory_prefix exclude_file_prefix
598605 && has_acceptable_suffix filename)
599606
600607let syntax custom_matcher_path =
601- match Sys. file_exists custom_matcher_path with
602- | `No | `Unknown ->
608+ match Stdlib. Sys. file_exists custom_matcher_path with
609+ | false ->
603610 Format. eprintf " Could not open file: %s@." custom_matcher_path;
604611 exit 1
605- | `Yes ->
612+ | true ->
606613 Yojson.Safe. from_file custom_matcher_path
607614 |> Matchers.Language.Syntax. of_yojson
608615 |> (function
@@ -783,7 +790,7 @@ let create
783790 | Directory ->
784791 let target_directory =
785792 if target_directory = " ." then
786- Filename . realpath target_directory
793+ Filename_unix . realpath target_directory
787794 else
788795 target_directory
789796 in
0 commit comments