Skip to content

Commit 39fbede

Browse files
committed
fix(os-detection):identfy rpm-ostree or bootc
Use booted.image to detect between rpm-ostree or bootc if its null then use rpm-ostree verb else bootc. Signed-off-by: Sayan Paul <paul.sayan@gmail.com>
1 parent 33b27dc commit 39fbede

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

src/lib/handler.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22

33
use anyhow::{Context, Result, anyhow, bail};
44
use serde_json::Value;
5+
use std::path::Path;
56
use std::process::Command;
67
use std::str;
78

89
use crate::grub::get_boot_counter;
910

10-
/// Detects if the system is managed by bootc or is a rpm-ostree system
11-
/// Inspect bootc status JSON and decide based on `status.booted.incompatible`.
11+
/// Detects if the system is managed by bootc or is a rpm-ostree system.
12+
/// First checks for `/run/ostree-booted`, then inspects `status.booted.image`
13+
/// from `bootc status --booted --json` to distinguish between the two.
1214
pub fn detect_os_deployment() -> Option<&'static str> {
15+
if !Path::new("/run/ostree-booted").exists() {
16+
log::info!("'/run/ostree-booted' not found, not an ostree-based system");
17+
return None;
18+
}
19+
1320
let output = match Command::new("bootc")
1421
.args(["status", "--booted", "--json"])
1522
.output()
@@ -34,19 +41,18 @@ pub fn detect_os_deployment() -> Option<&'static str> {
3441
match json
3542
.get("status")
3643
.and_then(|s| s.get("booted"))
37-
.and_then(|b| b.get("incompatible"))
38-
.and_then(|i| i.as_bool())
44+
.and_then(|b| b.get("image"))
3945
{
40-
Some(true) => {
41-
log::info!("System detected as rpm-ostree (incompatible=true)");
46+
Some(image) if image.is_null() => {
47+
log::info!("System detected as rpm-ostree (status.booted.image is null)");
4248
Some("rpm-ostree")
4349
}
44-
Some(false) => {
45-
log::info!("System detected as bootc (incompatible=false)");
50+
Some(_) => {
51+
log::info!("System detected as bootc (status.booted.image is present)");
4652
Some("bootc")
4753
}
4854
None => {
49-
log::error!("bootc status JSON missing boolean field status.booted.incompatible");
55+
log::error!("bootc status JSON missing field status.booted.image");
5056
None
5157
}
5258
}

0 commit comments

Comments
 (0)