Skip to content

Commit 361eeb7

Browse files
committed
cfsctl: Fix keyring command and seal for repo-less/config-less usage
Route keyring commands through run_app() before opening a repository, fixing 'cfsctl keyring add-cert' which doesn't need a repo but was failing with 'Cannot open composefs repository at /sysroot/composefs'. Consolidate CLI dispatch: main.rs delegates to cfsctl::run_from_args() instead of duplicating the dispatch logic. Fix 'oci seal' to handle OCI images whose ImageConfiguration has config: None (allowed by the OCI spec) by using unwrap_or_default(). Assisted-by: OpenCode (Claude claude-opus-4-6)
1 parent bd959d1 commit 361eeb7

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

crates/cfsctl/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ fn run_keyring_cmd(cmd: &KeyringCommand) -> Result<()> {
355355
Ok(())
356356
}
357357

358+
/// Run the CLI using `std::env::args()`, as if invoked from the command line.
359+
pub async fn run_from_args() -> Result<()> {
360+
run_app(App::parse()).await
361+
}
362+
358363
/// Acts as a proxy for the `cfsctl` CLI by executing the CLI logic programmatically
359364
///
360365
/// This function behaves the same as invoking the `cfsctl` binary from the
@@ -368,7 +373,10 @@ where
368373
let args = App::parse_from(
369374
std::iter::once(OsString::from("cfsctl")).chain(args.into_iter().map(Into::into)),
370375
);
376+
run_app(args).await
377+
}
371378

379+
async fn run_app(args: App) -> Result<()> {
372380
// Handle commands that don't need a repository first
373381
if let Command::Keyring { ref cmd } = args.cmd {
374382
return run_keyring_cmd(cmd);
@@ -1125,8 +1133,8 @@ where
11251133
);
11261134
}
11271135
}
1128-
Command::Keyring { ref cmd } => {
1129-
run_keyring_cmd(cmd)?;
1136+
Command::Keyring { .. } => {
1137+
unreachable!("keyring commands are handled before opening a repository")
11301138
}
11311139
#[cfg(feature = "http")]
11321140
Command::Fetch { url, name } => {

crates/cfsctl/src/main.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,10 @@
44
//! creating and mounting filesystem images, handling OCI containers, and performing
55
//! repository maintenance operations like garbage collection.
66
7-
use cfsctl::{open_repo, run_cmd_with_repo, App, HashType};
8-
97
use anyhow::Result;
10-
use clap::Parser;
11-
use composefs::fsverity::{Sha256HashValue, Sha512HashValue};
128

139
#[tokio::main]
1410
async fn main() -> Result<()> {
1511
env_logger::init();
16-
17-
let args = App::parse();
18-
19-
match args.hash {
20-
HashType::Sha256 => run_cmd_with_repo(open_repo::<Sha256HashValue>(&args)?, args).await,
21-
HashType::Sha512 => run_cmd_with_repo(open_repo::<Sha512HashValue>(&args)?, args).await,
22-
}
12+
cfsctl::run_from_args().await
2313
}

crates/composefs-oci/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub mod tar;
2121

2222
use std::{collections::HashMap, io::Read, sync::Arc};
2323

24-
use anyhow::{bail, ensure, Context, Result};
24+
use anyhow::{bail, ensure, Result};
2525
use containers_image_proxy::ImageProxyConfig;
2626
use oci_spec::image::ImageConfiguration;
2727
use sha2::{Digest, Sha256};
@@ -248,7 +248,7 @@ pub fn seal<ObjectID: FsVerityHashValue>(
248248
config_verity: Option<&ObjectID>,
249249
) -> Result<ContentAndVerity<ObjectID>> {
250250
let (mut config, refs) = open_config(repo, config_name, config_verity)?;
251-
let mut myconfig = config.config().clone().context("no config!")?;
251+
let mut myconfig = config.config().clone().unwrap_or_default();
252252
let labels = myconfig.labels_mut().get_or_insert_with(HashMap::new);
253253
let fs = crate::image::create_filesystem(repo, config_name, config_verity)?;
254254
let id = fs.compute_image_id();

0 commit comments

Comments
 (0)