Skip to content

Commit

Permalink
Improve System::long_os_version() on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 13, 2024
1 parent 8c8874b commit d1e0c22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/common/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ impl System {
///
/// | example platform | value of `System::long_os_version()` |
/// |---|---|
/// | linux laptop | "Linux 24.04 Ubuntu" |
/// | linux laptop | "Linux (Ubuntu 24.04)" |
/// | android phone | "Android 15 on Pixel 9 Pro" |
/// | apple laptop | "macOS 15.1.1 Sequoia" |
/// | windows server | "Windows Server 2022 Datacenter" |
Expand Down
19 changes: 12 additions & 7 deletions src/unix/linux/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,19 @@ impl SystemInner {
pub(crate) fn long_os_version() -> Option<String> {
let mut long_name = "Linux".to_owned();

if let Some(os_version) = Self::os_version() {
long_name.push(' ');
long_name.push_str(&os_version);
}

if let Some(short_name) = Self::name() {
let distro_name = Self::name();
let distro_version = Self::os_version();
if let (Some(distro_name), Some(distro_version)) = (&distro_name, &distro_version) {
// "Linux (Ubuntu 24.04)"
long_name.push_str(" (");
long_name.push_str(distro_name);
long_name.push(' ');
long_name.push_str(&short_name);
long_name.push_str(distro_version);
long_name.push(')');
} else if let Some(distro_or_version) = distro_name.or(distro_version) {
long_name.push_str(" (");
long_name.push_str(&distro_or_version);
long_name.push(')');
}

Some(long_name)
Expand Down

0 comments on commit d1e0c22

Please sign in to comment.