From c568b16c38013fa81e405b97989bb855d3139580 Mon Sep 17 00:00:00 2001 From: Julien Sagot Date: Mon, 28 Apr 2014 19:43:18 +0200 Subject: [PATCH] `md5sum | cut` call replaced by module Digest functions. See #2. --- makorel.ml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/makorel.ml b/makorel.ml index abf32ea..6fb75c7 100644 --- a/makorel.ml +++ b/makorel.ml @@ -1,6 +1,8 @@ +open Digest +open Str open Sys open Unix -open Str + open Urlex open Unixx @@ -84,19 +86,17 @@ let _ = (k, replace v prev_ver new_ver) | "checksum" -> - let checksum = Unixx.pipes [[|"curl"; "-Lsf"; new_url|]; - [|"md5sum"|]; - [|"cut"; "-d "; "-f"; "1"|]] - Unix.stdin in - (* assumes that everything goes well *) - let in_channel = Unix.in_channel_of_descr checksum in - let checksum = input_line in_channel in - close_in in_channel; - print_endline (checksum); - (k, checksum) - + let curl_cmd = "curl -Lsf " ^ new_url in + let curl_out = open_process_in curl_cmd in + let checksum = Digest.input curl_out |> Digest.to_hex in + if Unix.close_process_in curl_out <> Unix.WEXITED 0 + then failwith curl_cmd + else (k, checksum) + | "mirrors" -> (k, v) (* TODO: something interesting *) - | _ -> prerr_string ("unknown field " ^ k); exit 1 + + | _ -> failwith ("unknown field " ^ k) + in List.map process_field url_fields in (* write to url file *)