From 15b08d2fdf47e05c8084ec55f39f41b2561377cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Mon, 20 Apr 2020 14:38:10 +0200 Subject: [PATCH] Use Filename.quote_command (#9476) --- ocamltest/filecompare.ml | 13 ++++++------- ocamltest/main.ml | 5 ++++- ocamltest/ocamltest_stdlib.ml | 3 +-- tools/objinfo.ml | 8 ++++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ocamltest/filecompare.ml b/ocamltest/filecompare.ml index d2e8c310c..2e87d0ce0 100644 --- a/ocamltest/filecompare.ml +++ b/ocamltest/filecompare.ml @@ -166,13 +166,12 @@ let check_file ?(tool = default_comparison_tool) files = let diff files = let temporary_file = Filename.temp_file "ocamltest" "diff" in - let diff_commandline = String.concat " " - [ - "diff -u"; - files.reference_filename; - files.output_filename; - "> " ^ temporary_file - ] in + let diff_commandline = + Filename.quote_command "diff" ~stdout:temporary_file + [ "-u"; + files.reference_filename; + files.output_filename ] + in let result = if (Sys.command diff_commandline) = 2 then Stdlib.Error "diff" else Ok (Sys.string_of_file temporary_file) diff --git a/ocamltest/main.ml b/ocamltest/main.ml index b2859b15a..9d9529652 100644 --- a/ocamltest/main.ml +++ b/ocamltest/main.ml @@ -155,7 +155,10 @@ let test_file test_filename = let test_build_directory_prefix = get_test_build_directory_prefix test_directory in let clean_test_build_directory () = - ignore (Sys.command ("rm -rf " ^ test_build_directory_prefix)) in + ignore + (Sys.command + (Filename.quote_command "rm" ["-rf"; test_build_directory_prefix])) + in clean_test_build_directory (); Sys.make_directory test_build_directory_prefix; let summary = Sys.with_chdir test_build_directory_prefix diff --git a/ocamltest/ocamltest_stdlib.ml b/ocamltest/ocamltest_stdlib.ml index 2d667299f..3b5501013 100644 --- a/ocamltest/ocamltest_stdlib.ml +++ b/ocamltest/ocamltest_stdlib.ml @@ -102,8 +102,7 @@ module Sys = struct let mkdir dir = if not (Sys.file_exists dir) then - let quoted_dir = "\"" ^ dir ^ "\"" in - run_system_command ("mkdir " ^ quoted_dir) + run_system_command (Filename.quote_command "mkdir" [dir]) let rec make_directory dir = if Sys.file_exists dir then () diff --git a/tools/objinfo.ml b/tools/objinfo.ml index 42d4c6e0a..d2a01995c 100644 --- a/tools/objinfo.ml +++ b/tools/objinfo.ml @@ -250,10 +250,10 @@ let find_dyn_offset filename = Fun.protect ~finally:(fun () -> remove_file tempfile) (fun () -> - let rc = Sys.command (sprintf "%s %s > %s" - (Filename.quote helper) - (Filename.quote filename) - tempfile) in + let rc = + Sys.command + (Filename.quote_command helper ~stdout:tempfile [filename]) + in if rc <> 0 then failwith "cannot read"; let tc = Scanf.Scanning.from_file tempfile in Fun.protect