Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve System::long_os_version() on Linux and Android #1427

Merged
merged 4 commits into from
Dec 14, 2024

Conversation

dtolnay
Copy link
Contributor

@dtolnay dtolnay commented Dec 13, 2024

Closes #1420. Closes #1419.

Comment on lines 402 to 404
long_name.push_str(" (");
long_name.push_str(&distro_or_version);
long_name.push(')');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part might be weird — I am not sure what circumstances would lead to System::name() being Some and System::os_version() being None, or vice versa. The former wouldn't be an issue: "Linux (Ubuntu)" is perfectly fine. The latter is worse: "Linux (24.04)".

I considered leaving out os_version() if name() is None, but then we have a situation that the value of long_os_version() specifically does not include the os_version().

Copy link
Owner

@GuillaumeGomez GuillaumeGomez Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding "unknown" in case the OS name is not known would likely improve the situation? If the version is unknown then just "Linux (Ubuntu)" sounds fine I think.

So with the three cases it gives:

Linux (Ubuntu 24.04)
Linux (unknown 24.04)
Linux (Ubuntu)

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good call. I like that.

Speaking of "unknown", I forgot about checking for "unknown" in the Android case which is something I mentioned in #1419 (comment). Because getString in Build.java can return "unknown":

But looking at this more, I think "unknown" is specific to the Java API. They have public static final String MODEL where they have chosen to use the string "unknown" instead of null when a particular property hasn't been set. Whereas in Rust, we deal with libc::__system_property_get returning 0 by turning it into None (System::name() returns Option<String> not String). So I think we do not need to check for "unknown" after all.

if let Some(short_name) = Self::name() {
long_name.push(' ');
long_name.push_str(&short_name);
// Android's name() is extracted from the system property "ro.product.model"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the extra comment, always very appreciated! :)

@GuillaumeGomez
Copy link
Owner

Looks all good to me, thanks! Gonna merge it tomorrow once CI is done and brain has successfully rebooted. 😉

@GuillaumeGomez
Copy link
Owner

Thanks again!

@GuillaumeGomez GuillaumeGomez merged commit b290678 into GuillaumeGomez:master Dec 14, 2024
67 checks passed
@dtolnay dtolnay deleted the longosversion branch December 14, 2024 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linux long_os_version Android long_os_version
2 participants