|
1 | 1 | pub mod version_utils { |
| 2 | + use alpm::vercmp; |
2 | 3 | use lenient_semver; |
| 4 | + use std::cmp::Ordering; |
3 | 5 |
|
4 | | - // Helper function to compare versions properly |
| 6 | + // Helper function to compare versions using ALPM's vercmp for production consistency |
5 | 7 | pub fn is_version_newer(aur_version: &str, local_version: &str) -> bool { |
6 | | - // Handle git packages with revision numbers (e.g., "r89.fe26a90-1" or "-r89.fe26a90-1") |
7 | | - let extract_git_revision = |version: &str| -> Option<u32> { |
8 | | - if let Some(r_pos) = version.find('r') { |
9 | | - let after_r = &version[r_pos + 1..]; |
10 | | - if let Some(dot_pos) = after_r.find('.') { |
11 | | - if let Ok(rev) = after_r[..dot_pos].parse() { |
12 | | - return Some(rev); |
13 | | - } |
14 | | - } |
15 | | - } |
16 | | - None |
17 | | - }; |
18 | | - |
19 | | - // If both versions have git revision numbers, compare them |
20 | | - if let (Some(aur_rev), Some(local_rev)) = ( |
21 | | - extract_git_revision(aur_version), |
22 | | - extract_git_revision(local_version), |
23 | | - ) { |
24 | | - return aur_rev > local_rev; |
25 | | - } |
26 | | - |
27 | | - // Fall back to semantic version comparison |
28 | | - match ( |
29 | | - lenient_semver::parse(aur_version), |
30 | | - lenient_semver::parse(local_version), |
31 | | - ) { |
32 | | - (Ok(aur_semver), Ok(local_semver)) => aur_semver > local_semver, |
33 | | - // If semantic parsing fails, fall back to string comparison |
34 | | - // but only show as update if strings are different (conservative approach) |
35 | | - _ => aur_version != local_version && aur_version > local_version, |
| 8 | + // Use ALPM's vercmp which follows Arch Linux's official version comparison algorithm |
| 9 | + // vercmp returns Ordering::Greater if aur_version is newer than local_version |
| 10 | + match vercmp(aur_version, local_version) { |
| 11 | + Ordering::Greater => true, |
| 12 | + _ => false, |
36 | 13 | } |
37 | 14 | } |
38 | 15 |
|
|
0 commit comments