Actions
action #104355
closed[sle][security][sle15sp4]enhance current package version check code to use exist good function
Start date:
2021-12-27
Due date:
% Done:
100%
Estimated time:
10.00 h
Difficulty:
Description
We have several cases need compare the new version with old one.
e.g. https://openqa.suse.de/tests/7898036/modules/version_check/steps/1/src
However, current logic is too simple to cover complex package version.
Actually, we have already had one good function there. let me enhance my current code:
sub package_version_cmp {
my ($ver1, $ver2) = @_;
my @chunks1 = split(/-/, $ver1);
my @chunks2 = split(/-/, $ver2);
my $chunk_cnt = $#chunks1 > $#chunks2 ? scalar @chunks1 : scalar @chunks2;
for (my $cid = 0; $cid < $chunk_cnt; $cid++) {
my @tokens1 = split(/\./, $chunks1[$cid] // '0');
my @tokens2 = split(/\./, $chunks2[$cid] // '0');
my $token_cnt = scalar @tokens1;
$token_cnt = scalar @tokens2 if $#tokens2 > $#tokens1;
for (my $tid = 0; $tid < $token_cnt; $tid++) {
my $tok1 = $tokens1[$tid] // '0';
my $tok2 = $tokens2[$tid] // '0';
if ($tok1 =~ m/^\d+$/ && $tok2 =~ m/^\d+$/) {
next if $tok1 == $tok2;
return $tok1 - $tok2;
} else {
next if $tok1 eq $tok2;
return 1 if $tok1 gt $tok2;
return -1;
}
}
}
return 0;
}
Updated by rfan1 almost 2 years ago
Is any your codes need change as well? do let me know, I can fix them with 1 commit:)
Updated by rfan1 almost 2 years ago
- Status changed from New to In Progress
- % Done changed from 0 to 10
As discussed with team members, we'd better to build a function to simply our test.
let me do that
Updated by rfan1 almost 2 years ago
- % Done changed from 10 to 70
Updated by rfan1 over 1 year ago
- Status changed from In Progress to Feedback
- % Done changed from 70 to 90
- Estimated time changed from 8.00 h to 10.00 h
Updated by rfan1 over 1 year ago
- Status changed from Feedback to Resolved
- % Done changed from 90 to 100
Actions