From 756e4aa9fd1ef9eb5543d8cfb82a4b60953b2cdd Mon Sep 17 00:00:00 2001 From: Mystical-C <64483945+MysticalDevil@users.noreply.github.com> Date: Mon, 4 Mar 2024 14:42:17 +0800 Subject: [PATCH] Add support for VoidLinux --- cspell-dictionary.txt | 3 ++- os_info/src/info.rs | 1 + os_info/src/linux/file_release.rs | 13 ++++++++++++- os_info/src/linux/lsb_release.rs | 17 +++++++++++++++++ os_info/src/linux/mod.rs | 1 + os_info/src/linux/tests/Void/etc/os-release | 8 ++++++++ os_info/src/os_type.rs | 4 ++++ 7 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 os_info/src/linux/tests/Void/etc/os-release diff --git a/cspell-dictionary.txt b/cspell-dictionary.txt index 4cc5de9..764deed 100644 --- a/cspell-dictionary.txt +++ b/cspell-dictionary.txt @@ -53,4 +53,5 @@ xenenterprise xenial xenserver ultramarine -kuma \ No newline at end of file +voidlinux +kuma diff --git a/os_info/src/info.rs b/os_info/src/info.rs index 5242836..73ef998 100644 --- a/os_info/src/info.rs +++ b/os_info/src/info.rs @@ -239,6 +239,7 @@ mod tests { Type::SUSE, Type::Ubuntu, Type::Ultramarine, + Type::Void, Type::Mint, Type::Unknown, Type::Windows, diff --git a/os_info/src/linux/file_release.rs b/os_info/src/linux/file_release.rs index bf6c982..54b3603 100644 --- a/os_info/src/linux/file_release.rs +++ b/os_info/src/linux/file_release.rs @@ -136,7 +136,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ "ubuntu" => Some(Type::Ubuntu), "ultramarine" => Some(Type::Ultramarine), //"virtuozzo" => Virtuozzo - //"void" => Void + "void" => Some(Type::Void), //"XCP-ng" => xcp-ng //"xenenterprise" => xcp-ng //"xenserver" => xcp-ng @@ -623,6 +623,17 @@ mod tests { assert_eq!(info.codename, None); } + #[test] + fn void_os_release() { + let root = "src/linux/tests/Void"; + + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::Void); + assert_eq!(info.version, Version::Unknown); + assert_eq!(info.edition, None); + assert_eq!(info.codename, None); + } + #[test] fn release_info_debug() { dbg!("{:?}", &DISTRIBUTIONS[0]); diff --git a/os_info/src/linux/lsb_release.rs b/os_info/src/linux/lsb_release.rs index 113d60f..a6fdafb 100644 --- a/os_info/src/linux/lsb_release.rs +++ b/os_info/src/linux/lsb_release.rs @@ -43,6 +43,7 @@ pub fn get() -> Option { Some("SUSE") => Type::SUSE, Some("Ubuntu") => Type::Ubuntu, Some("UltramarineLinux") => Type::Ultramarine, + Some("VoidLinux") => Type::Void, _ => Type::Linux, }; @@ -322,6 +323,13 @@ mod tests { assert_eq!(parse_results.codename, Some("kuma".to_string())); } + #[test] + fn void_linux() { + let parse_results = parse(void_file()); + assert_eq!(parse_results.distribution, Some("Void".to_string())); + assert_eq!(parse_results.version, Some("rolling".to_string())); + } + #[test] fn raspbian() { let parse_results = parse(raspberry_os_file()); @@ -553,4 +561,13 @@ mod tests { Codename: kuma\n\ " } + + fn void_file() -> &'static str { + "LSB Version: n/a\n\ + Distributor ID: Void\n\ + Description: Void Linux\n\ + Release: rolling\n\ + Codename: n/a\n\ + " + } } diff --git a/os_info/src/linux/mod.rs b/os_info/src/linux/mod.rs index 2fab351..5fc0ca1 100644 --- a/os_info/src/linux/mod.rs +++ b/os_info/src/linux/mod.rs @@ -57,6 +57,7 @@ mod tests { | Type::SUSE | Type::Ubuntu | Type::Ultramarine + | Type::Void | Type::Mint => (), os_type => { panic!("Unexpected OS type: {}", os_type); diff --git a/os_info/src/linux/tests/Void/etc/os-release b/os_info/src/linux/tests/Void/etc/os-release new file mode 100644 index 0000000..12f5de4 --- /dev/null +++ b/os_info/src/linux/tests/Void/etc/os-release @@ -0,0 +1,8 @@ +NAME="Void" +ID="void" +PRETTY_NAME="Void Linux" +HOME_URL="https://voidlinux.org/" +DOCUMENTATION_URL="https://docs.voidlinux.org/" +LOGO="void-logo" +ANSI_COLOR="0;38;2;71;128;97" +DISTRIB_ID="void" diff --git a/os_info/src/os_type.rs b/os_info/src/os_type.rs index b7330ad..fecfc93 100644 --- a/os_info/src/os_type.rs +++ b/os_info/src/os_type.rs @@ -94,6 +94,8 @@ pub enum Type { Ubuntu, /// Ultramarine (). Ultramarine, + /// Void Linux (). + Void, /// Unknown operating system. Unknown, /// Windows (). @@ -130,6 +132,7 @@ impl Display for Type { Type::RockyLinux => write!(f, "Rocky Linux"), Type::SUSE => write!(f, "SUSE Linux Enterprise Server"), Type::Ultramarine => write!(f, "Ultramarine Linux"), + Type::Void => write!(f, "Void Linux"), _ => write!(f, "{self:?}"), } } @@ -182,6 +185,7 @@ mod tests { (Type::SUSE, "SUSE Linux Enterprise Server"), (Type::Ubuntu, "Ubuntu"), (Type::Ultramarine, "Ultramarine Linux"), + (Type::Void, "Void Linux"), (Type::Unknown, "Unknown"), (Type::Windows, "Windows"), ];