Skip to content

Commit 8416b43

Browse files
committed
cfs: Add --write-dumpfile-to
I was trying to cut over to computing the digest directly from the mounted filesystem in build-sealed because it's WAY cleaner but ran face first into containers/composefs-rs#132 What *really* helped me debug this was this patch which adds support for printing the dumpfile corresponding to the two composefs trees so I could `diff -u` on them. Signed-off-by: Colin Walters <[email protected]>
1 parent 4b83fa3 commit 8416b43

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

crates/lib/src/cfsctl.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
use std::{
22
ffi::OsString,
3-
fs::create_dir_all,
3+
fs::{create_dir_all, File},
4+
io::BufWriter,
45
path::{Path, PathBuf},
56
sync::Arc,
67
};
78

8-
use anyhow::Result;
9+
use anyhow::{Context, Result};
10+
use camino::Utf8PathBuf;
911
use clap::{Parser, Subcommand};
1012

1113
use rustix::fs::CWD;
1214

1315
use composefs_boot::{write_boot, BootOps};
1416

1517
use composefs::{
18+
dumpfile,
1619
fsverity::{FsVerityHashValue, Sha512HashValue},
1720
repository::Repository,
1821
};
@@ -130,6 +133,9 @@ enum Command {
130133
},
131134
ComputeId {
132135
path: PathBuf,
136+
/// Write the dumpfile to the provided target
137+
#[clap(long)]
138+
write_dumpfile_to: Option<Utf8PathBuf>,
133139
#[clap(long)]
134140
bootable: bool,
135141
#[clap(long)]
@@ -308,6 +314,7 @@ where
308314
},
309315
Command::ComputeId {
310316
ref path,
317+
write_dumpfile_to,
311318
bootable,
312319
stat_root,
313320
} => {
@@ -317,6 +324,12 @@ where
317324
}
318325
let id = fs.compute_image_id();
319326
println!("{}", id.to_hex());
327+
if let Some(path) = write_dumpfile_to.as_deref() {
328+
let mut w = File::create(path)
329+
.with_context(|| format!("Opening {path}"))
330+
.map(BufWriter::new)?;
331+
dumpfile::write_dumpfile(&mut w, &fs).context("Writing dumpfile")?;
332+
}
320333
}
321334
Command::CreateImage {
322335
ref path,

crates/lib/src/cli.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//! Command line tool to manage bootable ostree-based containers.
44
55
use std::ffi::{CString, OsStr, OsString};
6-
use std::io::Seek;
6+
use std::fs::File;
7+
use std::io::{BufWriter, Seek};
78
use std::os::unix::process::CommandExt;
89
use std::process::Command;
910
use std::sync::Arc;
@@ -14,6 +15,7 @@ use cap_std_ext::cap_std;
1415
use cap_std_ext::cap_std::fs::Dir;
1516
use clap::Parser;
1617
use clap::ValueEnum;
18+
use composefs::dumpfile;
1719
use composefs_boot::BootOps as _;
1820
use etc_merge::{compute_diff, print_diff};
1921
use fn_error_context::context;
@@ -329,6 +331,10 @@ pub(crate) enum ContainerOpts {
329331
/// Output the bootable composefs digest.
330332
#[clap(hide = true)]
331333
ComputeComposefsDigest {
334+
/// Additionally generate a dumpfile written to the target path
335+
#[clap(long)]
336+
write_dumpfile_to: Option<Utf8PathBuf>,
337+
332338
/// Identifier for image; if not provided, the running image will be used.
333339
image: Option<String>,
334340
},
@@ -1365,7 +1371,10 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
13651371
)?;
13661372
Ok(())
13671373
}
1368-
ContainerOpts::ComputeComposefsDigest { image } => {
1374+
ContainerOpts::ComputeComposefsDigest {
1375+
write_dumpfile_to,
1376+
image,
1377+
} => {
13691378
// Allocate a tempdir
13701379
let td = tempdir_in("/var/tmp")?;
13711380
let td = td.path();
@@ -1412,6 +1421,13 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
14121421
let id = fs.compute_image_id();
14131422
println!("{}", id.to_hex());
14141423

1424+
if let Some(path) = write_dumpfile_to.as_deref() {
1425+
let mut w = File::create(path)
1426+
.with_context(|| format!("Opening {path}"))
1427+
.map(BufWriter::new)?;
1428+
dumpfile::write_dumpfile(&mut w, &fs).context("Writing dumpfile")?;
1429+
}
1430+
14151431
Ok(())
14161432
}
14171433
},

0 commit comments

Comments
 (0)