Add package conflicts
Packages can declare conflicts in orbit.json. The solver keeps them apart, and a global install offers to replace the installed ones in the way. Rollback now checks for clashes before it unlinks anything. Planning: 8m9kt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6d35f207fd
commit
cc47acb3e2
9 files changed
+831
-28
No files matched your search
+100
-12
@@ -21,6 +21,7 @@ fn manifest_of_installed(p : Installed) -> Manifest {
|
||||
description: p.description,
|
||||
documentation: "",
|
||||
depends: p.depends,
|
||||
conflicts: p.conflicts,
|
||||
bins: p.bins,
|
||||
}
|
||||
}
|
||||
@@ -60,12 +61,15 @@ fn parse_spec(spec : String) -> (String?, String, String) raise OrbitError {
|
||||
}
|
||||
|
||||
///|
|
||||
/// Build a SAT-solved install/upgrade plan for global state.
|
||||
/// Build a SAT-solved install/upgrade plan for global state. Packages in
|
||||
/// `replacing` don't constrain it; with `ignore_installed`, none do.
|
||||
async fn plan_global(
|
||||
ctx : Ctx,
|
||||
req_specs : Array[(String?, String, String, String)],
|
||||
upgrade : Array[String],
|
||||
explicit_new : Map[String, String],
|
||||
replacing? : Array[String] = [],
|
||||
ignore_installed? : Bool = false,
|
||||
) -> Array[Step] raise OrbitError {
|
||||
let ch_by_name : Map[String, Channel] = Map([])
|
||||
for c in ctx.channels {
|
||||
@@ -76,8 +80,16 @@ async fn plan_global(
|
||||
let manifest_cache : Map[String, Manifest] = Map([])
|
||||
|
||||
let locked_bins : Map[String, String] = Map([])
|
||||
let locked : Map[String, LockedInfo] = Map([])
|
||||
for name, inst in ctx.state {
|
||||
if !upgrade.contains(name) && !explicit_new.contains(name) {
|
||||
if !ignore_installed &&
|
||||
!upgrade.contains(name) &&
|
||||
!explicit_new.contains(name) &&
|
||||
!replacing.contains(name) {
|
||||
locked[name] = LockedInfo::{
|
||||
version: inst.version,
|
||||
conflicts: inst.conflicts,
|
||||
}
|
||||
for b in inst.bins {
|
||||
locked_bins[basename(b)] = name
|
||||
}
|
||||
@@ -161,9 +173,14 @@ async fn plan_global(
|
||||
},
|
||||
extra_reqs: fn(pkg_name) {
|
||||
let reqs : Array[SolveReq] = []
|
||||
if ignore_installed {
|
||||
return reqs
|
||||
}
|
||||
match ctx.state.get(pkg_name) {
|
||||
Some(inst) =>
|
||||
if inst.explicit && !explicit_new.contains(pkg_name) {
|
||||
if inst.explicit &&
|
||||
!explicit_new.contains(pkg_name) &&
|
||||
!replacing.contains(pkg_name) {
|
||||
reqs.push(SolveReq::{
|
||||
name: pkg_name,
|
||||
channel: Some(inst.channel),
|
||||
@@ -180,7 +197,8 @@ async fn plan_global(
|
||||
for other, oinst in ctx.state {
|
||||
if other != pkg_name &&
|
||||
!upgrade.contains(other) &&
|
||||
!explicit_new.contains(other) {
|
||||
!explicit_new.contains(other) &&
|
||||
!replacing.contains(other) {
|
||||
for dk, dc in oinst.depends {
|
||||
let (dch, dname) = parse_dep_key(dk)
|
||||
if dname == pkg_name {
|
||||
@@ -197,6 +215,7 @@ async fn plan_global(
|
||||
reqs
|
||||
},
|
||||
locked_bins,
|
||||
locked,
|
||||
}
|
||||
|
||||
let reqs : Array[SolveReq] = []
|
||||
@@ -300,8 +319,8 @@ fn check_bin_conflicts(
|
||||
}
|
||||
|
||||
///|
|
||||
/// Switch `name` to a fetched build, keeping the old one for rollback.
|
||||
async fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
/// Fetch a step's build into the store and check its contents.
|
||||
async fn fetch_step(ctx : Ctx, st : Step) -> String raise OrbitError {
|
||||
let ch = find_channel(ctx, st.channel)
|
||||
let dir = fetch_into_store(ctx, ch, st.name, st.digest)
|
||||
for b in st.manifest.bins {
|
||||
@@ -309,6 +328,13 @@ async fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
raise OrbitError("\{st.name}: bin '\{b}' missing from package contents")
|
||||
}
|
||||
}
|
||||
dir
|
||||
}
|
||||
|
||||
///|
|
||||
/// Switch `name` to a fetched build, keeping the old one for rollback.
|
||||
async fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
let dir = fetch_step(ctx, st)
|
||||
check_bin_conflicts(ctx, st.name, st.manifest.bins)
|
||||
match ctx.state.get(st.name) {
|
||||
Some(inst) => {
|
||||
@@ -320,6 +346,7 @@ async fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
description: inst.description,
|
||||
bins: inst.bins,
|
||||
depends: inst.depends,
|
||||
conflicts: inst.conflicts,
|
||||
})
|
||||
while inst.history.length() > 2 {
|
||||
inst.history.remove(0) |> ignore
|
||||
@@ -330,6 +357,7 @@ async fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
inst.description = st.manifest.description
|
||||
inst.bins = st.manifest.bins
|
||||
inst.depends = st.manifest.depends
|
||||
inst.conflicts = st.manifest.conflicts
|
||||
inst.explicit = st.explicit
|
||||
inst.constraint = st.constraint
|
||||
println(
|
||||
@@ -347,6 +375,7 @@ async fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
constraint: st.constraint,
|
||||
bins: st.manifest.bins,
|
||||
depends: st.manifest.depends,
|
||||
conflicts: st.manifest.conflicts,
|
||||
history: [],
|
||||
}
|
||||
println(" \{st.name} \{st.version} installed")
|
||||
@@ -358,8 +387,25 @@ async fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
}
|
||||
|
||||
///|
|
||||
async fn apply_plan(ctx : Ctx, steps : Array[Step]) -> Unit raise OrbitError {
|
||||
async fn apply_plan(
|
||||
ctx : Ctx,
|
||||
steps : Array[Step],
|
||||
removals? : Array[String] = [],
|
||||
) -> Unit raise OrbitError {
|
||||
let mut changed = 0
|
||||
if removals.length() > 0 {
|
||||
// Have the replacements at hand before removing anything.
|
||||
for st in steps {
|
||||
if !st.keep {
|
||||
ignore(fetch_step(ctx, st))
|
||||
}
|
||||
}
|
||||
for name in removals {
|
||||
remove_one(ctx, name)
|
||||
changed = changed + 1
|
||||
}
|
||||
save_state(ctx)
|
||||
}
|
||||
for st in steps {
|
||||
if st.keep {
|
||||
match ctx.state.get(st.name) {
|
||||
@@ -383,9 +429,14 @@ async fn apply_plan(ctx : Ctx, steps : Array[Step]) -> Unit raise OrbitError {
|
||||
}
|
||||
|
||||
///|
|
||||
async fn cmd_install(ctx : Ctx, specs : Array[String]) -> Unit raise OrbitError {
|
||||
async fn cmd_install(
|
||||
ctx : Ctx,
|
||||
specs : Array[String],
|
||||
replace? : Bool = false,
|
||||
interactive? : Bool = stdin_is_interactive(),
|
||||
) -> Unit raise OrbitError {
|
||||
if specs.length() == 0 {
|
||||
raise OrbitError("usage: orbit install [channel::]<name>[@constraint]...")
|
||||
raise OrbitError("usage: orbit install [--replace] [channel::]<name>[@constraint]...")
|
||||
}
|
||||
let reqs : Array[(String?, String, String, String)] = []
|
||||
let explicit_new : Map[String, String] = Map([])
|
||||
@@ -394,8 +445,15 @@ async fn cmd_install(ctx : Ctx, specs : Array[String]) -> Unit raise OrbitError
|
||||
reqs.push((channel, name, c, "command line"))
|
||||
explicit_new[name] = c
|
||||
}
|
||||
let steps = plan_global(ctx, reqs, [], explicit_new)
|
||||
apply_plan(ctx, steps)
|
||||
let (steps, removals) = plan_install(ctx, reqs, explicit_new)
|
||||
if removals.length() > 0 && !replace {
|
||||
confirm_replace(ctx, steps, removals, interactive)
|
||||
}
|
||||
apply_plan(ctx, steps, removals~)
|
||||
if removals.length() > 0 {
|
||||
autoremove(ctx)
|
||||
save_state(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -460,6 +518,16 @@ async fn cmd_upgrade(ctx : Ctx, names : Array[String]) -> Unit raise OrbitError
|
||||
}
|
||||
}
|
||||
let steps = plan_global(ctx, reqs, targets, Map([]))
|
||||
// Upgrading everything ends by removing the dependencies nobody needs.
|
||||
let leaving : Array[String] = []
|
||||
if names.length() == 0 {
|
||||
for name, inst in ctx.state {
|
||||
if !inst.explicit {
|
||||
leaving.push(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
check_plan_conflicts(ctx, steps, leaving)
|
||||
apply_plan(ctx, steps)
|
||||
if names.length() == 0 {
|
||||
autoremove(ctx)
|
||||
@@ -570,6 +638,18 @@ async fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
"previous build of \{name} (\{prev.version}) is no longer in the store",
|
||||
)
|
||||
}
|
||||
for other, oinst in ctx.state {
|
||||
if other != name &&
|
||||
(
|
||||
declares_conflict(prev.conflicts, other, oinst.version) ||
|
||||
declares_conflict(oinst.conflicts, name, prev.version)
|
||||
) {
|
||||
raise OrbitError(
|
||||
"\{name} \{prev.version} conflicts with installed \{other} \{oinst.version}",
|
||||
)
|
||||
}
|
||||
}
|
||||
check_bin_conflicts(ctx, name, prev.bins)
|
||||
unlink_bins(ctx, inst.bins)
|
||||
inst.history.push(Gen::{
|
||||
channel: inst.channel,
|
||||
@@ -578,6 +658,7 @@ async fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
description: inst.description,
|
||||
bins: inst.bins,
|
||||
depends: inst.depends,
|
||||
conflicts: inst.conflicts,
|
||||
})
|
||||
inst.channel = prev.channel
|
||||
let from = inst.version
|
||||
@@ -586,7 +667,7 @@ async fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
inst.description = prev.description
|
||||
inst.bins = prev.bins
|
||||
inst.depends = prev.depends
|
||||
check_bin_conflicts(ctx, name, inst.bins)
|
||||
inst.conflicts = prev.conflicts
|
||||
link_bins(ctx, dir, inst.bins)
|
||||
save_state(ctx)
|
||||
println("\{name}: \{from} -> \{prev.version}")
|
||||
@@ -696,6 +777,13 @@ fn cmd_info(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||
deps.push(d + "@" + c)
|
||||
}
|
||||
println(" depends: \{join(deps, " ")}")
|
||||
if !p.conflicts.is_empty() {
|
||||
let cs : Array[String] = []
|
||||
for n, c in p.conflicts {
|
||||
cs.push(n + "@" + c)
|
||||
}
|
||||
println(" conflicts: \{join(cs, " ")}")
|
||||
}
|
||||
let rd = reverse_deps(ctx, name)
|
||||
println(" needed by: \{join(rd, " ")}")
|
||||
let hist : Array[String] = []
|
||||
|
||||
Reference in new issue
Block a user