Skip to content

Commit 67b0e12

Browse files
committed
Fix bugs with autoremove
- restriction to the cone of mentionned packages was broken - the command could cause conflicts in the case of orphan packages; when we only do removals that won't lead to rebuilds, as is the case with autoremove without argument, we can actually just ignore orphans (with argument, only keep orphans within the reverse dep cone, as usual).
1 parent e4e1546 commit 67b0e12

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

Diff for: .ocamlinit

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#use "topfind";;
2+
#use "down.top";;
23
#require "opam-client";;
34

45
OpamClientConfig.opam_init ();;

Diff for: master_changes.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ New option/command/subcommand are prefixed with ◈.
1919
* The stdout of `pre-` and `post-session` hooks is now propagated to the user [#4382 @AltGr - fix #4359]
2020

2121
## Remove
22-
*
22+
* Fix `opam remove --autoremove <PKG>` to not autoremove unrelated packages
23+
* Fix cases where `opam remove -a` could trigger conflicts in the presence of orphan packages
2324

2425
## Switch
2526
* Fix `--update-invariant` when removing or changing package name [#4360 @AltGr - fix #4353]

Diff for: src/client/opamClient.ml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1261,10 +1261,10 @@ let remove_t ?ask ~autoremove ~force atoms t =
12611261
(slog OpamFormula.string_of_atoms) atoms;
12621262

12631263
let t, full_orphans, orphan_versions =
1264-
let changes =
1265-
if autoremove then None
1266-
else Some (OpamSwitchState.packages_of_atoms t atoms) in
1267-
orphans ?changes t
1264+
if atoms = [] then t, OpamPackage.Set.empty, OpamPackage.Set.empty
1265+
else
1266+
let changes = OpamSwitchState.packages_of_atoms t atoms in
1267+
orphans ~changes t
12681268
in
12691269

12701270
let nothing_to_do = ref true in
@@ -1306,7 +1306,7 @@ let remove_t ?ask ~autoremove ~force atoms t =
13061306
let to_keep =
13071307
(if autoremove then t.installed_roots %% t.installed else t.installed)
13081308
++ universe.u_base
1309-
-- to_remove -- full_orphans -- orphan_versions
1309+
-- to_remove
13101310
in
13111311
let to_keep =
13121312
OpamSolver.dependencies ~build:true ~post:true
@@ -1318,10 +1318,10 @@ let remove_t ?ask ~autoremove ~force atoms t =
13181318
let requested = OpamPackage.names_of_packages packages in
13191319
let to_remove =
13201320
if autoremove then
1321-
let to_remove = t.installed -- to_keep in
1322-
if atoms = [] then to_remove
1321+
let to_remove1 = t.installed -- to_keep in
1322+
if atoms = [] then to_remove1
13231323
else (* restrict to the dependency cone of removed pkgs *)
1324-
to_remove %%
1324+
to_remove1 %%
13251325
(OpamSolver.dependencies ~build:true ~post:true
13261326
~depopts:true ~installed:true universe to_remove)
13271327
else to_remove in

Diff for: src/state/opamSwitchState.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ let load lock_kind gt rt switch =
314314
let opams =
315315
OpamPackage.Map.union (fun _ x -> x) repos_package_index pinned_opams
316316
in
317-
let packages = OpamPackage.keys opams in
318317
let available_packages =
319318
lazy (compute_available_packages gt switch switch_config
320319
~pinned ~opams)
@@ -324,6 +323,7 @@ let load lock_kind gt rt switch =
324323
computing availability *)
325324
OpamPackage.Map.union (fun _ x -> x) installed_opams opams
326325
in
326+
let packages = OpamPackage.keys opams in
327327
let installed_without_def =
328328
OpamPackage.Set.fold (fun nv nodef ->
329329
if OpamPackage.Map.mem nv installed_opams then nodef else

0 commit comments

Comments
 (0)