summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/manifest.rs11
-rw-r--r--tests/compare.rs51
2 files changed, 59 insertions, 3 deletions
diff --git a/src/manifest.rs b/src/manifest.rs
index 6168706..8e9d13c 100644
--- a/src/manifest.rs
+++ b/src/manifest.rs
@@ -69,7 +69,7 @@ impl ArtifactManifest {
}
Self::new(
packages,
- collect_files(rootfs)?,
+ collect_files(rootfs, initrd.as_ref())?,
initrd,
collect_services(rootfs)?,
collect_archive_members(archive.as_ref())?,
@@ -119,7 +119,9 @@ impl ArtifactManifest {
bail!("multiple initrd images found in archive {}", archive_path.display());
}
}
- files.push(FileRecord::file(path, digest));
+ if !path.starts_with("boot/initrd-") || !path.ends_with(".img") {
+ files.push(FileRecord::file(path, digest));
+ }
}
EntryType::Symlink => {
let target = entry
@@ -153,7 +155,7 @@ impl ArtifactManifest {
}
}
-fn collect_files(rootfs: &Path) -> Result<Vec<FileRecord>> {
+fn collect_files(rootfs: &Path, initrd: Option<&InitrdRecord>) -> Result<Vec<FileRecord>> {
let mut files = Vec::new();
let mut entries = WalkDir::new(rootfs)
.follow_links(false)
@@ -169,6 +171,9 @@ fn collect_files(rootfs: &Path) -> Result<Vec<FileRecord>> {
continue;
}
let path = portable_path(relative)?;
+ if initrd.is_some_and(|record| record.path == path) {
+ continue;
+ }
let file_type = entry.file_type();
if file_type.is_file() {
let metadata = entry.metadata().with_context(|| format!("inspect rootfs file {}", entry.path().display()))?;
diff --git a/tests/compare.rs b/tests/compare.rs
index 8bc1a07..2e06a39 100644
--- a/tests/compare.rs
+++ b/tests/compare.rs
@@ -79,6 +79,57 @@ fn distinguishes_added_and_removed_initrd_records() {
}
#[test]
+fn archive_collection_records_an_initrd_once_as_a_dedicated_boot_fact() {
+ let fixture = tempdir().expect("temporary directory");
+ let rootfs = fixture.path().join("rootfs");
+ fs::create_dir_all(rootfs.join("boot")).expect("create boot directory");
+ fs::write(rootfs.join("boot/initrd-6.12-rt1.img"), "initrd\n").expect("write initrd");
+ let artifact = fixture.path().join("controller.tar");
+ NativeTarWriter::new()
+ .write(&rootfs, &artifact)
+ .expect("write native archive");
+
+ let manifest = ArtifactManifest::collect_archive(&artifact).expect("collect archive facts");
+
+ assert_eq!(
+ manifest.initrd,
+ Some(InitrdRecord::new(
+ "boot/initrd-6.12-rt1.img",
+ "8f7ed204b9dfaa20aa484445f54233c4b407cb80ec0f8c07f1f0a59675fb44cf",
+ ))
+ );
+ assert!(manifest
+ .files
+ .iter()
+ .all(|record| record.path != "boot/initrd-6.12-rt1.img"));
+}
+
+#[test]
+fn rootfs_collection_records_a_supplied_initrd_once_as_a_dedicated_boot_fact() {
+ let fixture = tempdir().expect("temporary directory");
+ let rootfs = fixture.path().join("rootfs");
+ fs::create_dir_all(rootfs.join("boot")).expect("create boot directory");
+ fs::write(rootfs.join("boot/initrd-6.12-rt1.img"), "initrd\n").expect("write initrd");
+ let artifact = fixture.path().join("controller.tar");
+ NativeTarWriter::new()
+ .write(&rootfs, &artifact)
+ .expect("write native archive");
+ let initrd = InitrdRecord::new(
+ "boot/initrd-6.12-rt1.img",
+ "8f7ed204b9dfaa20aa484445f54233c4b407cb80ec0f8c07f1f0a59675fb44cf",
+ );
+
+ let manifest = ArtifactManifest::collect(&rootfs, vec![], Some(initrd.clone()), &artifact)
+ .expect("collect rootfs facts");
+
+ assert_eq!(manifest.initrd, Some(initrd));
+ assert!(manifest
+ .files
+ .iter()
+ .all(|record| record.path != "boot/initrd-6.12-rt1.img"));
+}
+
+#[test]
fn reads_and_writes_a_toml_manifest_beside_an_artifact() {
let fixture = tempdir().expect("temporary directory");
let artifact = fixture.path().join("controller.tar");