Skip to content

Commit

Permalink
coreos: let aleph file be a symlink
Browse files Browse the repository at this point in the history
Once osbuild/osbuild#1475 gets picked up and
starts getting used the .coreos-aleph-version.json will be a symlink.
Let's canonicalize and find the actual file before dropping into
sysroot.open_file_optional() because the underlying code for that uses
O_NOFOLLOW and will give an ELOOP (too many symbolic links) error.
  • Loading branch information
dustymabe committed Dec 16, 2023
1 parent 8c610f5 commit c87a979
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/coreos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -30,7 +31,18 @@ const ALEPH_PATH: &str = "/sysroot/.coreos-aleph-version.json";

pub(crate) fn get_aleph_version() -> Result<Option<AlephWithTimestamp>> {
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)?;
Expand Down

0 comments on commit c87a979

Please sign in to comment.