@@ -22,34 +22,27 @@ let trim_broken_metadata_entries ~trimmed_so_far =
2222 Layout.Versioned. file_path (Version.Metadata. file_version version)
2323 in
2424 List. fold_left metadata_entries ~init: trimmed_so_far
25- ~f: (fun trimmed_so_far path ->
25+ ~f: (fun trimmed_so_far ( path , rule_or_action_digest ) ->
2626 let should_be_removed =
27- match Digest. from_hex (Path. basename path) with
28- | None ->
29- (* Keep unrecognized entries in the cache. *)
27+ match Metadata.Versioned. restore version ~rule_or_action_digest with
28+ | Not_found_in_cache ->
29+ (* A concurrent process must have removed this metadata file. No
30+ need to try removing such "phantom" metadata files again. *)
3031 false
31- | Some rule_or_action_digest -> (
32- match
33- Metadata.Versioned. restore version ~rule_or_action_digest
34- with
35- | Not_found_in_cache ->
36- (* A concurrent process must have removed this metadata file. No
37- need to try removing such "phantom" metadata files again. *)
32+ | Error _exn ->
33+ (* If a metadata file can't be restored, let's trim it. *)
34+ true
35+ | Restored metadata -> (
36+ match metadata with
37+ | Metadata. Value _ ->
38+ (* We do not expect to see any value entries in the cache. Let's
39+ keep them untrimmed for now. *)
3840 false
39- | Error _exn ->
40- (* If a metadata file can't be restored, let's trim it. *)
41- true
42- | Restored metadata -> (
43- match metadata with
44- | Metadata. Value _ ->
45- (* We do not expect to see any value entries in the cache.
46- Let's keep them untrimmed for now. *)
47- false
48- | Metadata. Artifacts { entries; _ } ->
49- List. exists entries
50- ~f: (fun { Artifacts.Metadata_entry. file_digest; _ } ->
51- let reference = file_path ~file_digest in
52- not (Path. exists reference))))
41+ | Metadata. Artifacts { entries; _ } ->
42+ List. exists entries
43+ ~f: (fun { Artifacts.Metadata_entry. file_digest; _ } ->
44+ let reference = file_path ~file_digest in
45+ not (Path. exists reference)))
5346 in
5447 match should_be_removed with
5548 | true ->
@@ -73,14 +66,14 @@ let files_in_cache_for_all_supported_versions () =
7366let file_exists_and_is_unused ~stats = stats.Unix. st_nlink = 1
7467
7568let trim ~goal =
76- let files = files_in_cache_for_all_supported_versions () in
69+ let files = files_in_cache_for_all_supported_versions () |> List. map ~f: fst in
7770 let f path =
7871 let stats = Path. stat path in
7972 if file_exists_and_is_unused ~stats then
8073 Some (path, stats.st_size, stats.st_ctime)
8174 else
8275 None
83- and compare (_ , _ , t1 ) (_ , _ , t2 ) = Ordering. of_int ( Stdlib. compare t1 t2) in
76+ and compare (_ , _ , t1 ) (_ , _ , t2 ) = Poly. compare t1 t2 in
8477 let files = List. sort ~compare (List. filter_map ~f files)
8578 and delete (trimmed_so_far : Trimming_result.t ) (path , bytes , _ ) =
8679 if trimmed_so_far.trimmed_bytes > = goal then
@@ -98,7 +91,7 @@ let trim ~goal =
9891 trim_broken_metadata_entries ~trimmed_so_far
9992
10093let overhead_size () =
101- let files = files_in_cache_for_all_supported_versions () in
94+ let files = files_in_cache_for_all_supported_versions () |> List. map ~f: fst in
10295 let stats =
10396 let f p =
10497 try
0 commit comments