Bug 18030

Summary: [PATCH] pkg_version thinks 4.04 > 4.1
Product: Base System Reporter: Andrew Stevenson <andrew>
Component: binAssignee: Bruce A. Mah <bmah>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.0-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Andrew Stevenson 2000-04-16 03:50:01 UTC
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.

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).

How-To-Repeat: 
Run pkg_version with an old port (such as analog 4.04) installed.
Comment 1 Garrett A. Wollman 2000-04-16 04:09:00 UTC
<<On Sun, 16 Apr 2000 12:47:28 +1000 (EST), andrew@ugh.net.au said:

>> Synopsis:       [PATCH] pkg_version thinks 4.04 > 4.1

That's because it is.  Version numbers, by tradition, are not reals;
4.10 comes nine revisions after 4.1.

-GAWollman

--
Garrett A. Wollman   | O Siem / We are all family / O Siem / We're all the same
wollman@lcs.mit.edu  | O Siem / The fires of freedom 
Opinions not those of| Dance in the burning flame
MIT, LCS, CRS, or NSA|                     - Susan Aglukark and Chad Irschick
Comment 2 root 2000-04-17 07:53:48 UTC
On 16/04, andrew@ugh.net.au wrote:

| Force a . on the front of the numbers. This seems to work.

a2ps 4.12 > a2ps 4.3, and your patch will break it. There is no way to make
this fully automated.
Comment 3 Andrew Stevenson 2000-04-17 09:24:16 UTC
On Mon, 17 Apr 2000, Samuel Tardieu wrote:

> On 16/04, andrew@ugh.net.au wrote:
> 
> | Force a . on the front of the numbers. This seems to work.
> 
> a2ps 4.12 > a2ps 4.3, and your patch will break it. There is no way to make
> this fully automated.

Garrett Wollman pointed this out...I suggested only forcing a . infront of
version numbers beggining with 0? I think that should fix things but
perhaps I'm missing something else...

Thanks,

Andrew
Comment 4 Andrew Stevenson 2000-07-05 17:47:14 UTC
Well no one said anything about my leading 0 suggestion so I have coded
it. It seems to get everything right on my system and I'm guessing even if
it now gets some wrong that it used to get right it will get more right
overall.

I guess it will have trouble if anyone puts a leading 0 on their version
numbers just to pad the field. Hopefully not too many of them.

Thanks,

Andrew

--- /usr/src/usr.sbin/pkg_install/version/pkg_version.pl.orig	Mon Dec  6 13:19:16 1999
+++ pkg_version.pl	Thu Jul  6 00:39:22 2000
@@ -57,7 +57,7 @@
 # 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];
 
@@ -77,9 +77,14 @@
 	if (($p1 eq "") && ($p2 eq "")) {
 	    return 0;
 	}
-	# Check for numeric inequality.  We assume here that (for example)
-	# 3.09 < 3.10.
+		# Check for numeric inequality.  We assume here that if the number
+		# begins with a 0 then it is a decimal, else it is natural.
+		# 3.09 < 3.10, 4.03 < 4.1
 	elsif ($p1 != $p2) {
+			if ((index($p1, '0') == 0) or (index($p2, '0') == 0)) {
+				$p1 = '.' . $p1;
+				$p2 = '.' . $p2;
+			}
 	    return $p1 <=> $p2;
 	}
 	# Check for string inequality, given numeric equality.  This
Comment 5 Sheldon Hearn freebsd_committer freebsd_triage 2000-08-07 15:04:45 UTC
Responsible Changed
From-To: freebsd-bugs->billf

Over to the maintainer.
Comment 6 Bruce A. Mah freebsd_committer freebsd_triage 2000-10-20 07:17:52 UTC
State Changed
From-To: open->closed

I think that pkg_version is doing the right thing;  
if a port has version numbers that work like decimals, we ought to  
change the metadata in the port's Makefile. 


Comment 7 Bruce A. Mah freebsd_committer freebsd_triage 2000-10-20 07:17:52 UTC
Responsible Changed
From-To: billf->bmah

MAINTAINER change.