Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions src/aleph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::path::Path;
/// See https://github.com/coreos/fedora-coreos-tracker/blob/66d7d00bedd9d5eabc7287b9577f443dcefb7c04/internals/README-internals.md#aleph-version
pub(crate) struct Aleph {
#[serde(alias = "build")]
pub(crate) version: String,
pub(crate) version: Option<String>,
}

pub(crate) struct AlephWithTimestamp {
Expand Down Expand Up @@ -91,7 +91,7 @@ mod test {
std::fs::create_dir(sysroot).context("Creating sysroot")?;
std::fs::write(root.join(ALEPH_PATHS[0]), V1_ALEPH_DATA).context("Writing aleph")?;
let aleph = get_aleph_version(root).unwrap().unwrap();
assert_eq!(aleph.aleph.version, "32.20201002.dev.2");
assert_eq!(aleph.aleph.version, Some("32.20201002.dev.2".into()));
Ok(())
}

Expand All @@ -105,7 +105,7 @@ mod test {
std::fs::create_dir(sysroot).context("Creating sysroot")?;
std::fs::write(root.join(ALEPH_PATHS[1]), V1_ALEPH_DATA).context("Writing aleph")?;
let aleph = get_aleph_version(root).unwrap().unwrap();
assert_eq!(aleph.aleph.version, "32.20201002.dev.2");
assert_eq!(aleph.aleph.version, Some("32.20201002.dev.2".into()));
Ok(())
}

Expand All @@ -123,7 +123,7 @@ mod test {
std::fs::write(root.join(ALEPH_PATHS[0]), coreos_data).context("Writing coreos aleph")?;
std::fs::write(root.join(ALEPH_PATHS[1]), bootc_data).context("Writing bootc aleph")?;
let aleph = get_aleph_version(root).unwrap().unwrap();
assert_eq!(aleph.aleph.version, "coreos-version");
assert_eq!(aleph.aleph.version, Some("coreos-version".into()));
Ok(())
}

Expand All @@ -140,7 +140,7 @@ mod test {
std::fs::write(root.join(target), V1_ALEPH_DATA).context("Writing aleph")?;
std::os::unix::fs::symlink(target_name, root.join(ALEPH_PATHS[0])).context("Symlinking")?;
let aleph = get_aleph_version(root).unwrap().unwrap();
assert_eq!(aleph.aleph.version, "32.20201002.dev.2");
assert_eq!(aleph.aleph.version, Some("32.20201002.dev.2".into()));
Ok(())
}

Expand All @@ -156,14 +156,14 @@ mod test {
"imgid": "fedora-coreos-32.20201002.dev.2-qemu.x86_64.qcow2"
}"##;
let aleph: Aleph = serde_json::from_str(alephdata)?;
assert_eq!(aleph.version, "32.20201002.dev.2");
assert_eq!(aleph.version, Some("32.20201002.dev.2".into()));
Ok(())
}

#[test]
fn test_parse_aleph() -> Result<()> {
let aleph: Aleph = serde_json::from_str(V1_ALEPH_DATA)?;
assert_eq!(aleph.version, "32.20201002.dev.2");
assert_eq!(aleph.version, Some("32.20201002.dev.2".into()));
Ok(())
}

Expand Down Expand Up @@ -196,7 +196,36 @@ mod test {
"version": "43.20260301.20.dev1"
}"##;
let aleph: Aleph = serde_json::from_str(alephdata)?;
assert_eq!(aleph.version, "43.20260301.20.dev1");
assert_eq!(aleph.version, Some("43.20260301.20.dev1".into()));
Ok(())
}

#[test]
fn test_parse_null_version_aleph() -> Result<()> {
let alephdata = r##"
{
"version": null,
"ref": "fedora/x86_64/coreos/testing-devel",
"ostree-commit": "b2ea6159d6274e1bbbb49aa0ef093eda5d53a75c8a793dbe184f760ed64dc862",
"timestamp": null
}"##;

let aleph: Aleph = serde_json::from_str(alephdata)?;
assert_eq!(aleph.version, None);
Ok(())
}

#[test]
fn test_parse_no_version_aleph() -> Result<()> {
let alephdata = r##"
{
"ref": "fedora/x86_64/coreos/testing-devel",
"ostree-commit": "b2ea6159d6274e1bbbb49aa0ef093eda5d53a75c8a793dbe184f760ed64dc862",
"timestamp": null
}"##;

let aleph: Aleph = serde_json::from_str(alephdata)?;
assert_eq!(aleph.version, None);
Ok(())
}
}
2 changes: 1 addition & 1 deletion src/bootupd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ pub(crate) fn status() -> Result<Status> {
let root = Dir::open_ambient_dir("/", ambient_authority())?;

// Populate aleph version
ret.aleph_version = aleph::get_aleph_version(Path::new("/"))?.map(|a| a.aleph.version);
ret.aleph_version = aleph::get_aleph_version(Path::new("/"))?.and_then(|a| a.aleph.version);

// Populate boot method
#[cfg(any(
Expand Down
2 changes: 1 addition & 1 deletion src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub(crate) fn query_adopt_state() -> Result<Option<Adoptable>> {
if let Some(aleph) = crate::aleph::get_aleph_version(Path::new("/"))? {
let meta = ContentMetadata {
timestamp: aleph.ts,
version: aleph.aleph.version,
version: aleph.aleph.version.unwrap_or_else(|| "unknown".into()),
versions: None,
#[cfg(efi_arch)]
default_bootloader: None,
Expand Down
Loading