Date: Sun, 16 Apr 2000 12:47:28 +1000 (EST) From: andrew@ugh.net.au To: FreeBSD-gnats-submit@freebsd.org Subject: bin/18030: [PATCH] pkg_version thinks 4.04 > 4.1 Message-ID: <20000416024728.95336A818@starbug.ugh.net.au>
next in thread | raw e-mail | index | archive | help
>Number: 18030 >Category: bin >Synopsis: [PATCH] pkg_version thinks 4.04 > 4.1 >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Apr 15 19:50:01 PDT 2000 >Closed-Date: >Last-Modified: >Originator: Andrew >Release: FreeBSD 4.0-STABLE i386 >Organization: UgH! >Environment: 4.0-STABLE as of yesterday >Description: pkg_version thinks 4.04 > 4.1. It does this becasue it splits version numbers up as if they were . delimited. It then tries to comapre each group. The second comparison is 04 <=> 1. Perl treats 04 as 4 and so it becomes bigger. >How-To-Repeat: Run pkg_version with an old port (such as analog 4.04) installed. >Fix: Force a . on the front of the numbers. This seems to work. I have also changed the variables $p1 and $p2 to my from local as per perlsub(1) and changed a little bit of indenting to make it more logical (IMHO) and closer to style(9). --- pkg_version.pl.orig Mon Dec 6 13:19:16 1999 +++ pkg_version.pl Sun Apr 16 12:32:36 2000 @@ -57,36 +57,39 @@ # This function returns -1, 0, or 1, in the same manner as <=> or cmp. # sub CompareVersions { - local($v1, $v2); + my($v1, $v2); $v1 = $_[0]; $v2 = $_[1]; # Short-cut in case of equality if ($v1 eq $v2) { - return 0; + return 0; } # Loop over different components (the parts separated by dots). # If any component differs, we have the basis for an inequality. while (1) { - ($p1, $v1) = split(/\./, $v1, 2); - ($p2, $v2) = split(/\./, $v2, 2); + ($p1, $v1) = split(/\./, $v1, 2); + ($p2, $v2) = split(/\./, $v2, 2); - # If we\'re out of components, they\'re equal (this probably won\'t - # happen, since the short-cut case above should get this). - if (($p1 eq "") && ($p2 eq "")) { - return 0; - } - # Check for numeric inequality. We assume here that (for example) - # 3.09 < 3.10. - elsif ($p1 != $p2) { - return $p1 <=> $p2; - } - # Check for string inequality, given numeric equality. This - # handles version numbers of the form 3.4j < 3.4k. - elsif ($p1 ne $p2) { - return $p1 cmp $p2; - } + # If we\'re out of components, they\'re equal (this probably won\'t + # happen, since the short-cut case above should get this). + if (($p1 eq "") && ($p2 eq "")) { + return 0; + } + # Check for numeric inequality. We assume here that (for example) + # 3.09 < 3.10. We force a . on the front of $p1 and $p2 so that + # 4.1 > 4.04 + elsif ($p1 != $p2) { + $p1 = '.' . $p1; + $p2 = '.' . $p2; + return $p1 <=> $p2; + } + # Check for string inequality, given numeric equality. This + # handles version numbers of the form 3.4j < 3.4k. + elsif ($p1 ne $p2) { + return $p1 cmp $p2; + } } } >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000416024728.95336A818>