Skip to content

Commit

Permalink
teach gc about composefs-info objects
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonkarlitskaya committed Oct 8, 2024
1 parent 5f2cd16 commit 5b34ba3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{
Path,
PathBuf,
},
process::Command,
};

use anyhow::{
Expand Down Expand Up @@ -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")? {
Expand Down

0 comments on commit 5b34ba3

Please sign in to comment.