From 3d390e557f8c2b39cf541549492bb518e67a8c30 Mon Sep 17 00:00:00 2001 From: isa Date: Tue, 24 Sep 2024 11:22:31 -0400 Subject: [PATCH] Convert citadel image version numbers to semver --- Cargo.lock | 9 ++++++++- citadel-tool/src/boot/rootfs.rs | 7 +++++-- citadel-tool/src/image/mod.rs | 4 ++-- citadel-tool/src/mkimage/build.rs | 10 +++++----- citadel-tool/src/mkimage/config.rs | 6 +++--- citadel-tool/src/update/mod.rs | 6 +++--- libcitadel/Cargo.toml | 1 + libcitadel/src/header.rs | 6 +++--- libcitadel/src/resource.rs | 7 +++++-- libcitadel/src/util.rs | 7 ++++++- 10 files changed, 41 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ae5668..52eddb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1212,6 +1212,7 @@ dependencies = [ "nix 0.17.0", "posix-acl", "procfs", + "semver 1.0.23", "serde", "serde_derive", "serde_json", @@ -1773,7 +1774,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" dependencies = [ - "semver", + "semver 0.11.0", ] [[package]] @@ -1800,6 +1801,12 @@ dependencies = [ "semver-parser", ] +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + [[package]] name = "semver-parser" version = "0.10.2" diff --git a/citadel-tool/src/boot/rootfs.rs b/citadel-tool/src/boot/rootfs.rs index 3a74cb7..df12750 100644 --- a/citadel-tool/src/boot/rootfs.rs +++ b/citadel-tool/src/boot/rootfs.rs @@ -136,8 +136,11 @@ fn compare_boot_partitions(a: Option, b: Partition) -> Option Result<()> { if kernel_version.chars().any(|c| c == '/') { bail!("Kernel version field has / char"); } - format!("citadel-kernel-{}-{:03}.img", kernel_version, metainfo.version()) + format!("citadel-kernel-{}-{}.img", kernel_version, metainfo.version()) } else { - format!("citadel-extra-{:03}.img", metainfo.version()) + format!("citadel-extra-{}.img", metainfo.version()) }; if !metainfo.channel().chars().all(|c| c.is_ascii_lowercase()) { diff --git a/citadel-tool/src/mkimage/build.rs b/citadel-tool/src/mkimage/build.rs index b2ae638..47cc9fa 100644 --- a/citadel-tool/src/mkimage/build.rs +++ b/citadel-tool/src/mkimage/build.rs @@ -38,15 +38,15 @@ impl UpdateBuilder { } fn target_filename(&self) -> String { - format!("citadel-{}-{}-{:03}.img", self.config.img_name(), self.config.channel(), self.config.version()) + format!("citadel-{}-{}-{:}.img", self.config.img_name(), self.config.channel(), self.config.version()) } fn build_filename(config: &BuildConfig) -> String { - format!("citadel-{}-{}-{:03}", config.image_type(), config.channel(), config.version()) + format!("citadel-{}-{}-{}", config.image_type(), config.channel(), config.version()) } fn verity_filename(&self) -> String { - format!("verity-hash-{}-{:03}", self.config.image_type(), self.config.version()) + format!("verity-hash-{}-{}", self.config.image_type(), self.config.version()) } pub fn build(&mut self) -> Result<()> { @@ -154,7 +154,7 @@ impl UpdateBuilder { bail!("failed to compress {:?}: {}", self.image(), err); } // Rename back to original image_data filename - util::rename(self.image().with_extension("xz"), self.image())?; + util::rename(util::append_to_path(self.image(), ".xz"), self.image())?; } Ok(()) } @@ -217,7 +217,7 @@ impl UpdateBuilder { writeln!(v, "realmfs-name = \"{}\"", name)?; } writeln!(v, "channel = \"{}\"", self.config.channel())?; - writeln!(v, "version = {}", self.config.version())?; + writeln!(v, "version = \"{}\"", self.config.version())?; writeln!(v, "timestamp = \"{}\"", self.config.timestamp())?; writeln!(v, "nblocks = {}", self.nblocks.unwrap())?; writeln!(v, "shasum = \"{}\"", self.shasum.as_ref().unwrap())?; diff --git a/citadel-tool/src/mkimage/config.rs b/citadel-tool/src/mkimage/config.rs index 7ff2e09..77d52ef 100644 --- a/citadel-tool/src/mkimage/config.rs +++ b/citadel-tool/src/mkimage/config.rs @@ -9,7 +9,7 @@ pub struct BuildConfig { #[serde(rename = "image-type")] image_type: String, channel: String, - version: usize, + version: String, timestamp: String, source: String, #[serde(default)] @@ -102,8 +102,8 @@ impl BuildConfig { self.realmfs_name.as_ref().map(|s| s.as_str()) } - pub fn version(&self) -> usize { - self.version + pub fn version(&self) -> &str { + &self.version } pub fn channel(&self) -> &str { diff --git a/citadel-tool/src/update/mod.rs b/citadel-tool/src/update/mod.rs index 69844ae..39b18af 100644 --- a/citadel-tool/src/update/mod.rs +++ b/citadel-tool/src/update/mod.rs @@ -93,7 +93,7 @@ fn create_tmp_copy(path: &Path) -> Result { Ok(path) } -fn install_image(path: &Path, flags: u32) -> Result<()> { +pub fn install_image(path: &Path, flags: u32) -> Result<()> { if !path.exists() || path.file_name().is_none() { bail!("file path {} does not exist", path.display()); } @@ -140,7 +140,7 @@ fn prepare_image(image: &ResourceImage, flags: u32) -> Result<()> { } fn install_extra_image(image: &ResourceImage) -> Result<()> { - let filename = format!("citadel-extra-{:03}.img", image.header().metainfo().version()); + let filename = format!("citadel-extra-{}.img", image.header().metainfo().version()); install_image_file(image, filename.as_str())?; remove_old_extra_images(image)?; Ok(()) @@ -186,7 +186,7 @@ fn install_kernel_image(image: &mut ResourceImage) -> Result<()> { info!("kernel version is {}", kernel_version); install_kernel_file(image, &kernel_version)?; - let filename = format!("citadel-kernel-{}-{:03}.img", kernel_version, version); + let filename = format!("citadel-kernel-{}-{}.img", kernel_version, version); install_image_file(image, &filename)?; let all_versions = all_boot_kernel_versions()?; diff --git a/libcitadel/Cargo.toml b/libcitadel/Cargo.toml index 7242b35..898ab6a 100644 --- a/libcitadel/Cargo.toml +++ b/libcitadel/Cargo.toml @@ -20,6 +20,7 @@ walkdir = "2" dbus = "0.6" posix-acl = "1.0.0" procfs = "0.12.0" +semver = "1.0" [dependencies.inotify] version = "0.8" diff --git a/libcitadel/src/header.rs b/libcitadel/src/header.rs index fc31e3d..4cb6661 100644 --- a/libcitadel/src/header.rs +++ b/libcitadel/src/header.rs @@ -453,7 +453,7 @@ pub struct MetaInfo { realmfs_owner: Option, #[serde(default)] - version: u32, + version: String, #[serde(default)] timestamp: String, @@ -508,8 +508,8 @@ impl MetaInfo { Self::str_ref(&self.realmfs_owner) } - pub fn version(&self) -> u32 { - self.version + pub fn version(&self) -> &str { + &self.version } pub fn timestamp(&self) -> &str { diff --git a/libcitadel/src/resource.rs b/libcitadel/src/resource.rs index 826d530..452f465 100644 --- a/libcitadel/src/resource.rs +++ b/libcitadel/src/resource.rs @@ -420,8 +420,11 @@ fn compare_images(a: Option, b: ResourceImage) -> Result return Ok(b), }; - let ver_a = a.metainfo().version(); - let ver_b = b.metainfo().version(); + let bind_a = a.metainfo(); + let bind_b = b.metainfo(); + + let ver_a = bind_a.version(); + let ver_b = bind_b.version(); if ver_a > ver_b { Ok(a) diff --git a/libcitadel/src/util.rs b/libcitadel/src/util.rs index 7f11aeb..82b2a06 100644 --- a/libcitadel/src/util.rs +++ b/libcitadel/src/util.rs @@ -48,6 +48,12 @@ fn search_path(filename: &str) -> Result { bail!("could not find {} in $PATH", filename) } +pub fn append_to_path(p: &Path, s: &str) -> PathBuf { + let mut p_osstr = p.as_os_str().to_owned(); + p_osstr.push(s); + p_osstr.into() +} + pub fn ensure_command_exists(cmd: &str) -> Result<()> { let path = Path::new(cmd); if !path.is_absolute() { @@ -338,7 +344,6 @@ pub fn is_euid_root() -> bool { } } - fn utimes(path: &Path, atime: i64, mtime: i64) -> Result<()> { let cstr = CString::new(path.as_os_str().as_bytes()) .expect("path contains null byte");