Skip to content
Browse files

Improve OCaml script to check md5 checksums (eg. don't call md5/md5su…

…m anymore)
  • Loading branch information...
1 parent 09aa904 commit d651ce411a2dbfadebbed695016110f77c6d6c79 @samoht committed Mar 27, 2013
Showing with 7 additions and 34 deletions.
  1. +6 −33 shell/md5check.ml
  2. +1 −1 src_ext/Makefile
View
39 shell/md5check.ml
@@ -1,39 +1,12 @@
-#load "unix.cma"
-
-let command, file, md5 =
- if Array.length Sys.argv <> 4 then (
- Printf.eprintf "usage: ocaml %s <md5-command> <file> <md5>\n" Sys.argv.(0);
+let file, md5 =
+ if Array.length Sys.argv <> 3 then (
+ Printf.eprintf "usage: ocaml %s <file> <md5>\n" Sys.argv.(0);
exit 1
) else
- Sys.argv.(1), Sys.argv.(2), Sys.argv.(3)
-
-let input_line fmt =
- Printf.kprintf (fun cmd ->
- try
- let ic = Unix.open_process_in cmd in
- let r = input_line ic in
- match Unix.close_process_in ic with
- | Unix.WEXITED 0 -> r
- | _ -> failwith "cmd_input_line"
- with
- | End_of_file
- | Unix.Unix_error _ -> failwith "cmd_input_line"
- ) fmt
+ Sys.argv.(1), Sys.argv.(2)
let md5_of_file =
- match command with
- | "md5" -> input_line "md5 -q %s" file
- | "md5sum" ->
- let line = input_line "md5sum %s" file in
- begin try
- let i = String.index line ' ' in
- String.sub line 0 i
- with _ ->
- ""
- end
- | x ->
- Printf.eprintf "%S is not a valid md5 command name." x;
- exit 2
+ Digest.to_hex (Digest.file file)
let () =
if md5 <> md5_of_file then (
@@ -42,6 +15,6 @@ let () =
\ expected: %s\n\
\ actual: %s\n"
file md5 md5_of_file;
- Unix.unlink file
+ Sys.remove file
) else
Printf.printf "%s has the expected MD5.\n" file
View
2 src_ext/Makefile
@@ -19,7 +19,7 @@ RE = ocaml-re-1.2.0
REMD5 = 5cbfc137683ef2b0e91f931577f2e673
# Portable md5check
-MD5CHECK = ocaml ../shell/md5check.ml $(MD5SUM)
+MD5CHECK = ocaml ../shell/md5check.ml
all: clone depends.ocp

0 comments on commit d651ce4

Please sign in to comment.
Something went wrong with that request. Please try again.