MCPcopy Create free account
hub / github.com/bootc-dev/bootc / edit_ostree

Function edit_ostree

crates/lib/src/cli.rs:1561–1614  ·  view source on GitHub ↗
(
    opts: EditOpts,
    storage: &Storage,
    booted_ostree: &BootedOstree<'_>,
)

Source from the content-addressed store, hash-verified

1559/// Implementation of the `bootc edit` CLI command for ostree backend.
1560#[context("Editing spec (ostree)")]
1561async fn edit_ostree(
1562 opts: EditOpts,
1563 storage: &Storage,
1564 booted_ostree: &BootedOstree<'_>,
1565) -> Result<()> {
1566 let repo = &booted_ostree.repo();
1567 let (_, host) = crate::status::get_status(booted_ostree)?;
1568
1569 let new_host: Host = if let Some(filename) = opts.filename {
1570 let mut r = std::io::BufReader::new(std::fs::File::open(filename)?);
1571 serde_yaml::from_reader(&mut r)?
1572 } else {
1573 let tmpf = tempfile::NamedTempFile::with_suffix(".yaml")?;
1574 serde_yaml::to_writer(std::io::BufWriter::new(tmpf.as_file()), &host)?;
1575 crate::utils::spawn_editor(&tmpf)?;
1576 tmpf.as_file().seek(std::io::SeekFrom::Start(0))?;
1577 serde_yaml::from_reader(&mut tmpf.as_file())?
1578 };
1579
1580 if new_host.spec == host.spec {
1581 println!("Edit cancelled, no changes made.");
1582 return Ok(());
1583 }
1584 host.spec.verify_transition(&new_host.spec)?;
1585 let new_spec = RequiredHostSpec::from_spec(&new_host.spec)?;
1586
1587 let prog = ProgressWriter::default();
1588
1589 // We only support two state transitions right now; switching the image,
1590 // or flipping the bootloader ordering.
1591 if host.spec.boot_order != new_host.spec.boot_order {
1592 return crate::deploy::rollback(storage).await;
1593 }
1594
1595 let fetched = crate::deploy::pull(
1596 repo,
1597 new_spec.image,
1598 None,
1599 opts.quiet,
1600 prog.clone(),
1601 Some(&booted_ostree.deployment),
1602 )
1603 .await?;
1604
1605 // TODO gc old layers here
1606
1607 let stateroot = booted_ostree.stateroot();
1608 let from = MergeState::from_stateroot(storage, &stateroot)?;
1609 crate::deploy::stage(storage, from, &fetched, &new_spec, prog.clone(), false).await?;
1610
1611 storage.update_mtime()?;
1612
1613 Ok(())
1614}
1615
1616/// Implementation of the `bootc edit` CLI command.
1617#[context("Editing spec")]

Callers 1

editFunction · 0.85

Calls 9

get_statusFunction · 0.85
spawn_editorFunction · 0.85
pullFunction · 0.85
stageFunction · 0.85
verify_transitionMethod · 0.80
update_mtimeMethod · 0.80
rollbackFunction · 0.70
repoMethod · 0.45
staterootMethod · 0.45

Tested by

no test coverage detected