From 8627db86be3a7bbf34793ff2da796588c33e8791 Mon Sep 17 00:00:00 2001 From: Bryan Bennett Date: Sat, 17 Aug 2024 09:36:21 -0400 Subject: [PATCH] Filter missing watches before hashing --- bin/flake_env.re | 8 ++++---- lib/flake_env__util.re | 1 - lib/flake_env__watches.re | 7 +++++++ tests/flake_env_test_util.re | 6 +++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/bin/flake_env.re b/bin/flake_env.re index 1fb7b5a..b24467e 100644 --- a/bin/flake_env.re +++ b/bin/flake_env.re @@ -6,9 +6,9 @@ let main = () => { | Ok((layout_directory, flake_specifier, other_args)) => switch (preflight(layout_directory)) { | Ok () => - switch (Lib.Watches.get()) { + switch (Lib.Watches.get_extant()) { | Ok(watches) => - let paths = Array.map(watch => watch.path, watches); + let paths = List.map(watch => watch.path, watches); let hash = switch (Util.hash_files(paths)) { | Ok(hsh) => hsh @@ -24,8 +24,8 @@ let main = () => { | (true, true) => let profile_rc_mtime = Unix.stat(profile_rc).st_mtime; let all_older = - Array.map(watch => watch.modtime, watches) - |> Array.for_all(watch_mtime => + List.map(watch => watch.modtime, watches) + |> List.for_all(watch_mtime => watch_mtime <= int_of_float(profile_rc_mtime) ); if (all_older) { diff --git a/lib/flake_env__util.re b/lib/flake_env__util.re index fbd899c..32716c2 100644 --- a/lib/flake_env__util.re +++ b/lib/flake_env__util.re @@ -44,7 +44,6 @@ let hash_files = filenames => { let ctx = Sha1.init(); let files_to_hash = filenames - |> Array.to_list |> List.filter(f => Sys.file_exists(f) ? true diff --git a/lib/flake_env__watches.re b/lib/flake_env__watches.re index a707dd8..da68ee8 100644 --- a/lib/flake_env__watches.re +++ b/lib/flake_env__watches.re @@ -28,6 +28,13 @@ let get = () => { }; }; +let get_extant = () => { + get() + |> Result.map(watches => + watches |> Array.to_list |> List.filter(a => a.exists) + ); +}; + let get_path = doc => { let pth = doc |> member("path") |> to_string; String.sub(pth, 11, String.length(pth) - 11); diff --git a/tests/flake_env_test_util.re b/tests/flake_env_test_util.re index 3dc691c..b8c70dd 100644 --- a/tests/flake_env_test_util.re +++ b/tests/flake_env_test_util.re @@ -75,7 +75,7 @@ let test_hash_one = () => { check_result_string( "Hash matches", Ok("6ead949bf4bcae230b9ed9cd11e578e34ce9f9ea"), - hash_files([|"spit_version.sh"|]), + hash_files(["spit_version.sh"]), ); }; @@ -83,7 +83,7 @@ let test_hash_multiple = () => { check_result_string( "Hash matches", Ok("f109b7892a541ed1e3cf39314cd25d21042b984f"), - hash_files([|"spit_version.sh", "spit_version.sh"|]), + hash_files(["spit_version.sh", "spit_version.sh"]), ); }; @@ -91,7 +91,7 @@ let test_hash_filters_nonexistent = () => { check_result_string( "Hash matches", Ok("6ead949bf4bcae230b9ed9cd11e578e34ce9f9ea"), - hash_files([|"spit_version.sh", "FOOBARBAZ"|]), + hash_files(["spit_version.sh", "FOOBARBAZ"]), ); };