@@ -22,34 +22,27 @@ let trim_broken_metadata_entries ~trimmed_so_far =
22
22
Layout.Versioned. file_path (Version.Metadata. file_version version)
23
23
in
24
24
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 ) ->
26
26
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. *)
30
31
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. *)
38
40
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)))
53
46
in
54
47
match should_be_removed with
55
48
| true ->
@@ -73,14 +66,14 @@ let files_in_cache_for_all_supported_versions () =
73
66
let file_exists_and_is_unused ~stats = stats.Unix. st_nlink = 1
74
67
75
68
let 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
77
70
let f path =
78
71
let stats = Path. stat path in
79
72
if file_exists_and_is_unused ~stats then
80
73
Some (path, stats.st_size, stats.st_ctime)
81
74
else
82
75
None
83
- and compare (_ , _ , t1 ) (_ , _ , t2 ) = Ordering. of_int ( Stdlib. compare t1 t2) in
76
+ and compare (_ , _ , t1 ) (_ , _ , t2 ) = Poly. compare t1 t2 in
84
77
let files = List. sort ~compare (List. filter_map ~f files)
85
78
and delete (trimmed_so_far : Trimming_result.t ) (path , bytes , _ ) =
86
79
if trimmed_so_far.trimmed_bytes > = goal then
@@ -98,7 +91,7 @@ let trim ~goal =
98
91
trim_broken_metadata_entries ~trimmed_so_far
99
92
100
93
let 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
102
95
let stats =
103
96
let f p =
104
97
try
0 commit comments