From dc3a7435771ab4f14a25629d420e7c5dd1d690bc Mon Sep 17 00:00:00 2001 From: wugeer <1284057728@qq.com> Date: Fri, 25 Oct 2024 14:08:17 +0800 Subject: [PATCH] feat:add support for CachyOS Linux --- cspell-dictionary.txt | 1 + os_info/src/info.rs | 1 + os_info/src/linux/file_release.rs | 12 ++++++++++++ os_info/src/linux/lsb_release.rs | 16 ++++++++++++++++ os_info/src/linux/mod.rs | 1 + os_info/src/linux/tests/CachyOS/etc/os-release | 13 +++++++++++++ os_info/src/os_type.rs | 4 ++++ 7 files changed, 48 insertions(+) create mode 100644 os_info/src/linux/tests/CachyOS/etc/os-release diff --git a/cspell-dictionary.txt b/cspell-dictionary.txt index da86a66..34d8da3 100644 --- a/cspell-dictionary.txt +++ b/cspell-dictionary.txt @@ -6,6 +6,7 @@ aosc archarm artix bitness +cachyos centos clippy clearos diff --git a/os_info/src/info.rs b/os_info/src/info.rs index 1139888..5dcad29 100644 --- a/os_info/src/info.rs +++ b/os_info/src/info.rs @@ -216,6 +216,7 @@ mod tests { Type::Android, Type::Arch, Type::Artix, + Type::CachyOS, Type::CentOS, Type::Debian, Type::Emscripten, diff --git a/os_info/src/linux/file_release.rs b/os_info/src/linux/file_release.rs index da16b42..421def1 100644 --- a/os_info/src/linux/file_release.rs +++ b/os_info/src/linux/file_release.rs @@ -99,6 +99,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ "arch" => Some(Type::Arch), "archarm" => Some(Type::Arch), "artix" => Some(Type::Artix), + "cachyos" => Some(Type::CachyOS), "centos" => Some(Type::CentOS), //"clear-linux-os" => ClearLinuxOS //"clearos" => ClearOS @@ -659,6 +660,17 @@ mod tests { assert_eq!(info.codename, None); } + #[test] + fn cachy_os_release() { + let root = "src/linux/tests/CachyOS"; + + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::CachyOS); + 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 cfe1242..232ea22 100644 --- a/os_info/src/linux/lsb_release.rs +++ b/os_info/src/linux/lsb_release.rs @@ -20,6 +20,7 @@ pub fn get() -> Option { Some("Amazon") | Some("AmazonAMI") => Type::Amazon, Some("Arch") => Type::Arch, Some("Artix") => Type::Artix, + Some("cachyos") => Type::CachyOS, Some("CentOS") => Type::CentOS, Some("Debian") => Type::Debian, Some("EndeavourOS") => Type::EndeavourOS, @@ -357,6 +358,13 @@ mod tests { assert_eq!(parse_results.codename, None); } + #[test] + fn cachyos() { + let parse_results = parse(&cachyos_file()); + assert_eq!(parse_results.distribution, Some("cachyos".to_string())); + assert_eq!(parse_results.version, Some("rolling".to_string())); + } + fn file() -> &'static str { "\nDistributor ID: Debian\n\ Description: Debian GNU/Linux 7.8 (wheezy)\n\ @@ -606,4 +614,12 @@ mod tests { Codename: n/a\n\ " } + + fn cachyos_file() -> &'static str { + "Distributor ID: cachyos\n\ + Description: CachyOS\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 10461fb..bccee71 100644 --- a/os_info/src/linux/mod.rs +++ b/os_info/src/linux/mod.rs @@ -32,6 +32,7 @@ mod tests { | Type::Amazon | Type::Arch | Type::Artix + | Type::CachyOS | Type::CentOS | Type::Debian | Type::EndeavourOS diff --git a/os_info/src/linux/tests/CachyOS/etc/os-release b/os_info/src/linux/tests/CachyOS/etc/os-release new file mode 100644 index 0000000..0b9cc20 --- /dev/null +++ b/os_info/src/linux/tests/CachyOS/etc/os-release @@ -0,0 +1,13 @@ +NAME="CachyOS Linux" +PRETTY_NAME="CachyOS" +ID=cachyos +ID_LIKE=arch +BUILD_ID=rolling +ANSI_COLOR="38;2;23;147;209" +HOME_URL="https://cachyos.org/" +DOCUMENTATION_URL="https://wiki.cachyos.org/" +SUPPORT_URL="https://forum.cachyos.org/" +BUG_REPORT_URL="https://github.com/cachyos" +LOGO=cachyos +IMAGE_ID=cachyos +IMAGE_VERSION=2023.04.23 diff --git a/os_info/src/os_type.rs b/os_info/src/os_type.rs index 431c2fa..2b89622 100644 --- a/os_info/src/os_type.rs +++ b/os_info/src/os_type.rs @@ -22,6 +22,8 @@ pub enum Type { Arch, /// Artix Linux (). Artix, + /// CachyOS (). + CachyOS, /// CentOS (). CentOS, /// Debian (). @@ -120,6 +122,7 @@ impl Display for Type { Type::AlmaLinux => write!(f, "AlmaLinux"), Type::Amazon => write!(f, "Amazon Linux AMI"), Type::Arch => write!(f, "Arch Linux"), + Type::CachyOS => write!(f, "CachyOS Linux"), Type::Artix => write!(f, "Artix Linux"), Type::DragonFly => write!(f, "DragonFly BSD"), Type::Garuda => write!(f, "Garuda Linux"), @@ -166,6 +169,7 @@ mod tests { (Type::Android, "Android"), (Type::Arch, "Arch Linux"), (Type::Artix, "Artix Linux"), + (Type::CachyOS, "CachyOS Linux"), (Type::CentOS, "CentOS"), (Type::Debian, "Debian"), (Type::DragonFly, "DragonFly BSD"),