From owner-freebsd-ports Sun Dec 5 16:45:48 1999 Delivered-To: freebsd-ports@freebsd.org Received: from nimitz.ca.sandia.gov (nimitz.ca.sandia.gov [146.246.243.56]) by hub.freebsd.org (Postfix) with ESMTP id B616414DCF for ; Sun, 5 Dec 1999 16:45:25 -0800 (PST) (envelope-from bmah@nimitz.ca.sandia.gov) Received: (from bmah@localhost) by nimitz.ca.sandia.gov (8.9.3/8.9.3) id QAA51570; Sun, 5 Dec 1999 16:45:25 -0800 (PST) Message-Id: <199912060045.QAA51570@nimitz.ca.sandia.gov> X-Mailer: exmh version 2.1.0 09/18/1999 To: freebsd-ports@freebsd.org Cc: bmah@CA.Sandia.GOV Subject: Contributed patches for pkg_version From: bmah@CA.Sandia.GOV (Bruce A. Mah) Reply-To: bmah@CA.Sandia.GOV X-Face: g~c`.{#4q0"(V*b#g[i~rXgm*w;:nMfz%_RZLma)UgGN&=j`5vXoU^@n5v4:OO)c["!w)nD/!!~e4Sj7LiT'6*wZ83454H""lb{CC%T37O!!'S$S&D}sem7I[A 2V%N&+ X-Url: http://www.ca.sandia.gov/~bmah/ Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==_Exmh_-1177410527P"; micalg=pgp-sha1; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit Date: Sun, 05 Dec 1999 16:45:25 -0800 Sender: owner-freebsd-ports@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org --==_Exmh_-1177410527P Content-Type: multipart/mixed ; boundary="==_Exmh_-12036930230" This is a multipart MIME message. --==_Exmh_-12036930230 Content-Type: text/plain; charset=us-ascii Over the months, several people have sent me patches to fix up one of pkg_version's weaknesses...namely that of not gracefully dealing with multiple installed versions of ports. A number of things have happened since then, of most relevence being: 1) I dropped the ball on incorporating any of these, 2) pkg_version has been imported into the base system (thanks to Bill Fumerola!), and 3) we have the 3.4 and 4.0 releases of FreeBSD looming in the fairly near future. Both Bill and I are really short on time at the moment, but Bill has offered to *try* to review and commit these patches, amidst all the many other things he's currently doing. They *might* not apply completely cleanly, since there's been a couple of minor changes since the ports version. There's also the question of picking which one of these patches to adopt (or some combination of them). Unfortunately, I don't have the time right now to look into this (and probably won't for another two months or so). So I'm posting the original patches here (not necessarily in their original order) for Bill or someone else to look at, and hopefully do something useful with. Bruce. PS. Again, to Stefan, Neil, and Dave, sorry for sitting on these. :-( --==_Exmh_-12036930230 Content-Type: message/rfc822 ; name="576" Content-Description: 576 Return-Path: sec@42.org Delivery-Date: Sat Nov 20 19:33:52 1999 Received: from california.sandia.gov (california.sandia.gov [146.246.250.1]) by nimitz.ca.sandia.gov (8.9.3/8.9.3) with ESMTP id TAA82742 for ; Sat, 20 Nov 1999 19:33:51 -0800 (PST) Received: (from smap@localhost) by california.sandia.gov (8.8.8/1.15) id TAA01827 for ; Sat, 20 Nov 1999 19:33:51 -0800 (PST) Received: from matrix.42.org(194.246.250.200) by ca.sandia.gov via smap (V1.3) id sma019707; Sat Nov 20 19:33:40 1999 Received: (from sec@localhost) by matrix.42.org (8.8.8/8.8.5) id EAA08880 for bmah@ca.sandia.gov (sender ); Sun, 21 Nov 1999 04:33:31 +0100 (CET) Date: Sun, 21 Nov 1999 04:33:30 +0100 From: Stefan `Sec` Zehl To: bmah@california.sandia.gov Subject: pkg_version, feature patch Message-ID: <19991121043330.A8844@matrix.42.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i I-love-doing-this: really Accept-Languages: de, en X-URL: http://sec.42.org/ Hi, I've been using pkg_version on a few machines to check for outdated ports once in a while. But the number of '?'s were to many for me, so I made a small patch to compare all versions in index with the one installed. It helps me a lot in whenever i use "pkg_version -v|grep -v '=' " Maybe you can use it in the port, too. --- /usr/local/bin/pkg_version Tue Feb 23 00:37:20 1999 +++ pkg_version Wed Mar 24 00:02:12 1999 @@ -247,7 +247,22 @@ $indexRefcount = $indexPackages{$packageName}{'refcount'}; $currentRefcount = $currentPackages{$packageName}{'refcount'}; - if (($indexRefcount > 1) || ($currentRefcount > 1)) { + if (($indexRefcount > 1) && ($currentRefcount == 1)) { + foreach $vers (split(/,/,$indexPackages{$packageName}{'version'})){ + $rc = &CompareVersions($currentVersion, $vers); + if ($rc==0) { + print "="; + } elsif ($rc<0){ + print "<"; + } else { + print ">"; + } + } + if ($VerboseFlag) { + printf " multiple versions (index has %s)", + "$indexPackages{$packageName}{'version'}"; + } + }elsif (($indexRefcount > 1) || ($currentRefcount > 1)) { print "?"; if ($VerboseFlag) { printf " multiple versions (index has %s)", CU, Sec -- Larry Wall: "Lisp has all the visual appeal of oatmeal with nail clippings thrown in." --==_Exmh_-12036930230 Content-Type: message/rfc822 ; name="353" Content-Description: 353 Replied: Mon, 22 Feb 1999 08:09:03 -0800 Return-Path: dglo@tick.ssec.wisc.edu Delivery-Date: Fri Feb 19 11:11:35 1999 Received: from california.sandia.gov (california.sandia.gov [146.246.250.1]) by stennis.ca.sandia.gov (8.9.3/8.9.3) with ESMTP id LAA00683 for ; Fri, 19 Feb 1999 11:11:35 -0800 (PST) Received: from tick.ssec.wisc.edu (tick.ssec.wisc.edu [144.92.108.121]) by california.sandia.gov (8.8.8/1.15) with ESMTP id LAA01731 for ; Fri, 19 Feb 1999 11:11:30 -0800 (PST) Received: from tick.ssec.wisc.edu (localhost [127.0.0.1]) by tick.ssec.wisc.edu (8.8.7/8.8.7) with ESMTP id NAA01660 for ; Fri, 19 Feb 1999 13:11:22 -0600 (CST) From: Dave Glowacki Message-Id: <199902191911.NAA01660@tick.ssec.wisc.edu> To: bmah@california.sandia.gov Subject: Patches for pkg_version X-Face: #|'.s Yc@Rl%LiGoShz:-!:|uG5X!G9P`0"s:=d?I]k48?&w5o>{y.(E!]I=:":C1=')5ndCZ:M9vBD={ Date: Fri, 19 Feb 1999 13:11:21 -0600 I *love* your pkg_version script, but it didn't quite do everything I wanted it to do. Specifically, I have over 90 packages installed and the outdated packages get lost among all the up-to-date packages. Also, 11 of those packages have multiple versions and I have to go through them every time and make sure I've still got an up-to-date version. Since my FreeBSD 3.1 upgrade went fairly smoothly, I had a couple of free hours, so I spent 'em hacking on pkg_version. First, I added a '-U' option which, if specified, doesn't report the up-to-date packages. Next, I added a '-m' option which tries to match multiple versions of packages. Finally, I added the Perl '-w' option to the first line (this enables something like a Perl LINT mode) and fixed the few problems which were pointed out by this, then added the 'use strict' directive and fixed everything that *this* whined about. These changes are appended as a set of three patch files, one for each block of changes. I'd *really* like the first two sets to make it in ... I did the last set mainly to make sure I hadn't messed up anything with my patches and figured you might find it useful. Here are the patches: ############################################################################## --- pkg_version 1999/02/19 17:19:02 1.1 +++ pkg_version 1999/02/19 18:51:04 @@ -44,6 +44,7 @@ #$indexFile = "ftp://ftp.freebsd.org/pub/FreeBSD/ports-current/INDEX"; $IndexFile = 'file:/usr/ports/INDEX'; $DebugFlag = 0; +$NoUpToDateFlag = 0; $VerboseFlag = 0; # @@ -144,9 +145,10 @@ pkg_version $Version Bruce A. Mah -Usage: pkg_version [-d debug] [-h] [-v] [index] +Usage: pkg_version [-d debug] [-h] [-U] [-v] [index] -d debug Debugging output (debug controls level of output) -h Help (this message) +-U Don't report up-to-date packages -v Verbose output index URL or filename of index file (Default is $IndexFile) @@ -156,13 +158,16 @@ # # Parse command-line arguments, deal with them # -if (!getopts('dhv') || ($opt_h)) { +if (!getopts('dhUv') || ($opt_h)) { &PrintHelp(); exit; } if ($opt_d) { $DebugFlag = $opt_d; } +if ($opt_U) { + $NoUpToDateFlag = 1; +} if ($opt_v) { $VerboseFlag = 1; } @@ -233,12 +238,14 @@ foreach $packageName (sort keys %currentPackages) { if ($VerboseFlag) { - printf "%-20s ", "$packageName-$currentPackages{$packageName}{'version'}"; + $fullName = "$packageName-$currentPackages{$packageName}{'version'}"; } else { - printf "%-20s ", "$packageName"; + $fullName = $packageName; } + $description = ""; + if (defined $indexPackages{$packageName}{'version'}) { $indexVersion = $indexPackages{$packageName}{'version'}; @@ -248,10 +255,10 @@ $currentRefcount = $currentPackages{$packageName}{'refcount'}; if (($indexRefcount > 1) || ($currentRefcount > 1)) { - print "?"; + $markChar = "?"; if ($VerboseFlag) { - printf " multiple versions (index has %s)", - "$indexPackages{$packageName}{'version'}"; + $description = "multiple versions (index has " . + $indexPackages{$packageName}{'version'} . ")"; } } else { @@ -259,41 +266,47 @@ $rc = &CompareVersions($currentVersion, $indexVersion); if ($rc == 0) { - print "="; - if ($VerboseFlag) { - print " up-to-date"; + if ($NoUpToDateFlag) { + $fullName = undef; + } else { + $markChar = "="; + if ($VerboseFlag) { + $description = "up-to-date"; + } } } elsif ($rc < 0) { - print "<"; + $markChar = "<"; if ($VerboseFlag) { - printf " needs updating (index has %s)", - "$indexPackages{$packageName}{'version'}"; + $description = "needs updating (index has " . + $indexPackages{$packageName}{'version'} . ")"; } } elsif ($rc > 0) { - print ">"; + $markChar = ">"; if ($VerboseFlag) { - printf " succeeds index (index has %s)", - "$indexPackages{$packageName}{'version'}"; + $description = "succeeds index (index has " . + $indexPackages{$packageName}{'version'} . ")"; } } else { - print "?"; + $markChar = "?"; if ($VerboseFlag) { - printf " Comparison failed."; + $description = "Comparison failed."; } } } } else { - printf "?"; + $markChar = "?"; if ($VerboseFlag) { - printf " unknown in index"; + $description = "unknown in index"; } } - print "\n"; + if (defined($fullName)) { + printf "%-20s %s %s\n", $fullName, $markChar, $description; + } } ############################################################################## --- pkg_version 1999/02/19 18:51:55 1.2 +++ pkg_version 1999/02/19 18:53:32 @@ -44,6 +44,7 @@ #$indexFile = "ftp://ftp.freebsd.org/pub/FreeBSD/ports-current/INDEX"; $IndexFile = 'file:/usr/ports/INDEX'; $DebugFlag = 0; +$MatchVersionsFlag = 0; $NoUpToDateFlag = 0; $VerboseFlag = 0; @@ -145,9 +146,10 @@ pkg_version $Version Bruce A. Mah -Usage: pkg_version [-d debug] [-h] [-U] [-v] [index] +Usage: pkg_version [-d debug] [-h] [-m] [-U] [-v] [index] -d debug Debugging output (debug controls level of output) -h Help (this message) +-m Match packages with multiple versions -U Don't report up-to-date packages -v Verbose output index URL or filename of index file @@ -158,13 +160,16 @@ # # Parse command-line arguments, deal with them # -if (!getopts('dhUv') || ($opt_h)) { +if (!getopts('dhmUv') || ($opt_h)) { &PrintHelp(); exit; } if ($opt_d) { $DebugFlag = $opt_d; } +if ($opt_m) { + $MatchVersionsFlag = 1; +} if ($opt_U) { $NoUpToDateFlag = 1; } @@ -255,10 +260,52 @@ $currentRefcount = $currentPackages{$packageName}{'refcount'}; if (($indexRefcount > 1) || ($currentRefcount > 1)) { - $markChar = "?"; - if ($VerboseFlag) { - $description = "multiple versions (index has " . - $indexPackages{$packageName}{'version'} . ")"; + if ($MatchVersionsFlag) { + my $numMatched = 0; + + my $curVer; + foreach $curVer (split(/,/, $currentVersion)) { + my $foundMatch = 0; + + my $idxVer; + foreach $idxVer (split(/,/, $indexVersion)) { + my $rc = &CompareVersions($curVer, $idxVer); + if ($rc == 0) { + $foundMatch = 1; + last; + } + } + if ($foundMatch) { + $numMatched++; + } + } + + if ($numMatched == $currentRefcount) { + if ($NoUpToDateFlag) { + $fullName = undef; + } else { + $markChar = "="; + if ($VerboseFlag) { + $description = "matched " . + ($currentRefcount == 1 ? "a version" : + "all versions") . + " (index has " . + $indexVersion . ")"; + } + } + } else { + $markChar = "M"; + if ($VerboseFlag) { + $description = "multiple versions (index has " . + $indexVersion . ")"; + } + } + } else { + $markChar = "?"; + if ($VerboseFlag) { + $description = "multiple versions (index has " . + $indexVersion . ")"; + } } } else { @@ -279,14 +326,14 @@ $markChar = "<"; if ($VerboseFlag) { $description = "needs updating (index has " . - $indexPackages{$packageName}{'version'} . ")"; + $indexVersion . ")"; } } elsif ($rc > 0) { $markChar = ">"; if ($VerboseFlag) { $description = "succeeds index (index has " . - $indexPackages{$packageName}{'version'} . ")"; + $indexVersion . ")"; } } else { ############################################################################## --- pkg_version Fri Feb 19 12:55:45 1999 1.3 +++ pkg_version Fri Feb 19 12:56:51 1999 @@ -1,4 +1,4 @@ -#! /usr/local/bin/perl +#! /usr/local/bin/perl -w # # Copyright 1998 Bruce A. Mah # @@ -31,22 +31,23 @@ # $Id: pkg_version,v 1.8 1998/08/28 01:51:33 bmah Exp $ # +use strict; use Getopt::Std; # # Configuration global variables # -$Version = '0.1'; -$CurrentPackagesCommand = 'pkg_info -aI'; -$CatProgram = "cat "; -$FetchProgram = "fetch -o - "; - -#$indexFile = "ftp://ftp.freebsd.org/pub/FreeBSD/ports-current/INDEX"; -$IndexFile = 'file:/usr/ports/INDEX'; -$DebugFlag = 0; -$MatchVersionsFlag = 0; -$NoUpToDateFlag = 0; -$VerboseFlag = 0; +my $Version = '0.1'; +my $CurrentPackagesCommand = 'pkg_info -aI'; +my $CatProgram = "cat "; +my $FetchProgram = "fetch -o - "; + +#my $IndexFile = "ftp://ftp.freebsd.org/pub/FreeBSD/ports-current/INDEX"; +my $IndexFile = 'file:/usr/ports/INDEX'; +my $DebugFlag = 0; +my $MatchVersionsFlag = 0; +my $NoUpToDateFlag = 0; +my $VerboseFlag = 0; # # CompareVersions @@ -56,9 +57,8 @@ # This function returns -1, 0, or 1, in the same manner as <=> or cmp. # sub CompareVersions { - local($v1, $v2); - $v1 = $_[0]; - $v2 = $_[1]; + my $v1 = shift; + my $v2 = shift; # Short-cut in case of equality if ($v1 eq $v2) { @@ -68,22 +68,31 @@ # 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); + my ($p1, $p2); + + ($p1, $v1) = split(/\./, $v1, 2) if defined $v1; + ($p2, $v2) = split(/\./, $v2, 2) if defined $v2; + + my $p1Empty = (!defined($p1) || ($p1 eq "")); + my $p2Empty = (!defined($p2) || ($p2 eq "")); # 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 "")) { + if ($p1Empty && $p2Empty) { return 0; } + if ($p1Empty || $p2Empty) { + return -1 if (!$p1Empty); + return 1; + } # Check for numeric inequality. We assume here that (for example) # 3.09 < 3.10. - elsif ($p1 != $p2) { + if ($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) { + if ($p1 ne $p2) { return $p1 cmp $p2; } } @@ -97,8 +106,7 @@ # what we think is its version number. # sub GetName { - local($string); - $string = $_[0]; + my $string = shift; # If no hyphens, we assume the whole thing is the name. if ($string !~ m/-/) { @@ -118,8 +126,7 @@ # Try to get the version number of a package. # sub GetVersion { - local($string); - $string = $_[0]; + my $string = shift; # If no hyphens, assume no version number if ($string !~ m/-/) { @@ -149,7 +156,7 @@ Usage: pkg_version [-d debug] [-h] [-m] [-U] [-v] [index] -d debug Debugging output (debug controls level of output) -h Help (this message) --m Match packages with multiple versions +-m Match versions -U Don't report up-to-date packages -v Verbose output index URL or filename of index file @@ -160,20 +167,21 @@ # # Parse command-line arguments, deal with them # -if (!getopts('dhmUv') || ($opt_h)) { +($::opt_d,$::opt_h,$::opt_m,$::opt_U,$::opt_v) = (0,0,0,0); +if (!getopts('dhmUv') || ($::opt_h)) { &PrintHelp(); exit; } -if ($opt_d) { - $DebugFlag = $opt_d; +if ($::opt_d) { + $DebugFlag = $::opt_d; } -if ($opt_m) { +if ($::opt_m) { $MatchVersionsFlag = 1; } -if ($opt_U) { +if ($::opt_U) { $NoUpToDateFlag = 1; } -if ($opt_v) { +if ($::opt_v) { $VerboseFlag = 1; } if ($#ARGV >= 0) { @@ -184,6 +192,7 @@ # we can make a lot of this code go away...basically the problem is that # we can't depend on "fetch -o -" to do the right thing with files in the # filesystem. +my $IndexPackagesCommand; if ($IndexFile =~ s-^file:/-/-) { $IndexPackagesCommand = $CatProgram . $IndexFile; } @@ -201,11 +210,13 @@ print STDERR "$CurrentPackagesCommand\n"; } +my %currentPackages = (); + open CURRENT, "$CurrentPackagesCommand|"; while () { - ($packageString, $rest) = split; - $packageName = &GetName($packageString); - $packageVersion = &GetVersion($packageString); + my ($packageString, $rest) = split; + my $packageName = &GetName($packageString); + my $packageVersion = &GetVersion($packageString); $currentPackages{$packageName}{'name'} = $packageName; if (defined $currentPackages{$packageName}{'version'}) { $currentPackages{$packageName}{'version'} .= "," . $packageVersion; @@ -221,11 +232,13 @@ print STDERR "$IndexPackagesCommand\n"; } +my %indexPackages = (); + open INDEX, "$IndexPackagesCommand|"; while () { - ($packageString, $rest) = split(/\|/); - $packageName = &GetName($packageString); - $packageVersion = &GetVersion($packageString); + my ($packageString, $rest) = split(/\|/); + my $packageName = &GetName($packageString); + my $packageVersion = &GetVersion($packageString); $indexPackages{$packageName}{'name'} = $packageName; if (defined $indexPackages{$packageName}{'version'}) { $indexPackages{$packageName}{'version'} .= "," . $packageVersion; @@ -240,7 +253,9 @@ # # Produce reports # +my $packageName; foreach $packageName (sort keys %currentPackages) { + my ($fullName,$markChar,$description); if ($VerboseFlag) { $fullName = "$packageName-$currentPackages{$packageName}{'version'}"; @@ -253,11 +268,11 @@ if (defined $indexPackages{$packageName}{'version'}) { - $indexVersion = $indexPackages{$packageName}{'version'}; - $currentVersion = $currentPackages{$packageName}{'version'}; + my $indexVersion = $indexPackages{$packageName}{'version'}; + my $currentVersion = $currentPackages{$packageName}{'version'}; - $indexRefcount = $indexPackages{$packageName}{'refcount'}; - $currentRefcount = $currentPackages{$packageName}{'refcount'}; + my $indexRefcount = $indexPackages{$packageName}{'refcount'}; + my $currentRefcount = $currentPackages{$packageName}{'refcount'}; if (($indexRefcount > 1) || ($currentRefcount > 1)) { if ($MatchVersionsFlag) { @@ -310,7 +325,7 @@ } else { - $rc = &CompareVersions($currentVersion, $indexVersion); + my $rc = &CompareVersions($currentVersion, $indexVersion); if ($rc == 0) { if ($NoUpToDateFlag) { --==_Exmh_-12036930230 Content-Type: message/rfc822 ; name="480" Content-Description: 480 Return-Path: nbm@rucus.ru.ac.za Delivery-Date: Wed Aug 25 00:53:45 1999 Received: from california.sandia.gov (california.sandia.gov [146.246.250.1]) by stennis.ca.sandia.gov (8.9.3/8.9.3) with ESMTP id AAA18151 for ; Wed, 25 Aug 1999 00:53:45 -0700 (PDT) Received: (from smap@localhost) by california.sandia.gov (8.8.8/1.15) id AAA08207 for ; Wed, 25 Aug 1999 00:53:44 -0700 (PDT) Received: from rucus.ru.ac.za(146.231.29.2) by ca.sandia.gov via smap (V1.3) id sma012037; Wed Aug 25 00:53:25 1999 Received: (qmail 16042 invoked by uid 1003); 25 Aug 1999 07:54:03 -0000 Date: Wed, 25 Aug 1999 09:54:03 +0200 From: Neil Blakey-Milner To: Bill Fumerola Cc: "Bruce A. Mah" , freebsd-ports@FreeBSD.ORG Subject: Re: pkg_version Message-ID: <19990825095403.A14846@rucus.ru.ac.za> References: <199908242123.OAA20675@stennis.ca.sandia.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.6i In-Reply-To: ; from Bill Fumerola on Tue, Aug 24, 1999 at 04:48:09PM -0400 On Tue 1999-08-24 (16:48), Bill Fumerola wrote: > > Proceeding from the assumption that the pkg_version utility that I wrote > > as a weekend project oh so many months ago is actually useful to > > people.... > > > Any thoughts? > > I think it should come in. I agree. As my first quip, I'd suggest we change the multiple-versions handling (and thus slow the thing down incredibly). I have patches at http://rucus.ru.ac.za/~nbm/pkg_version-patch There is a bug in a very specific case, and I'd appreciate some testing. Neil -- Neil Blakey-Milner nbm@rucus.ru.ac.za --==_Exmh_-12036930230-- --==_Exmh_-1177410527P Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: PGPfreeware 5.0i for non-commercial use MessageID: zBea2D+JIxRg9Yw/154pjFZtLN3a5dkr iQA/AwUBOEsHJdjKMXFboFLDEQI/DQCgn/r/Ygx+qoeEIQbMJXIT5MdTLbUAoKbS Fpr4vcpxoit1ukUxOIqUXKYW =7FY3 -----END PGP SIGNATURE----- --==_Exmh_-1177410527P-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message