Skip to content

Commit 138fc18

Browse files
committed
Fix: handle special deb package names (bsc#1150113)
Package version for RPM does not contain any '-': ``` susemanager=# select count(*) from rhnpackage; count -------- 217621 (1 row) susemanager=# select * from rhnpackageevr where version like '%-%'; id | epoch | version | release | evr ----+-------+---------+---------+----- (0 rows) ``` For Debian packages, some packages are named with a '-' in their version, e.g.: ``` gcc-8-base-8-20180414-1ubuntu2.amd64-deb gcc-8-base-8.2.0-1ubuntu2~18.04.amd64-deb lib32gcc1-8-20180414-1ubuntu2:1.amd64-deb lib32gcc1-8.2.0-1ubuntu2~18.04:1.amd64-deb libatomic1-8-20180414-1ubuntu2.amd64-deb libatomic1-8.2.0-1ubuntu2~18.04.amd64-deb libcc1-0-8-20180414-1ubuntu2.amd64-deb libcc1-0-8.2.0-1ubuntu2~18.04.amd64-deb libgcc1-8-20180414-1ubuntu2:1.amd64-deb libgcc1-8.2.0-1ubuntu2~18.04:1.amd64-deb libgomp1-8-20180414-1ubuntu2.amd64-deb libgomp1-8.2.0-1ubuntu2~18.04.amd64-deb libitm1-8-20180414-1ubuntu2.amd64-deb libitm1-8.2.0-1ubuntu2~18.04.amd64-deb liblsan0-8-20180414-1ubuntu2.amd64-deb liblsan0-8.2.0-1ubuntu2~18.04.amd64-deb libmpx2-8-20180414-1ubuntu2.amd64-deb libmpx2-8.2.0-1ubuntu2~18.04.amd64-deb libquadmath0-8-20180414-1ubuntu2.amd64-deb libquadmath0-8.2.0-1ubuntu2~18.04.amd64-deb libstdc++6-8-20180414-1ubuntu2.amd64-deb libstdc++6-8.2.0-1ubuntu2~18.04.amd64-deb libtsan0-8-20180414-1ubuntu2.amd64-deb libtsan0-8.2.0-1ubuntu2~18.04.amd64-deb ``` The version is correctly parsed: ``` susemanager=# select * from rhnpackageevr where id in (select evr_id from rhnpackage where name_id in (select id from rhnpackagename where name like '%gcc-8-base%')); id | epoch | version | release | evr ------+-------+------------+------------------+--------------------------- 316 | | 8-20180414 | 1ubuntu2 | (,8-20180414,1ubuntu2) 1835 | | 8.3.0 | 6ubuntu1~18.04.1 | (,8.3.0,6ubuntu1~18.04.1) (2 rows) ``` This PR adds a special check in the version: if it contains a '-', then we are dealing with a pre-release version of a Debian package. We replace '-' to '~' to signal that we are dealing with a pre-release version.
1 parent 6a577e8 commit 138fc18

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

java/code/src/com/redhat/rhn/common/util/RpmVersionComparator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030
public class RpmVersionComparator implements Comparator<String> {
3131

32+
public static final String DEBIAN_PACKAGE_VERSION_REGEX = "\\d-\\d{8}";
33+
3234
/**
3335
* {@inheritDoc}
3436
*/
@@ -51,6 +53,13 @@ public int compare(String o1, String o2) {
5153
int b1 = 0;
5254
int b2 = 0;
5355

56+
// Ubuntu/Debian package handling: 8-20180414 is older than 8.3.0 (bsc#1150113)
57+
if (str1.matches(DEBIAN_PACKAGE_VERSION_REGEX)) {
58+
str1 = str1.replace("-", "~");
59+
}
60+
if (str2.matches(DEBIAN_PACKAGE_VERSION_REGEX)) {
61+
str2 = str2.replace("-", "~");
62+
}
5463

5564
/* loop through each version segment of str1 and str2 and compare them */
5665
while (true) {

java/code/src/com/redhat/rhn/common/util/test/RpmVersionComparatorTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public void testCaretSorting() {
102102
assertCompareSymm(1, "1.0^20160102", "1.0^20160101^git1");
103103
}
104104

105+
public void testUbuntuBugzilla1150113() {
106+
assertCompareSymm(-1, "8-20180414", "8.3.0");
107+
assertCompareSymm(-1, "2.7.15~rc1", "2.7.15");
108+
assertCompareSymm(-1, "1.20.4", "14.1");
109+
}
110+
105111
/* from official rpm tests */
106112
public void testTildeAndCaretSorting() {
107113
assertCompareSymm(1, "1.0~rc1^git1", "1.0~rc1");

schema/spacewalk/postgres/packages/rpm.pkb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,19 @@ $$ language 'plpgsql';
6060
then
6161
RAISE EXCEPTION 'VALUE_ERROR.';
6262
end if;
63-
63+
6464
if str1 = str2
6565
then
6666
return 0;
6767
end if;
68+
if regexp_match(str1, '[[:digit:]](-)[[:digit:]]{8}') is not null
69+
then
70+
str1 := replace(str1, '-', '~');
71+
end if;
72+
if regexp_match(str2, '[[:digit:]](-)[[:digit:]]{8}') is not null
73+
then
74+
str2 := replace(str2, '-', '~');
75+
end if;
6876
one := str1;
6977
two := str2;
7078

0 commit comments

Comments
 (0)