From 5b34ba3a9e005492e1a7f598c7adf232aa40f666 Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Tue, 8 Oct 2024 13:35:52 +0200 Subject: [PATCH] teach gc about composefs-info objects --- src/repository.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/repository.rs b/src/repository.rs index 6856bc4..ed222ba 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -12,6 +12,7 @@ use std::{ Path, PathBuf, }, + process::Command, }; use anyhow::{ @@ -324,7 +325,28 @@ impl Repository { println!("{} lives as an image", hex::encode(object)); objects.insert(object); - // TODO: composefs-info objects + // composefs-info mmaps the file, so pipes aren't normally OK but we pass the + // underlying file directly, which works. + let output = Command::new("composefs-info") + .stdin(File::from(self.open_object(object)?)) + .args(["objects", "/proc/self/fd/0"]) + .output()? + .stdout; + + if output.len() % 66 != 0 { + bail!("composefs-info gave invalid output (wrong size)"); + } + + for line in output.chunks_exact(66) { + if line[2] != b'/' || line[65] != b'\n' { + bail!("composefs-info gave invalid output"); + } + let mut value = Sha256HashValue::EMPTY; + hex::decode_to_slice(&line[0..2], &mut value[0..1])?; + hex::decode_to_slice(&line[3..65], &mut value[1..32])?; + println!(" with {}", hex::encode(&value)); + objects.insert(value); + } } for object in self.gc_category("streams")? {