diff --git a/jruby_executable/src/bin/jruby_build.rs b/jruby_executable/src/bin/jruby_build.rs index 34bda4e..f8ea97a 100644 --- a/jruby_executable/src/bin/jruby_build.rs +++ b/jruby_executable/src/bin/jruby_build.rs @@ -127,24 +127,30 @@ fn jruby_build(args: &Args) -> Result<(), Box> { let timestamp = chrono::Utc::now(); for cpu_arch in &[CpuArch::new("amd64")?, CpuArch::new("arm64")?] { let distro_version = base_image.distro_version(); - + let artifact = Artifact { + version: GemVersion::from_str(version)?, + os: inventory::artifact::Os::Linux, + arch: cpu_arch.try_into()?, + url: format!( + "{S3_BASE_URL}/{}", + sha_seven_path.strip_prefix(&volume_output_dir)?.display() + ), + checksum: format!("sha256:{sha}").parse()?, + metadata: ArtifactMetadata { + distro_version, + timestamp, + }, + }; atomic_file_contents(&inventory, |file, contents| { let mut inventory = parse_inventory(contents)?; - inventory.push(Artifact { - version: GemVersion::from_str(version)?, - os: inventory::artifact::Os::Linux, - arch: cpu_arch.try_into()?, - url: format!( - "{S3_BASE_URL}/{}", - sha_seven_path.strip_prefix(&volume_output_dir)?.display() - ), - checksum: format!("sha256:{sha}").parse()?, - metadata: ArtifactMetadata { - distro_version, - timestamp, - }, + inventory.artifacts.retain(|a| { + a.version != artifact.version + || a.arch != artifact.arch + || a.metadata.distro_version != artifact.metadata.distro_version }); + inventory.push(artifact); + writeln!(file, "{inventory}").expect("Writeable file"); Ok(()) diff --git a/shared/src/inventory_help.rs b/shared/src/inventory_help.rs index f5b9cd5..ef57d69 100644 --- a/shared/src/inventory_help.rs +++ b/shared/src/inventory_help.rs @@ -2,16 +2,14 @@ use crate::base_image::DistroVersion; use crate::{download_tar, Error, TarDownloadPath}; use chrono::{DateTime, Utc}; use fs2::FileExt; -use fs_err::os::unix::fs; use gem_version::GemVersion; -use inventory::artifact::Artifact; use inventory::checksum::Checksum; use inventory::inventory::Inventory; use rayon::prelude::*; use serde::{Deserialize, Serialize}; use sha2::Sha256; use std::borrow::Borrow; -use std::io::{Read, Seek, Write}; +use std::io::Read; use std::path::Path; #[derive(Debug, Serialize, Deserialize, Clone)] @@ -169,9 +167,10 @@ where #[cfg(test)] mod test { - use std::str::FromStr; - use crate::BaseImage; + use inventory::artifact::Artifact; + use std::io::Write; + use std::str::FromStr; use super::*;