forked from brl/citadel-tools
Convert citadel image version numbers to semver
This commit is contained in:
parent
24f786cf75
commit
3d390e557f
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -1212,6 +1212,7 @@ dependencies = [
|
|||||||
"nix 0.17.0",
|
"nix 0.17.0",
|
||||||
"posix-acl",
|
"posix-acl",
|
||||||
"procfs",
|
"procfs",
|
||||||
|
"semver 1.0.23",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -1773,7 +1774,7 @@ version = "0.3.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee"
|
checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"semver",
|
"semver 0.11.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1800,6 +1801,12 @@ dependencies = [
|
|||||||
"semver-parser",
|
"semver-parser",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "1.0.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver-parser"
|
name = "semver-parser"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
|
@ -136,8 +136,11 @@ fn compare_boot_partitions(a: Option<Partition>, b: Partition) -> Option<Partiti
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compare versions and channels
|
// Compare versions and channels
|
||||||
let a_v = a.metainfo().version();
|
let bind_a = a.metainfo();
|
||||||
let b_v = b.metainfo().version();
|
let bind_b = b.metainfo();
|
||||||
|
|
||||||
|
let a_v = bind_a.version();
|
||||||
|
let b_v = bind_b.version();
|
||||||
|
|
||||||
// Compare versions only if channels match
|
// Compare versions only if channels match
|
||||||
if a.metainfo().channel() == b.metainfo().channel() {
|
if a.metainfo().channel() == b.metainfo().channel() {
|
||||||
|
@ -250,9 +250,9 @@ fn install_image(arg_matches: &ArgMatches) -> Result<()> {
|
|||||||
if kernel_version.chars().any(|c| c == '/') {
|
if kernel_version.chars().any(|c| c == '/') {
|
||||||
bail!("Kernel version field has / char");
|
bail!("Kernel version field has / char");
|
||||||
}
|
}
|
||||||
format!("citadel-kernel-{}-{:03}.img", kernel_version, metainfo.version())
|
format!("citadel-kernel-{}-{}.img", kernel_version, metainfo.version())
|
||||||
} else {
|
} else {
|
||||||
format!("citadel-extra-{:03}.img", metainfo.version())
|
format!("citadel-extra-{}.img", metainfo.version())
|
||||||
};
|
};
|
||||||
|
|
||||||
if !metainfo.channel().chars().all(|c| c.is_ascii_lowercase()) {
|
if !metainfo.channel().chars().all(|c| c.is_ascii_lowercase()) {
|
||||||
|
@ -38,15 +38,15 @@ impl UpdateBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn target_filename(&self) -> String {
|
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 {
|
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 {
|
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<()> {
|
pub fn build(&mut self) -> Result<()> {
|
||||||
@ -154,7 +154,7 @@ impl UpdateBuilder {
|
|||||||
bail!("failed to compress {:?}: {}", self.image(), err);
|
bail!("failed to compress {:?}: {}", self.image(), err);
|
||||||
}
|
}
|
||||||
// Rename back to original image_data filename
|
// 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -217,7 +217,7 @@ impl UpdateBuilder {
|
|||||||
writeln!(v, "realmfs-name = \"{}\"", name)?;
|
writeln!(v, "realmfs-name = \"{}\"", name)?;
|
||||||
}
|
}
|
||||||
writeln!(v, "channel = \"{}\"", self.config.channel())?;
|
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, "timestamp = \"{}\"", self.config.timestamp())?;
|
||||||
writeln!(v, "nblocks = {}", self.nblocks.unwrap())?;
|
writeln!(v, "nblocks = {}", self.nblocks.unwrap())?;
|
||||||
writeln!(v, "shasum = \"{}\"", self.shasum.as_ref().unwrap())?;
|
writeln!(v, "shasum = \"{}\"", self.shasum.as_ref().unwrap())?;
|
||||||
|
@ -9,7 +9,7 @@ pub struct BuildConfig {
|
|||||||
#[serde(rename = "image-type")]
|
#[serde(rename = "image-type")]
|
||||||
image_type: String,
|
image_type: String,
|
||||||
channel: String,
|
channel: String,
|
||||||
version: usize,
|
version: String,
|
||||||
timestamp: String,
|
timestamp: String,
|
||||||
source: String,
|
source: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@ -102,8 +102,8 @@ impl BuildConfig {
|
|||||||
self.realmfs_name.as_ref().map(|s| s.as_str())
|
self.realmfs_name.as_ref().map(|s| s.as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn version(&self) -> usize {
|
pub fn version(&self) -> &str {
|
||||||
self.version
|
&self.version
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn channel(&self) -> &str {
|
pub fn channel(&self) -> &str {
|
||||||
|
@ -93,7 +93,7 @@ fn create_tmp_copy(path: &Path) -> Result<PathBuf> {
|
|||||||
Ok(path)
|
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() {
|
if !path.exists() || path.file_name().is_none() {
|
||||||
bail!("file path {} does not exist", path.display());
|
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<()> {
|
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())?;
|
install_image_file(image, filename.as_str())?;
|
||||||
remove_old_extra_images(image)?;
|
remove_old_extra_images(image)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -186,7 +186,7 @@ fn install_kernel_image(image: &mut ResourceImage) -> Result<()> {
|
|||||||
info!("kernel version is {}", kernel_version);
|
info!("kernel version is {}", kernel_version);
|
||||||
install_kernel_file(image, &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)?;
|
install_image_file(image, &filename)?;
|
||||||
|
|
||||||
let all_versions = all_boot_kernel_versions()?;
|
let all_versions = all_boot_kernel_versions()?;
|
||||||
|
@ -20,6 +20,7 @@ walkdir = "2"
|
|||||||
dbus = "0.6"
|
dbus = "0.6"
|
||||||
posix-acl = "1.0.0"
|
posix-acl = "1.0.0"
|
||||||
procfs = "0.12.0"
|
procfs = "0.12.0"
|
||||||
|
semver = "1.0"
|
||||||
|
|
||||||
[dependencies.inotify]
|
[dependencies.inotify]
|
||||||
version = "0.8"
|
version = "0.8"
|
||||||
|
@ -453,7 +453,7 @@ pub struct MetaInfo {
|
|||||||
realmfs_owner: Option<String>,
|
realmfs_owner: Option<String>,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
version: u32,
|
version: String,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
timestamp: String,
|
timestamp: String,
|
||||||
@ -508,8 +508,8 @@ impl MetaInfo {
|
|||||||
Self::str_ref(&self.realmfs_owner)
|
Self::str_ref(&self.realmfs_owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn version(&self) -> u32 {
|
pub fn version(&self) -> &str {
|
||||||
self.version
|
&self.version
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn timestamp(&self) -> &str {
|
pub fn timestamp(&self) -> &str {
|
||||||
|
@ -420,8 +420,11 @@ fn compare_images(a: Option<ResourceImage>, b: ResourceImage) -> Result<Resource
|
|||||||
None => return Ok(b),
|
None => return Ok(b),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ver_a = a.metainfo().version();
|
let bind_a = a.metainfo();
|
||||||
let ver_b = b.metainfo().version();
|
let bind_b = b.metainfo();
|
||||||
|
|
||||||
|
let ver_a = bind_a.version();
|
||||||
|
let ver_b = bind_b.version();
|
||||||
|
|
||||||
if ver_a > ver_b {
|
if ver_a > ver_b {
|
||||||
Ok(a)
|
Ok(a)
|
||||||
|
@ -48,6 +48,12 @@ fn search_path(filename: &str) -> Result<PathBuf> {
|
|||||||
bail!("could not find {} in $PATH", filename)
|
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<()> {
|
pub fn ensure_command_exists(cmd: &str) -> Result<()> {
|
||||||
let path = Path::new(cmd);
|
let path = Path::new(cmd);
|
||||||
if !path.is_absolute() {
|
if !path.is_absolute() {
|
||||||
@ -338,7 +344,6 @@ pub fn is_euid_root() -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn utimes(path: &Path, atime: i64, mtime: i64) -> Result<()> {
|
fn utimes(path: &Path, atime: i64, mtime: i64) -> Result<()> {
|
||||||
let cstr = CString::new(path.as_os_str().as_bytes())
|
let cstr = CString::new(path.as_os_str().as_bytes())
|
||||||
.expect("path contains null byte");
|
.expect("path contains null byte");
|
||||||
|
Loading…
Reference in New Issue
Block a user