添加 rpmvercmp(v1: &str, v2: &str) -> i32 {}
Signed-off-by: Jia Chao <jiachao2130@126.com>
This commit is contained in:
parent
bd144d231f
commit
f69a461c65
|
@ -5,6 +5,9 @@ use librpm::config;
|
|||
// use librpm
|
||||
pub mod rpm;
|
||||
|
||||
// use librpmio;
|
||||
pub mod rpmio;
|
||||
|
||||
// 使用 Once 对配置进行一次性地初始化
|
||||
static CONFIGURE: Once = Once::new();
|
||||
|
||||
|
|
29
src/rpmio.rs
Normal file
29
src/rpmio.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use std::ffi::CString;
|
||||
|
||||
/// rpmvercmp 可对比两个软件包的版本
|
||||
/// 若 V1 大于 V2,则结果 > 0
|
||||
/// 若 V1 等于 V2,则结果 == 0
|
||||
/// 若 V1 小于 V2,则结果 < 0
|
||||
pub fn rpmvercmp(v1: &str, v2: &str) -> i32 {
|
||||
let v1 = CString::new(v1).expect("?");
|
||||
let v2 = CString::new(v2).expect("?");
|
||||
|
||||
unsafe { librpm_sys::rpmvercmp(v1.as_ptr(), v2.as_ptr()) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rpmvercmp() {
|
||||
let v1 = "5.10.0-60.ule3.x86_64";
|
||||
let v2 = "5.10.0-96.ule3.x86_64";
|
||||
let v3 = "5.10.0-108.ule3.x86_64";
|
||||
|
||||
let lt = rpmvercmp(v1, v2);
|
||||
let eq = rpmvercmp(v2, v2);
|
||||
let gt = rpmvercmp(v3, v2);
|
||||
|
||||
if lt < eq && eq < gt && eq == 0 {
|
||||
assert!(true);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user