Skip to content

Commit

Permalink
Factorize the linking of cache files
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Jul 5, 2024
1 parent 4107f3a commit 308a5fd
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/repository/opamRepository.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ let cache_file cache_dir checksum =
in
aux cache_dir (OpamHash.to_path checksum)

let link_files ~target f l =
List.iter (fun x ->
try
OpamFilename.link ~relative:true ~target ~link:(f x)
with Sys_error _ -> ()) (* Can happen on Windows *)
l

let fetch_from_cache =
let currently_downloading = ref [] in
let rec no_concurrent_dls key f x =
Expand Down Expand Up @@ -92,9 +99,6 @@ let fetch_from_cache =
| #OpamUrl.version_control ->
failwith "Version control not allowed as cache URL"
in
let link_files ~target f l =
List.iter (fun x -> OpamFilename.link ~relative:true ~target ~link:(f x)) l
in
try
match
List.fold_left (fun (hit, misses) ck ->
Expand Down Expand Up @@ -161,14 +165,9 @@ let validate_and_add_to_cache label url cache_dir file checksums =
(let checksums = OpamHash.sort checksums in
match cache_dir, checksums with
| Some dir, best_chks :: others_chks ->
OpamFilename.copy ~src:file ~dst:(cache_file dir best_chks);
List.iter (fun checksum ->
let target = cache_file dir best_chks in
let link = cache_file dir checksum in
try
OpamFilename.link ~relative:true ~target ~link
with Sys_error _ -> ())
others_chks;
let target = cache_file dir best_chks in
OpamFilename.copy ~src:file ~dst:target;
link_files ~target (cache_file dir) others_chks;
| _ -> ());
true

Expand Down

0 comments on commit 308a5fd

Please sign in to comment.