From a00ee73796cbfb4d880213f332af7e437f0404a1 Mon Sep 17 00:00:00 2001 From: wangmengc Date: Wed, 17 Apr 2024 15:36:28 +0800 Subject: [PATCH] add support for Uos 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 | 20 ++++++++++++++++++++ os_info/src/linux/mod.rs | 1 + os_info/src/linux/tests/Uos/etc/os-release | 8 ++++++++ os_info/src/os_type.rs | 4 ++++ 7 files changed, 47 insertions(+) create mode 100644 os_info/src/linux/tests/Uos/etc/os-release diff --git a/cspell-dictionary.txt b/cspell-dictionary.txt index bc560bd..da86a66 100644 --- a/cspell-dictionary.txt +++ b/cspell-dictionary.txt @@ -34,6 +34,7 @@ musl netbsd nixos nobara +uos openbsd opencloudos openeuler diff --git a/os_info/src/info.rs b/os_info/src/info.rs index 93487bf..1139888 100644 --- a/os_info/src/info.rs +++ b/os_info/src/info.rs @@ -228,6 +228,7 @@ mod tests { Type::Mariner, Type::NixOS, Type::Nobara, + Type::Uos, Type::OpenCloudOS, Type::openEuler, Type::openSUSE, diff --git a/os_info/src/linux/file_release.rs b/os_info/src/linux/file_release.rs index 497596e..da16b42 100644 --- a/os_info/src/linux/file_release.rs +++ b/os_info/src/linux/file_release.rs @@ -118,6 +118,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ //"nexus" => Nexus "nixos" => Some(Type::NixOS), "nobara" => Some(Type::Nobara), + "Uos" => Some(Type::Uos), "opencloudos" => Some(Type::OpenCloudOS), "openEuler" => Some(Type::openEuler), "ol" => Some(Type::OracleLinux), @@ -469,6 +470,17 @@ mod tests { assert_eq!(info.codename, None); } + #[test] + fn uos_os_release() { + let root = "src/linux/tests/Uos"; + + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::Uos); + assert_eq!(info.version, Version::Semantic(20, 0, 0)); + assert_eq!(info.edition, None); + assert_eq!(info.codename, None); + } + #[test] fn none_invalid_os_release() { let root = "src/linux/tests/none_invalid_os_release"; diff --git a/os_info/src/linux/lsb_release.rs b/os_info/src/linux/lsb_release.rs index 5537313..10eb33b 100644 --- a/os_info/src/linux/lsb_release.rs +++ b/os_info/src/linux/lsb_release.rs @@ -33,6 +33,7 @@ pub fn get() -> Option { Some("Mariner") => Type::Mariner, Some("NixOS") => Type::NixOS, Some("NobaraLinux") => Type::Nobara, + Some("Uos") => Type::Uos, Some("OpenCloudOS") => Type::OpenCloudOS, Some("openEuler") => Type::openEuler, Some("openSUSE") => Type::openSUSE, @@ -195,6 +196,17 @@ mod tests { assert_eq!(parse_results.codename, None); } + #[test] + fn Uos() { + let parse_results = parse(uos_file()); + assert_eq!( + parse_results.distribution, + Some("uos".to_string()) + ); + assert_eq!(parse_results.version, Some("20".to_string())); + assert_eq!(parse_results.codename, Some("eagle".to_string())); + } + #[test] fn amazon1() { let parse_results = parse(amazon1_file()); @@ -428,6 +440,14 @@ mod tests { " } + fn uos_file() -> &'static str { + "Distributor ID: uos\n\ + Description: UnionTech OS 20\n\ + Release: 20\n\ + Codename: eagle\n\ + " + } + // Amazon Linux 1 uses a separate Distributor ID and Release format from Amazon Linux 2 fn amazon1_file() -> &'static str { "LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch\n\ diff --git a/os_info/src/linux/mod.rs b/os_info/src/linux/mod.rs index 617c4bb..10461fb 100644 --- a/os_info/src/linux/mod.rs +++ b/os_info/src/linux/mod.rs @@ -45,6 +45,7 @@ mod tests { | Type::Mariner | Type::NixOS | Type::Nobara + | Type::Uos | Type::OpenCloudOS | Type::openEuler | Type::openSUSE diff --git a/os_info/src/linux/tests/Uos/etc/os-release b/os_info/src/linux/tests/Uos/etc/os-release new file mode 100644 index 0000000..c3feaf2 --- /dev/null +++ b/os_info/src/linux/tests/Uos/etc/os-release @@ -0,0 +1,8 @@ +PRETTY_NAME="UnionTech OS Desktop 20 Pro" +NAME="Uos" +VERSION_ID="20" +VERSION="20" +ID=Uos +HOME_URL="https://www.chinauos.com/" +BUG_REPORT_URL="http://bbs.chinauos.com" +VERSION_CODENAME=eagle diff --git a/os_info/src/os_type.rs b/os_info/src/os_type.rs index 8c7ede8..431c2fa 100644 --- a/os_info/src/os_type.rs +++ b/os_info/src/os_type.rs @@ -66,6 +66,8 @@ pub enum Type { NixOS, /// Nobara (). Nobara, + /// Uos (). + Uos, /// OpenBSD (). OpenBSD, /// OpenCloudOS (). @@ -128,6 +130,7 @@ impl Display for Type { Type::MidnightBSD => write!(f, "Midnight BSD"), Type::Mint => write!(f, "Linux Mint"), Type::Nobara => write!(f, "Nobara Linux"), + Type::Uos => write!(f, "Uos"), Type::openEuler => write!(f, "EulerOS"), Type::OracleLinux => write!(f, "Oracle Linux"), Type::Pop => write!(f, "Pop!_OS"), @@ -185,6 +188,7 @@ mod tests { (Type::NetBSD, "NetBSD"), (Type::NixOS, "NixOS"), (Type::Nobara, "Nobara Linux"), + (Type::Uos, "Uos"), (Type::OpenCloudOS, "OpenCloudOS"), (Type::OpenBSD, "OpenBSD"), (Type::openEuler, "EulerOS"),