Skip to content

Commit

Permalink
Fix the install cache storing the wrong version of the opam file afte…
Browse files Browse the repository at this point in the history
…r a build failure
  • Loading branch information
kit-ty-kate committed Sep 26, 2024
1 parent 3c31268 commit 1b0440c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ users)
## Config report

## Actions
* Fix the install cache storing the wrong version of the opam file after a build failure [#6213 @kit-ty-kate]

## Install

Expand Down
48 changes: 39 additions & 9 deletions src/client/opamSolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -824,15 +824,45 @@ let parallel_apply t

(* 2/ Display errors and finalize *)

OpamSwitchState.Installed_cache.save
(OpamPath.Switch.installed_opams_cache t.switch_global.root t.switch)
(OpamPackage.Set.fold (fun nv opams ->
let opam =
OpamSwitchState.opam t nv |>
OpamFile.OPAM.with_metadata_dir None
in
OpamPackage.Map.add nv opam opams)
t.installed OpamPackage.Map.empty);
let save_installed_cache failed =
OpamSwitchState.Installed_cache.save
(OpamPath.Switch.installed_opams_cache t.switch_global.root t.switch)
(OpamPackage.Set.fold (fun nv opams ->
let pkg_failed =
List.exists (function
| `Fetch ps -> List.for_all (OpamPackage.equal nv) ps
| `Build p
| `Change (_, _, p)
| `Install p
| `Reinstall p
| `Remove p -> OpamPackage.equal nv p)
failed
in
let add_to_opams opam =
let opam = OpamFile.OPAM.with_metadata_dir None opam in
OpamPackage.Map.add nv opam opams
in
if pkg_failed then
match OpamPackage.Map.find_opt nv t.installed_opams with
| None -> opams
| Some opam -> add_to_opams opam
else
add_to_opams (OpamSwitchState.opam t nv))
t.installed OpamPackage.Map.empty);
in
begin match action_results with
| `Exception _ | `Error Aborted -> ()
| `Error (Nothing_to_do | OK _) -> assert false
| `Error (Partial_error res) ->
let { actions_successes = _;
actions_errors;
actions_aborted;
} = res
in
save_installed_cache (List.map fst actions_errors @ actions_aborted)
| `Successful _ ->
save_installed_cache []
end;

let cleanup_artefacts graph =
PackageActionGraph.iter_vertex (function
Expand Down
10 changes: 2 additions & 8 deletions tests/reftests/extrafile.test
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,5 @@ extra-files: [
["something.patch" "md5=cfbe7fc8ca145cbd193a140c0824c40b"]
]
### opam upgrade
The following actions will be performed:
=== recompile 1 package
- recompile upgrade 1 [upstream or system changes]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed upgrade.1
-> installed upgrade.1
Done.
Already up-to-date.
Nothing to do.

0 comments on commit 1b0440c

Please sign in to comment.