mirror of
https://git.sr.ht/~bryan_bennett/flake_env
synced 2025-12-16 22:51:24 +01:00
Rework hash_files to return (str, str) result
This commit is contained in:
parent
98c3131f7f
commit
6b313a6ff6
3 changed files with 60 additions and 22 deletions
|
|
@ -17,23 +17,39 @@ let nix = args =>
|
|||
);
|
||||
|
||||
let hash_files = filenames => {
|
||||
/*** Hash all entries in [filenames], returning a hex-encoded string of the hash of their contents */
|
||||
/*** Hash all entries in [filenames]
|
||||
Returns Some(hex-string) or None if no filenames are found.
|
||||
*/
|
||||
let ctx = Sha1.init();
|
||||
let () =
|
||||
let files_to_hash =
|
||||
filenames
|
||||
|> Array.filter(~f=f =>
|
||||
switch (Sys_unix.file_exists(f)) {
|
||||
| `Yes => true
|
||||
| _ => false
|
||||
| _ =>
|
||||
// let fullpth = Filename_unix.realpath(f);
|
||||
Printf.eprintf(
|
||||
"Cannot find file %s (cwd: %s)\n",
|
||||
f,
|
||||
Core_unix.getcwd(),
|
||||
);
|
||||
false;
|
||||
}
|
||||
)
|
||||
|> Array.iter(~f=f => {
|
||||
f
|
||||
|> In_channel.create
|
||||
|> In_channel.input_all
|
||||
|> Sha1.update_string(ctx)
|
||||
});
|
||||
Sha1.finalize(ctx) |> Sha1.to_hex;
|
||||
);
|
||||
|
||||
switch (files_to_hash |> Array.length) {
|
||||
| 0 => Error("No files found to hash")
|
||||
| _ =>
|
||||
let () =
|
||||
files_to_hash
|
||||
|> Array.iter(~f=f => {
|
||||
f
|
||||
|> In_channel.create
|
||||
|> In_channel.input_all
|
||||
|> Sha1.update_string(ctx)
|
||||
});
|
||||
Ok(Sha1.finalize(ctx) |> Sha1.to_hex);
|
||||
};
|
||||
};
|
||||
|
||||
let rec rmrf = path => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue