Skip to content

Commit 0917560

Browse files
authored
Merge pull request #133 from cgwalters/update-check
upgrade: Wire up --check to new API
2 parents 6f9f850 + 1c055ad commit 0917560

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

lib/src/cli.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,17 @@ pub(crate) async fn get_locked_sysroot() -> Result<ostree_ext::sysroot::SysrootL
186186
Ok(sysroot)
187187
}
188188

189+
/// Wrapper for pulling a container image, wiring up status output.
190+
async fn new_importer(
191+
repo: &ostree::Repo,
192+
imgref: &ostree_container::OstreeImageReference,
193+
) -> Result<ostree_container::store::ImageImporter> {
194+
let config = Default::default();
195+
let mut imp = ostree_container::store::ImageImporter::new(repo, imgref, config).await?;
196+
imp.require_bootable();
197+
Ok(imp)
198+
}
199+
189200
/// Wrapper for pulling a container image, wiring up status output.
190201
#[context("Pulling")]
191202
async fn pull(
@@ -194,8 +205,7 @@ async fn pull(
194205
quiet: bool,
195206
) -> Result<Box<LayeredImageState>> {
196207
let imgref = &OstreeImageReference::from(imgref.clone());
197-
let config = Default::default();
198-
let mut imp = ostree_container::store::ImageImporter::new(repo, imgref, config).await?;
208+
let mut imp = new_importer(repo, imgref).await?;
199209
let prep = match imp.prepare().await? {
200210
PrepareResult::AlreadyPresent(c) => {
201211
println!("No changes in {} => {}", imgref, c.manifest_digest);
@@ -259,6 +269,7 @@ pub(crate) async fn prepare_for_write() -> Result<()> {
259269
async fn upgrade(opts: UpgradeOpts) -> Result<()> {
260270
prepare_for_write().await?;
261271
let sysroot = &get_locked_sysroot().await?;
272+
let repo = &sysroot.repo();
262273
let booted_deployment = &sysroot.require_booted_deployment()?;
263274
let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?;
264275
// SAFETY: There must be a status if we have a booted deployment
@@ -278,27 +289,21 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
278289
.and_then(|e| e.image.as_ref())
279290
.map(|img| img.image_digest.as_str());
280291
if opts.check {
281-
// pull the image manifest without the layers
282-
let config = Default::default();
283-
let imgref = &OstreeImageReference::from(imgref.clone());
284-
let mut imp =
285-
ostree_container::store::ImageImporter::new(&sysroot.repo(), imgref, config).await?;
286-
imp.require_bootable();
292+
let imgref = imgref.clone().into();
293+
let mut imp = new_importer(repo, &imgref).await?;
287294
match imp.prepare().await? {
288-
PrepareResult::AlreadyPresent(c) => {
289-
println!(
290-
"No changes available for {}. Latest digest: {}",
291-
imgref, c.manifest_digest
292-
);
295+
PrepareResult::AlreadyPresent(_) => {
296+
println!("No changes in: {}", imgref);
293297
return Ok(());
294298
}
295299
PrepareResult::Ready(r) => {
296-
// TODO show a diff
297-
println!(
298-
"New image available for {imgref}. Digest {}",
299-
r.manifest_digest
300-
);
301-
// Note here we'll fall through to handling the --touch-if-changed below
300+
println!("Update available for: {}", imgref);
301+
println!(" Digest: {}", r.manifest_digest);
302+
if let Some(previous) = r.previous_state.as_ref() {
303+
let diff = ostree_container::ManifestDiff::new(&previous.manifest, &r.manifest);
304+
diff.print();
305+
}
306+
// Note fallthrough to -- touch-if-changed
302307
}
303308
}
304309
} else {

0 commit comments

Comments
 (0)