Skip to content

Commit

Permalink
boundimage: Drop const parameter
Browse files Browse the repository at this point in the history
We were always passing this single constant value to the
function; let's just reference it inside the function
and simplify callers.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Jul 18, 2024
1 parent 555e1db commit f1b2aa8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/src/boundimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ struct BoundImage {
/// Given a deployment, pull all container images it references.
pub(crate) fn pull_bound_images(sysroot: &SysrootLock, deployment: &Deployment) -> Result<()> {
let deployment_root = &crate::utils::deployment_fd(sysroot, deployment)?;
let bound_images = parse_spec_dir(deployment_root, BOUND_IMAGE_DIR)?;
let bound_images = parse_spec_dir(deployment_root)?;
pull_images(deployment_root, bound_images)
}

#[context("parse bound image spec dir")]
fn parse_spec_dir(root: &Dir, spec_dir: &str) -> Result<Vec<BoundImage>> {
fn parse_spec_dir(root: &Dir) -> Result<Vec<BoundImage>> {
let spec_dir = BOUND_IMAGE_DIR;
let Some(bound_images_dir) = root.open_dir_optional(spec_dir)? else {
tracing::debug!("Missing {spec_dir}");
return Ok(Default::default());
Expand Down Expand Up @@ -178,12 +179,12 @@ mod tests {

// Empty dir should return an empty vector
let td = &cap_std_ext::cap_tempfile::TempDir::new(cap_std::ambient_authority())?;
let images = parse_spec_dir(td, &BOUND_IMAGE_DIR).unwrap();
let images = parse_spec_dir(td).unwrap();
assert_eq!(images.len(), 0);

td.create_dir_all(BOUND_IMAGE_DIR).unwrap();
td.create_dir_all(CONTAINER_IMAGE_DIR).unwrap();
let images = parse_spec_dir(td, &BOUND_IMAGE_DIR).unwrap();
let images = parse_spec_dir(td).unwrap();
assert_eq!(images.len(), 0);

// Should return BoundImages
Expand Down Expand Up @@ -215,7 +216,7 @@ mod tests {
)
.unwrap();

let mut images = parse_spec_dir(td, &BOUND_IMAGE_DIR).unwrap();
let mut images = parse_spec_dir(td).unwrap();
images.sort_by(|a, b| a.image.as_str().cmp(&b.image.as_str()));
assert_eq!(images.len(), 2);
assert_eq!(images[0].image, "quay.io/bar/bar:latest");
Expand All @@ -224,13 +225,13 @@ mod tests {
// Invalid symlink should return an error
td.symlink("./blah", format!("{BOUND_IMAGE_DIR}/blah.image"))
.unwrap();
assert!(parse_spec_dir(td, &BOUND_IMAGE_DIR).is_err());
assert!(parse_spec_dir(td).is_err());

// Invalid image contents should return an error
td.write("error.image", "[Image]\n").unwrap();
td.symlink_contents("/error.image", format!("{BOUND_IMAGE_DIR}/error.image"))
.unwrap();
assert!(parse_spec_dir(td, &BOUND_IMAGE_DIR).is_err());
assert!(parse_spec_dir(td).is_err());

Ok(())
}
Expand Down

0 comments on commit f1b2aa8

Please sign in to comment.