From fcc20051494a7ee2a16ad581d274bbe968862a07 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 18 Jul 2024 16:35:38 -0400 Subject: [PATCH] boundimage: Drop const parameter 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 --- lib/src/boundimage.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/src/boundimage.rs b/lib/src/boundimage.rs index 89ba491bf..7718679b8 100644 --- a/lib/src/boundimage.rs +++ b/lib/src/boundimage.rs @@ -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> { +fn parse_spec_dir(root: &Dir) -> Result> { + 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()); @@ -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 @@ -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"); @@ -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(()) }