Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions crates/lib/src/cfsctl.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use std::{
ffi::OsString,
fs::create_dir_all,
fs::{create_dir_all, File},
io::BufWriter,
path::{Path, PathBuf},
sync::Arc,
};

use anyhow::Result;
use anyhow::{Context, Result};
use camino::Utf8PathBuf;
use clap::{Parser, Subcommand};

use rustix::fs::CWD;

use composefs_boot::{write_boot, BootOps};

use composefs::{
dumpfile,
fsverity::{FsVerityHashValue, Sha512HashValue},
repository::Repository,
};
Expand Down Expand Up @@ -130,6 +133,9 @@ enum Command {
},
ComputeId {
path: PathBuf,
/// Write the dumpfile to the provided target
#[clap(long)]
write_dumpfile_to: Option<Utf8PathBuf>,
#[clap(long)]
bootable: bool,
#[clap(long)]
Expand Down Expand Up @@ -308,6 +314,7 @@ where
},
Command::ComputeId {
ref path,
write_dumpfile_to,
bootable,
stat_root,
} => {
Expand All @@ -317,6 +324,12 @@ where
}
let id = fs.compute_image_id();
println!("{}", id.to_hex());
if let Some(path) = write_dumpfile_to.as_deref() {
let mut w = File::create(path)
.with_context(|| format!("Opening {path}"))
.map(BufWriter::new)?;
dumpfile::write_dumpfile(&mut w, &fs).context("Writing dumpfile")?;
}
}
Command::CreateImage {
ref path,
Expand Down
20 changes: 18 additions & 2 deletions crates/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
//! Command line tool to manage bootable ostree-based containers.

use std::ffi::{CString, OsStr, OsString};
use std::io::Seek;
use std::fs::File;
use std::io::{BufWriter, Seek};
use std::os::unix::process::CommandExt;
use std::process::Command;
use std::sync::Arc;
Expand All @@ -14,6 +15,7 @@ use cap_std_ext::cap_std;
use cap_std_ext::cap_std::fs::Dir;
use clap::Parser;
use clap::ValueEnum;
use composefs::dumpfile;
use composefs_boot::BootOps as _;
use etc_merge::{compute_diff, print_diff};
use fn_error_context::context;
Expand Down Expand Up @@ -329,6 +331,10 @@ pub(crate) enum ContainerOpts {
/// Output the bootable composefs digest.
#[clap(hide = true)]
ComputeComposefsDigest {
/// Additionally generate a dumpfile written to the target path
#[clap(long)]
write_dumpfile_to: Option<Utf8PathBuf>,

/// Identifier for image; if not provided, the running image will be used.
image: Option<String>,
},
Expand Down Expand Up @@ -1365,7 +1371,10 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
)?;
Ok(())
}
ContainerOpts::ComputeComposefsDigest { image } => {
ContainerOpts::ComputeComposefsDigest {
write_dumpfile_to,
image,
} => {
// Allocate a tempdir
let td = tempdir_in("/var/tmp")?;
let td = td.path();
Expand Down Expand Up @@ -1412,6 +1421,13 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
let id = fs.compute_image_id();
println!("{}", id.to_hex());

if let Some(path) = write_dumpfile_to.as_deref() {
let mut w = File::create(path)
.with_context(|| format!("Opening {path}"))
.map(BufWriter::new)?;
dumpfile::write_dumpfile(&mut w, &fs).context("Writing dumpfile")?;
}

Ok(())
}
},
Expand Down