diff --git a/src/coreos.rs b/src/coreos.rs index 46dd8727..bf600f43 100644 --- a/src/coreos.rs +++ b/src/coreos.rs @@ -6,10 +6,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -use anyhow::Result; +use anyhow::{Context, Result}; use chrono::prelude::*; use openat_ext::OpenatDirExt; use serde::{Deserialize, Serialize}; +use std::fs::{canonicalize, symlink_metadata}; #[derive(Serialize, Deserialize, Clone, Debug, Hash, Ord, PartialOrd, PartialEq, Eq)] #[serde(rename_all = "kebab-case")] @@ -30,7 +31,18 @@ const ALEPH_PATH: &str = "/sysroot/.coreos-aleph-version.json"; pub(crate) fn get_aleph_version() -> Result> { let sysroot = openat::Dir::open("/")?; - if let Some(statusf) = sysroot.open_file_optional(ALEPH_PATH)? { + let mut path = ALEPH_PATH; + let target; + let is_link = symlink_metadata(path) + .with_context(|| format!("reading metadata for {}", path))? + .file_type() + .is_symlink(); + if is_link { + target = + canonicalize(path).with_context(|| format!("getting absolute path to {}", path))?; + path = target.to_str().unwrap() + } + if let Some(statusf) = sysroot.open_file_optional(path)? { let meta = statusf.metadata()?; let bufr = std::io::BufReader::new(statusf); let aleph: Aleph = serde_json::from_reader(bufr)?;