Skip to content

Commit fd68fdf

Browse files
committed
ostree-ext/cli: make json output reproducible
Signed-off-by: Etienne Champetier <[email protected]>
1 parent 7887daa commit fd68fdf

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ostree-ext/src/cli.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::commit::container_commit;
3030
use crate::container::store::{ExportToOCIOpts, ImportProgress, LayerProgress, PreparedImport};
3131
use crate::container::{self as ostree_container, ManifestDiff};
3232
use crate::container::{Config, ImageReference, OstreeImageReference};
33+
use crate::json::JsonOrderedSerialize;
3334
use crate::objectsource::ObjectSourceMeta;
3435
use crate::sysroot::SysrootLock;
3536
use ostree_container::store::{ImageImporter, PrepareResult};
@@ -880,7 +881,9 @@ async fn container_store(
880881
if let Some(check) = check.as_deref() {
881882
let rootfs = Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
882883
rootfs.atomic_replace_with(check.as_str().trim_start_matches('/'), |w| {
883-
serde_json::to_writer(w, &prep.manifest).context("Serializing manifest")
884+
prep.manifest
885+
.to_json_ordered_writer(w)
886+
.context("Serializing manifest")
884887
})?;
885888
// In check mode, we're done
886889
return Ok(());
@@ -1007,10 +1010,11 @@ fn container_remount_sysroot(sysroot: &Utf8Path) -> Result<()> {
10071010
#[context("Serializing to output file")]
10081011
fn handle_serialize_to_file<T: serde::Serialize>(path: Option<&Utf8Path>, obj: T) -> Result<()> {
10091012
if let Some(path) = path {
1010-
let mut out = std::fs::File::create(path)
1013+
let out = std::fs::File::create(path)
10111014
.map(BufWriter::new)
10121015
.with_context(|| anyhow::anyhow!("Opening {path} for writing"))?;
1013-
serde_json::to_writer(&mut out, &obj).context("Serializing output")?;
1016+
obj.to_json_ordered_writer(out)
1017+
.context("Serializing output")?;
10141018
}
10151019
Ok(())
10161020
}
@@ -1136,9 +1140,9 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
11361140
let stdout = std::io::stdout().lock();
11371141
let mut stdout = std::io::BufWriter::new(stdout);
11381142
if config {
1139-
serde_json::to_writer(&mut stdout, &image.configuration)?;
1143+
image.configuration.to_json_ordered_writer(&mut stdout)?;
11401144
} else {
1141-
serde_json::to_writer(&mut stdout, &image.manifest)?;
1145+
image.manifest.to_json_ordered_writer(&mut stdout)?;
11421146
}
11431147
stdout.flush()?;
11441148
Ok(())

0 commit comments

Comments
 (0)