10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-12-22 04:13:31 +01:00

Added md5 update

This commit is contained in:
Anthony Scemama 2016-01-31 00:29:36 +01:00
parent 010c3374a4
commit 9b34e07283
2 changed files with 55 additions and 11 deletions

View File

@ -92,7 +92,7 @@ let hash_file filename =
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ()) ) |> Cryptokit.transform_string (Cryptokit.Hexa.encode ()) )
end end
| _ -> "" | _ -> ""
(** Cache containing the current value of the MD5 hash. *) (** Cache containing the current value of the MD5 hash. *)
let _hash = let _hash =
@ -110,12 +110,17 @@ let hash () =
else else
"" ""
in in
let new_md5 = files_to_track let md5_string =
|> List.map ~f:(fun x -> Printf.sprintf "%s/%s" ezfio_filename x) files_to_track
|> List.map ~f:hash_file |> List.map ~f:(fun x -> Printf.sprintf "%s/%s" ezfio_filename x)
|> String.concat |> List.map ~f:hash_file
|> Cryptokit.hash_string (Cryptokit.Hash.md5 ()) |> String.concat
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ()) in
let new_md5 =
md5_string
|> Cryptokit.hash_string (Cryptokit.Hash.md5 ())
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ())
in in
if (new_md5 <> old_md5) then if (new_md5 <> old_md5) then
begin begin

View File

@ -1,6 +1,6 @@
open Core.Std open Core.Std
let run ?c ?d ~l ezfio_filename = let run ?c ?d ~l ~update ezfio_filename =
Qputils.set_ezfio_filename ezfio_filename; Qputils.set_ezfio_filename ezfio_filename;
@ -25,6 +25,43 @@ let run ?c ?d ~l ezfio_filename =
Sys.file_exists_exn filename Sys.file_exists_exn filename
in in
if (update) then
begin
Printf.printf "Updating\n%!" ;
let update_one old_key =
Qmcchem_edit.run ~c:false ~input:(filename_of_key old_key) ezfio_filename;
Md5.reset_hash ();
let new_key =
Md5.hash ()
in
if (old_key <> new_key) then
begin
let new_name =
String.concat ~sep:"/" [ ezfio_filename; "blocks"; new_key ]
and old_name =
String.concat ~sep:"/" [ ezfio_filename; "blocks"; old_key ]
in
Printf.printf "Renaming %s -> %s\n" old_name new_name;
try Sys.rename old_name new_name with
| Sys_error _ -> ();
let old_name =
String.concat ~sep:"/" [ ezfio_filename; "input"; old_key ]
in
Printf.printf "Removing %s\n%!" old_name;
try Sys.remove old_name with
| Sys_error _ -> ();
end
in
let l =
Sys.ls_dir input_directory
in
List.iter l ~f:(fun x -> update_one x) ;
Printf.printf "Done\n%!" ;
end
;
let () = let () =
match c with match c with
| None -> () | None -> ()
@ -79,8 +116,8 @@ let run ?c ?d ~l ezfio_filename =
in in
match (c,d,l) with match (c,d,l,update) with
| (None,None,false) -> | (None,None,false,false) ->
Printf.printf "Current key :\n%s\n" (Md5.hash ()) Printf.printf "Current key :\n%s\n" (Md5.hash ())
| _ -> handle_options () | _ -> handle_options ()
@ -94,6 +131,8 @@ let spec =
~doc:("<key> Show input differences with <key>") ~doc:("<key> Show input differences with <key>")
+> flag "l" no_arg +> flag "l" no_arg
~doc:(" List all the saved MD5 keys.") ~doc:(" List all the saved MD5 keys.")
+> flag "update" no_arg
~doc:(" Update to the latest MD5 format.")
+> anon ("ezfio_file" %: string) +> anon ("ezfio_file" %: string)
@ -106,7 +145,7 @@ let command =
Manipulate input MD5 keys Manipulate input MD5 keys
") ")
spec spec
(fun c d l ezfio_file () -> run ?c ?d ~l ezfio_file ) (fun c d l update ezfio_file () -> run ?c ?d ~l ~update ezfio_file )