Skip to content

Commit 41ebc7f

Browse files
authored
Merge pull request #105 from jbtrystram/update-dry-run
cli: Add a `--check` flag for update
2 parents 730c07e + a022d80 commit 41ebc7f

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

CONTRIBUTING.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Required dependencies
2+
3+
In order to build `bootc` you will need the following dependencies.
4+
5+
Fedora:
6+
```
7+
sudo dnf install ostree-libs ostree-devel
8+
```
9+
10+
# Pre flight checks
11+
12+
Makes sure you commented your code additions, then run
13+
```
14+
cargo fmt
15+
cargo clippy
16+
```
17+
Make sure to apply any relevant suggestions.
18+

lib/src/cli.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ pub(crate) struct UpgradeOpts {
2828

2929
#[clap(long)]
3030
pub(crate) touch_if_changed: Option<Utf8PathBuf>,
31+
32+
/// Check if an update is available without applying it
33+
#[clap(long)]
34+
pub(crate) check: bool,
3135
}
3236

33-
/// Perform an upgrade operation
37+
/// Perform an switch operation
3438
#[derive(Debug, Parser)]
3539
pub(crate) struct SwitchOpts {
3640
/// Don't display progress
@@ -57,7 +61,7 @@ pub(crate) struct SwitchOpts {
5761
pub(crate) target: String,
5862
}
5963

60-
/// Perform an upgrade operation
64+
/// Perform a status operation
6165
#[derive(Debug, Parser)]
6266
pub(crate) struct StatusOpts {
6367
/// Output in JSON format.
@@ -281,14 +285,36 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
281285
let commit = booted_deployment.csum();
282286
let state = ostree_container::store::query_image_commit(repo, &commit)?;
283287
let digest = state.manifest_digest.as_str();
284-
let fetched = pull(repo, &imgref, opts.quiet).await?;
285288

286-
if fetched.merge_commit.as_str() == commit.as_str() {
287-
println!("Already queued: {digest}");
288-
return Ok(());
289-
}
289+
if opts.check {
290+
// pull the image manifest without the layers
291+
let config = Default::default();
292+
let mut imp = ostree_container::store::ImageImporter::new(repo, &imgref, config).await?;
293+
match imp.prepare().await? {
294+
PrepareResult::AlreadyPresent(c) => {
295+
println!(
296+
"No changes available for {}. Latest digest: {}",
297+
imgref, c.manifest_digest
298+
);
299+
return Ok(());
300+
}
301+
PrepareResult::Ready(p) => {
302+
println!(
303+
"New manifest available for {}. Digest {}",
304+
imgref, p.manifest_digest
305+
);
306+
}
307+
}
308+
} else {
309+
let fetched = pull(repo, &imgref, opts.quiet).await?;
310+
311+
if fetched.merge_commit.as_str() == commit.as_str() {
312+
println!("Already queued: {digest}");
313+
return Ok(());
314+
}
290315

291-
stage(sysroot, &osname, &imgref, fetched, &origin).await?;
316+
stage(sysroot, &osname, &imgref, fetched, &origin).await?;
317+
}
292318

293319
if let Some(path) = opts.touch_if_changed {
294320
std::fs::write(&path, "").with_context(|| format!("Writing {path}"))?;

0 commit comments

Comments
 (0)