Skip to content
This repository has been archived by the owner on May 13, 2019. It is now read-only.

Commit

Permalink
Used ocurl instead of calling curl executable.
Browse files Browse the repository at this point in the history
  • Loading branch information
sagotch committed Apr 28, 2014
1 parent 7a3e53d commit 800391b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ makorel: makorel.native
mv $< $@

makorel.native:
ocamlbuild -use-ocamlfind -package str,unix $@
ocamlbuild -use-ocamlfind -package str,unix,curl $@

clean:
ocamlbuild -clean
20 changes: 14 additions & 6 deletions makorel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ open Str
open Sys
open Unix

open Curl
open Urlex
open Unixx

Expand Down Expand Up @@ -86,12 +87,19 @@ let _ =
(k, replace v prev_ver new_ver)

| "checksum" ->
let curl_cmd = "curl -Lsf " ^ new_url in
let curl_out = open_process_in curl_cmd in
let checksum = Digest.channel curl_out (-1) |> Digest.to_hex in
if Unix.close_process_in curl_out <> Unix.WEXITED 0
then failwith curl_cmd
else (k, checksum)
(* may need to handle any curl failure? *)
let buf = Buffer.create 256 in
let h = new Curl.handle in
h#set_post false;
h#set_url new_url;
h#set_followlocation true;
h#set_writefunction (fun s -> Buffer.add_string buf s;
String.length s);
h#perform;
h#cleanup;
(k, Buffer.contents buf
|> Digest.string
|> Digest.to_hex)

| "mirrors" -> (k, v) (* TODO: something interesting *)

Expand Down

0 comments on commit 800391b

Please sign in to comment.