Use moonbitlang/async for process and file IO
Process execution and file access go through @process and @fs. The spinner is a background task in a task group, and the C stub keeps only getenv, exit, isatty, symlink and stderr output. orbit info reads installed state only, and it records and restores package descriptions. just install adds Orbit's bin directory to ~/.bashrc once. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
65e5dc966f
commit
ec21287549
11 files changed
+236
-213
No files matched your search
+83
-61
@@ -26,7 +26,7 @@ fn manifest_of_installed(p : Installed) -> Manifest {
|
||||
Manifest::{
|
||||
name: p.name,
|
||||
version: p.version,
|
||||
description: "",
|
||||
description: p.description,
|
||||
documentation: "",
|
||||
depends: p.depends,
|
||||
bins: p.bins,
|
||||
@@ -75,7 +75,7 @@ fn constraints_for(
|
||||
}
|
||||
|
||||
///|
|
||||
fn visit(
|
||||
async fn visit(
|
||||
p : Planner,
|
||||
name : String,
|
||||
requested : String,
|
||||
@@ -206,26 +206,35 @@ fn owner_of_bin(ctx : Ctx, bin : String) -> String? {
|
||||
}
|
||||
|
||||
///|
|
||||
fn unlink_bins(ctx : Ctx, bins : Array[String]) -> Unit {
|
||||
async fn unlink_bins(ctx : Ctx, bins : Array[String]) -> Unit noraise {
|
||||
for b in bins {
|
||||
sh("rm -f " + sq(bin_dir(ctx) + "/" + basename(b))) |> ignore
|
||||
let path = bin_dir(ctx) + "/" + basename(b)
|
||||
try {
|
||||
@fs.remove(path)
|
||||
} catch {
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn link_bins(
|
||||
async fn link_bins(
|
||||
ctx : Ctx,
|
||||
dir : String,
|
||||
bins : Array[String],
|
||||
) -> Unit raise OrbitError {
|
||||
sh_ok("mkdir -p " + sq(bin_dir(ctx)))
|
||||
try {
|
||||
@fs.mkdir(bin_dir(ctx), recursive=true)
|
||||
} catch {
|
||||
e => raise OrbitError("cannot create bin dir: " + e.to_string())
|
||||
}
|
||||
for b in bins {
|
||||
sh_ok(
|
||||
"ln -sfn " +
|
||||
sq(dir + "/" + b) +
|
||||
" " +
|
||||
sq(bin_dir(ctx) + "/" + basename(b)),
|
||||
)
|
||||
let target = dir + "/" + b
|
||||
let linkpath = bin_dir(ctx) + "/" + basename(b)
|
||||
let rc = c_symlink(utf8_encode(target), utf8_encode(linkpath))
|
||||
if rc != 0 {
|
||||
raise OrbitError("cannot symlink " + linkpath + " -> " + target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +259,7 @@ fn check_bin_conflicts(
|
||||
|
||||
///|
|
||||
/// Switch `name` to a fetched build, keeping the old one for rollback.
|
||||
fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
async fn activate(ctx : Ctx, st : Step) -> Unit 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 {
|
||||
@@ -266,6 +275,7 @@ fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
channel: inst.channel,
|
||||
version: inst.version,
|
||||
digest: inst.digest,
|
||||
description: inst.description,
|
||||
bins: inst.bins,
|
||||
depends: inst.depends,
|
||||
})
|
||||
@@ -275,6 +285,7 @@ fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
inst.channel = st.channel
|
||||
inst.version = st.version
|
||||
inst.digest = st.digest
|
||||
inst.description = st.manifest.description
|
||||
inst.bins = st.manifest.bins
|
||||
inst.depends = st.manifest.depends
|
||||
inst.explicit = st.explicit
|
||||
@@ -289,6 +300,7 @@ fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
channel: st.channel,
|
||||
version: st.version,
|
||||
digest: st.digest,
|
||||
description: st.manifest.description,
|
||||
explicit: st.explicit,
|
||||
constraint: st.constraint,
|
||||
bins: st.manifest.bins,
|
||||
@@ -304,13 +316,14 @@ fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
}
|
||||
|
||||
///|
|
||||
fn apply_plan(ctx : Ctx, p : Planner) -> Unit raise OrbitError {
|
||||
async fn apply_plan(ctx : Ctx, p : Planner) -> Unit raise OrbitError {
|
||||
let mut changed = 0
|
||||
for st in p.order {
|
||||
if st.keep {
|
||||
match ctx.state.get(st.name) {
|
||||
Some(inst) => {
|
||||
inst.channel = st.channel
|
||||
inst.description = st.manifest.description
|
||||
inst.explicit = st.explicit
|
||||
inst.constraint = st.constraint
|
||||
}
|
||||
@@ -333,7 +346,7 @@ fn new_planner(ctx : Ctx, upgrade : Array[String]) -> Planner {
|
||||
}
|
||||
|
||||
///|
|
||||
fn cmd_install(ctx : Ctx, specs : Array[String]) -> Unit raise OrbitError {
|
||||
async fn cmd_install(ctx : Ctx, specs : Array[String]) -> Unit raise OrbitError {
|
||||
if specs.length() == 0 {
|
||||
raise OrbitError("usage: orbit install [channel::]<name>[@constraint]...")
|
||||
}
|
||||
@@ -348,7 +361,7 @@ fn cmd_install(ctx : Ctx, specs : Array[String]) -> Unit raise OrbitError {
|
||||
///|
|
||||
/// Upgrade the named packages (or everything) to the newest versions their
|
||||
/// constraints allow. Dependencies are moved only when required.
|
||||
fn cmd_upgrade(ctx : Ctx, names : Array[String]) -> Unit raise OrbitError {
|
||||
async fn cmd_upgrade(ctx : Ctx, names : Array[String]) -> Unit raise OrbitError {
|
||||
let targets : Array[String] = []
|
||||
if names.length() == 0 {
|
||||
for name, _ in ctx.state {
|
||||
@@ -384,7 +397,7 @@ fn reverse_deps(ctx : Ctx, name : String) -> Array[String] {
|
||||
}
|
||||
|
||||
///|
|
||||
fn remove_one(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
async fn remove_one(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
match ctx.state.get(name) {
|
||||
Some(inst) => {
|
||||
unlink_bins(ctx, inst.bins)
|
||||
@@ -398,7 +411,7 @@ fn remove_one(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
|
||||
///|
|
||||
/// Remove dependencies nobody needs any more.
|
||||
fn autoremove(ctx : Ctx) -> Unit raise OrbitError {
|
||||
async fn autoremove(ctx : Ctx) -> Unit raise OrbitError {
|
||||
let mut changed = true
|
||||
while changed {
|
||||
changed = false
|
||||
@@ -416,7 +429,7 @@ fn autoremove(ctx : Ctx) -> Unit raise OrbitError {
|
||||
}
|
||||
|
||||
///|
|
||||
fn cmd_remove(
|
||||
async fn cmd_remove(
|
||||
ctx : Ctx,
|
||||
names : Array[String],
|
||||
force : Bool,
|
||||
@@ -451,7 +464,7 @@ fn cmd_remove(
|
||||
|
||||
///|
|
||||
/// Swap the current build with the previous one (run twice to undo).
|
||||
fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
async fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
let inst = match ctx.state.get(name) {
|
||||
Some(i) => i
|
||||
None => raise OrbitError("\{name} is not installed")
|
||||
@@ -471,6 +484,7 @@ fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
channel: inst.channel,
|
||||
version: inst.version,
|
||||
digest: inst.digest,
|
||||
description: inst.description,
|
||||
bins: inst.bins,
|
||||
depends: inst.depends,
|
||||
})
|
||||
@@ -478,6 +492,7 @@ fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
let from = inst.version
|
||||
inst.version = prev.version
|
||||
inst.digest = prev.digest
|
||||
inst.description = prev.description
|
||||
inst.bins = prev.bins
|
||||
inst.depends = prev.depends
|
||||
check_bin_conflicts(ctx, name, inst.bins)
|
||||
@@ -503,14 +518,19 @@ fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
|
||||
///|
|
||||
/// Delete store entries that are neither current nor kept for rollback.
|
||||
fn cmd_gc(ctx : Ctx) -> Unit raise OrbitError {
|
||||
async fn cmd_gc(ctx : Ctx) -> Unit raise OrbitError {
|
||||
let store = ctx.root + "/store"
|
||||
if !exists(store) {
|
||||
println("store is empty")
|
||||
return
|
||||
}
|
||||
let mut freed = 0
|
||||
for pkg in lines(capture("ls -1 " + sq(store))) {
|
||||
let pkgs = try {
|
||||
@fs.readdir(store)
|
||||
} catch {
|
||||
_ => []
|
||||
}
|
||||
for pkg in pkgs {
|
||||
match ctx.state.get(pkg) {
|
||||
None => {
|
||||
sh_ok("rm -rf " + sq(store + "/" + pkg))
|
||||
@@ -521,7 +541,12 @@ fn cmd_gc(ctx : Ctx) -> Unit raise OrbitError {
|
||||
for g in inst.history {
|
||||
keep.push(store_id(g.digest))
|
||||
}
|
||||
for id in lines(capture("ls -1 " + sq(store + "/" + pkg))) {
|
||||
let ids = try {
|
||||
@fs.readdir(store + "/" + pkg)
|
||||
} catch {
|
||||
_ => []
|
||||
}
|
||||
for id in ids {
|
||||
if !keep.contains(id) {
|
||||
sh_ok("rm -rf " + sq(store + "/" + pkg + "/" + id))
|
||||
freed = freed + 1
|
||||
@@ -531,7 +556,7 @@ fn cmd_gc(ctx : Ctx) -> Unit raise OrbitError {
|
||||
}
|
||||
}
|
||||
let tmp = ctx.root + "/tmp"
|
||||
ignore(sh("rm -rf " + sq(tmp) + " && mkdir -p " + sq(tmp)))
|
||||
let _ = sh("rm -rf " + sq(tmp) + " && mkdir -p " + sq(tmp))
|
||||
println("removed \{freed} store entries")
|
||||
}
|
||||
|
||||
@@ -551,7 +576,7 @@ fn cmd_list(ctx : Ctx) -> Unit {
|
||||
///|
|
||||
/// Where to look up "[channel::]name": the channel asked for, else the one it
|
||||
/// was installed from, else by priority.
|
||||
fn locate_spec(
|
||||
async fn locate_spec(
|
||||
ctx : Ctx,
|
||||
spec : String,
|
||||
) -> (String, Channel, Array[String]) raise OrbitError {
|
||||
@@ -566,44 +591,38 @@ fn locate_spec(
|
||||
|
||||
///|
|
||||
fn cmd_info(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||
let (_, name) = split_channel(spec)
|
||||
match ctx.state.get(name) {
|
||||
Some(p) => {
|
||||
println("\{name} \{p.version} (installed)")
|
||||
println(" channel: \{p.channel}")
|
||||
println(" digest: \{p.digest}")
|
||||
println(" constraint: \{p.constraint}")
|
||||
println(" bin: \{join(p.bins, " ")}")
|
||||
let deps : Array[String] = []
|
||||
for d, c in p.depends {
|
||||
deps.push(d + "@" + c)
|
||||
}
|
||||
println(" depends: \{join(deps, " ")}")
|
||||
let rd = reverse_deps(ctx, name)
|
||||
println(" needed by: \{join(rd, " ")}")
|
||||
let hist : Array[String] = []
|
||||
for g in p.history {
|
||||
hist.push(g.version)
|
||||
}
|
||||
println(" rollback: \{join(hist, " ")}")
|
||||
}
|
||||
None => ()
|
||||
let (pin, name) = split_channel(spec)
|
||||
let p = match ctx.state.get(name) {
|
||||
Some(p) => p
|
||||
None => raise OrbitError("\{spec} is not installed")
|
||||
}
|
||||
let (_, ch, tags) = locate_spec(ctx, spec)
|
||||
match pick_tag(tags, ["*"]) {
|
||||
Some(t) => {
|
||||
let m = fetch_manifest(ch, name, resolve_digest(ch, name, t))
|
||||
println("\{name} \{m.version} (latest in \{ch.name}: \{ch.url})")
|
||||
if m.description != "" {
|
||||
println(" \{m.description}")
|
||||
}
|
||||
}
|
||||
None => println("\{name}: no stable versions published")
|
||||
if pin is Some(channel) && channel != p.channel {
|
||||
raise OrbitError("\{spec} is not installed (installed from '\{p.channel}')")
|
||||
}
|
||||
println("\{name} \{p.version} (installed)")
|
||||
if p.description != "" {
|
||||
println(" description: \{p.description}")
|
||||
}
|
||||
println(" channel: \{p.channel}")
|
||||
println(" digest: \{p.digest}")
|
||||
println(" constraint: \{p.constraint}")
|
||||
println(" bin: \{join(p.bins, " ")}")
|
||||
let deps : Array[String] = []
|
||||
for d, c in p.depends {
|
||||
deps.push(d + "@" + c)
|
||||
}
|
||||
println(" depends: \{join(deps, " ")}")
|
||||
let rd = reverse_deps(ctx, name)
|
||||
println(" needed by: \{join(rd, " ")}")
|
||||
let hist : Array[String] = []
|
||||
for g in p.history {
|
||||
hist.push(g.version)
|
||||
}
|
||||
println(" rollback: \{join(hist, " ")}")
|
||||
}
|
||||
|
||||
///|
|
||||
fn cmd_versions(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||
async fn cmd_versions(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||
let (name, ch, tags) = locate_spec(ctx, spec)
|
||||
for v in sorted_versions(tags) {
|
||||
let mark = match ctx.state.get(name) {
|
||||
@@ -615,10 +634,13 @@ fn cmd_versions(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||
}
|
||||
|
||||
///|
|
||||
fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||
async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||
let mut listed = 0
|
||||
for ch in ctx.channels {
|
||||
let out = capture(oras(ch, "repo ls " + sq(ch.url))) catch {
|
||||
let out = capture(
|
||||
oras(ch, "repo ls " + sq(ch.url)),
|
||||
progress="Listing packages in \{ch.name}",
|
||||
) catch {
|
||||
_ => {
|
||||
println("warning: channel '\{ch.name}' does not allow listing packages")
|
||||
continue
|
||||
@@ -633,7 +655,7 @@ fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||
}
|
||||
if listed == 0 {
|
||||
raise OrbitError(
|
||||
"no channel allows listing packages (catalog API); try `orbit info <name>`",
|
||||
"no channel allows listing packages (catalog API); try `orbit versions <name>`",
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user