Add fallback to /usr/lib/os-release on Linux (#18349)

This commit is contained in:
Zanie Blue
2026-03-06 10:50:54 -06:00
committed by GitHub
parent 7520fe6c25
commit 24e9b47900
+7 -7
View File
@@ -106,18 +106,18 @@ pub struct LinuxOsRelease {
}
impl LinuxOsRelease {
/// Reads and parses `/etc/os-release` on Linux.
/// Reads and parses `/etc/os-release` on Linux, falling back to `/usr/lib/os-release`.
///
/// See <https://www.freedesktop.org/software/systemd/man/latest/os-release.html>.
///
/// Returns `None` on non-Linux platforms or if the file cannot be read.
pub fn from_env() -> Option<Self> {
#[cfg(target_os = "linux")]
{
Some(
fs_err::read_to_string("/etc/os-release")
.ok()?
.parse()
.unwrap(),
)
let content = fs_err::read_to_string("/etc/os-release")
.or_else(|_| fs_err::read_to_string("/usr/lib/os-release"))
.ok()?;
Some(content.parse().unwrap())
}
#[cfg(not(target_os = "linux"))]
{