Skip to content

Commit

Permalink
Merge pull request #213 from DarkEld3r/codename
Browse files Browse the repository at this point in the history
Add the 'codename' field to the version
  • Loading branch information
stanislav-tkach authored Aug 15, 2020
2 parents 1b6551c + 4c31ded commit a4cb067
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 63 deletions.
45 changes: 31 additions & 14 deletions os_info/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,48 @@ mod tests {
#[test]
fn new() {
let types = [
Type::Unknown,
Type::Alpine,
Type::Amazon,
Type::Android,
Type::Emscripten,
Type::Linux,
Type::Redhat,
Type::Ubuntu,
Type::Debian,
Type::Arch,
Type::Centos,
Type::Fedora,
Type::Solus,
Type::Debian,
Type::Emscripten,
Type::EndeavourOS,
Type::Manjaro,
Type::Alpine,
Type::Fedora,
Type::Linux,
Type::Macos,
Type::Manjaro,
Type::openSUSE,
Type::OracleLinux,
Type::Pop,
Type::Redhat,
Type::RedHatEnterprise,
Type::Redox,
Type::Solus,
Type::SUSE,
Type::Ubuntu,
Type::Unknown,
Type::Windows,
];

let versions = [
Version::unknown(),
Version::semantic(0, 0, 0, None),
Version::semantic(1, 2, 3, Some("e".to_owned())),
Version::custom("version".to_owned(), None),
Version::custom("different version".to_owned(), Some("edition".to_owned())),
Version::semantic(0, 0, 0, None, None),
Version::semantic(1, 2, 3, Some("e".to_owned()), None),
Version::semantic(1, 2, 3, Some("e".to_owned()), Some("2020.06.08".to_owned())),
Version::rolling(None, None, None),
Version::rolling(
Some("2020.02.03".to_owned()),
Some("edition".to_owned()),
Some("codename".to_owned()),
),
Version::custom("version".to_owned(), None, None),
Version::custom(
"different version".to_owned(),
Some("edition".to_owned()),
Some("codename".to_owned()),
),
];

let bitnesses = [Bitness::Unknown, Bitness::X32, Bitness::X64];
Expand Down
16 changes: 8 additions & 8 deletions os_info/src/linux/file_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn retrieve(distributions: &[ReleaseInfo]) -> Option<Info> {
let version = release_info
.version_matcher
.find(&file_content)
.map(|x| Version::new(VersionType::from_string(&x), None))
.map(|x| Version::new(VersionType::from_string(&x), None, None))
.unwrap_or_else(Version::unknown);

return Some(Info::new(os_type, version, Bitness::Unknown));
Expand Down Expand Up @@ -109,7 +109,7 @@ mod tests {

let info = retrieve(&distributions).unwrap();
assert_eq!(info.os_type(), Type::OracleLinux);
assert_eq!(info.version, Version::semantic(8, 1, 0, None));
assert_eq!(info.version, Version::semantic(8, 1, 0, None, None));
}

#[test]
Expand All @@ -119,7 +119,7 @@ mod tests {

let info = retrieve(&distributions).unwrap();
assert_eq!(info.os_type(), Type::Centos);
assert_eq!(info.version, Version::semantic(7, 0, 0, None));
assert_eq!(info.version, Version::semantic(7, 0, 0, None, None));
}

#[test]
Expand All @@ -129,7 +129,7 @@ mod tests {

let info = retrieve(&distributions).unwrap();
assert_eq!(info.os_type(), Type::Ubuntu);
assert_eq!(info.version, Version::semantic(18, 10, 0, None));
assert_eq!(info.version, Version::semantic(18, 10, 0, None, None));
}

#[test]
Expand All @@ -139,7 +139,7 @@ mod tests {

let info = retrieve(&distributions).unwrap();
assert_eq!(info.os_type(), Type::Centos);
assert_eq!(info.version, Version::custom("XX", None));
assert_eq!(info.version, Version::custom("XX", None, None));
}

#[test]
Expand All @@ -149,7 +149,7 @@ mod tests {

let info = retrieve(&distributions).unwrap();
assert_eq!(info.os_type(), Type::Fedora);
assert_eq!(info.version, Version::semantic(26, 0, 0, None));
assert_eq!(info.version, Version::semantic(26, 0, 0, None, None));
}

#[test]
Expand All @@ -159,7 +159,7 @@ mod tests {

let info = retrieve(&distributions).unwrap();
assert_eq!(info.os_type(), Type::Redhat);
assert_eq!(info.version, Version::custom("XX", None));
assert_eq!(info.version, Version::custom("XX", None, None));
}

#[test]
Expand All @@ -169,6 +169,6 @@ mod tests {

let info = retrieve(&distributions).unwrap();
assert_eq!(info.os_type(), Type::Alpine);
assert_eq!(info.version, Version::custom("A.B.C", None));
assert_eq!(info.version, Version::custom("A.B.C", None, None));
}
}
2 changes: 1 addition & 1 deletion os_info/src/linux/lsb_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn get() -> Option<Info> {

let version = release
.version
.map_or_else(Version::unknown, |v| Version::custom(v, None));
.map_or_else(Version::unknown, |v| Version::custom(v, None, None));

let os_type = match release.distribution.as_ref().map(String::as_ref) {
Some("Ubuntu") => Type::Ubuntu,
Expand Down
2 changes: 1 addition & 1 deletion os_info/src/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn version() -> Version {
Some(val) => val,
};

Version::new(VersionType::from_string(&version), None)
Version::new(VersionType::from_string(&version), None, None)
}

fn product_version() -> Option<String> {
Expand Down
3 changes: 2 additions & 1 deletion os_info/src/redox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const UNAME_FILE: &str = "sys:uname";
pub fn current_platform() -> Info {
trace!("redox::current_platform is called");

let version = get_version().map_or_else(|| Version::unknown(), |v| Version::custom(v, None));
let version =
get_version().map_or_else(|| Version::unknown(), |v| Version::custom(v, None, None));
let info = Info {
os_type: Type::Redox,
version,
Expand Down
Loading

0 comments on commit a4cb067

Please sign in to comment.