Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 05 Oct 2000 21:26:57 -0700
From:      "Bruce A. Mah" <bmah@FreeBSD.ORG>
To:        Maxim Sobolev <sobomax@FreeBSD.ORG>
Cc:        bmah@FreeBSD.ORG, Neil Blakey-Milner <nbm@mithrandr.moria.org>, Akinori -Aki- MUSHA <knu@idaemons.org>, freebsd-ports@FreeBSD.ORG, asami@FreeBSD.ORG
Subject:   Re: PROPOSAL: Use @comment PLIST variable to track where installed packages came from [Was: Enhancement of pkg_version's version comparison routine] 
Message-ID:  <200010060426.e964Qvx70814@bmah-freebsd-0.cisco.com>
In-Reply-To: <39DB17BB.12805565@FreeBSD.org> 
References:  <86k8by6eis.wl@archon.local.idaemons.org> <20000927002401.A73341@mithrandr.moria.org> <39D9D006.652DC258@FreeBSD.org> <20001003161027.B67542@mithrandr.moria.org> <39D9EE01.7A880665@FreeBSD.org> <200010031657.e93Gvtg10718@bmah-freebsd-0.cisco.com> <39DB17BB.12805565@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--==_Exmh_-994978211P
Content-Type: text/plain; charset=us-ascii

Hi Max--

OK, I've been playing with your patch (a very little bit).  For what 
it's worth, I like it more now that I've hacked pkg_version to match.

Here's the relevent modifications for pkg_version (against -STABLE, but
should apply to -CURRENT also).  It ought to be backward compatable with
existing packages.  Feedback is welcome (from everyone, not just Max).

Cheers,

Bruce.

Index: pkg_version.1
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/version/pkg_version.1,v
retrieving revision 1.5.2.3
diff -c -r1.5.2.3 pkg_version.1
*** pkg_version.1	2000/09/20 08:53:55	1.5.2.3
--- pkg_version.1	2000/10/06 04:02:16
***************
*** 41,67 ****
  command is used to produce a report of non-base software packages
  installed using the 
  .Xr pkg_add 1
! command.  Version numbers are compared against an
! index file, to see which packages might need updating.
  .Pp
  Each package name is printed, along with a one-character status flag:
  .Bl -tag -width indent
  .It Li =
! The installed version of the package matches the index.
  .It Li <
! The installed version of the package is older than the version listed
! in the index.
  .It Li >
! The installed version of the package is newer than listed in the
! index.
  .It Li ?
  The installed package does not appear in the index. 
  This could be due to an out of date index or a package taken from a PR 
  that has not yet been committed.
  .It Li *
  There are multiple versions of a particular software package
! installed or there are multiple versions of a package listed in 
! the index file.
  Examples from the
  .Fx
  ports collection are the Tcl toolkit or the
--- 41,95 ----
  command is used to produce a report of non-base software packages
  installed using the 
  .Xr pkg_add 1
! command.  
  .Pp
+ Each package's version number is checked against one of two sources to
+ see if that package may require updating.  If the package contains
+ information about its origin in the
+ .Fx
+ ports tree, and a version number can be determined from the port's
+ .Pa Makefile ,
+ then the version number from the 
+ .Pa Makefile
+ will be used to determine whether the installed package is up-to-date
+ or requires updating.
+ .Pp
+ If no origin for a package can be found, or if the port's 
+ .Pa Makefile
+ cannot be located, 
+ .Nm
+ will search for the package in the ports collection index file
+ (typically
+ .Pa /usr/ports/INDEX ).  
+ Any matching version number(s) there will be used to determine whether
+ the installed package is up-to-date or requires updating.
+ .Pp
+ Generally, using the version number from a port's 
+ .Pa Makefile
+ will provide a more accurate result, since, unlike the index file, it 
+ provides an unambiguous current version number, even when multiple
+ versions of a port exist in the ports collection.
+ Moreover, the ports collection index file is only updated at
+ intervals, meaning that it may not completely reflect the version
+ numbers of the software contained in the ports collection.
+ .Pp
  Each package name is printed, along with a one-character status flag:
  .Bl -tag -width indent
  .It Li =
! The installed version of the package is current.
  .It Li <
! The installed version of the package is older than the current version.
  .It Li >
! The installed version of the package is newer than the current version.
! This situation can arise with an out-of-date index file, or when
! testing new ports.
  .It Li ?
  The installed package does not appear in the index. 
  This could be due to an out of date index or a package taken from a PR 
  that has not yet been committed.
  .It Li *
  There are multiple versions of a particular software package
! listed in the index file.
  Examples from the
  .Fx
  ports collection are the Tcl toolkit or the
***************
*** 80,93 ****
  Enable commands output.  Commands output includes the commands you should
  type to update your installed packages to the latest versions in the ports
  system.
  .It Fl d
  Enable debugging output.
  .It Fl h
  Print help message.
  .It Fl l
! Limit the output to those packages whose status flag matches
  .Ar limchar .
! You may specify more than one character to match in
  .Ar limchar .  
  Note that because some of the status flag characters are also special
  to the shell, it is best to quote
--- 108,133 ----
  Enable commands output.  Commands output includes the commands you should
  type to update your installed packages to the latest versions in the ports
  system.
+ This feature does
+ .Bf Em
+ not
+ .Ef
+ constitute an automated packages updating system.
+ The output of this command 
+ .Bf Em
+ must
+ .Ef
+ be edited, in order to avoid destroying dependencies between installed
+ packages.
  .It Fl d
  Enable debugging output.
  .It Fl h
  Print help message.
  .It Fl l
! Limit the output to those packages whose status flag matches the 
! character(s) in
  .Ar limchar .
! More than one character can be specified in
  .Ar limchar .  
  Note that because some of the status flag characters are also special
  to the shell, it is best to quote
***************
*** 135,147 ****
  .Pp
  The command below generates a file of commands to run to update the installed
  files.
! It is
  .Bf Em
  not
  .Ef
! suggested that you run these commands automatically.
! Always review the
! suggestions, and then cut-and-paste (or retype) the commands you want to run.
  .Pp
  .Dl % pkg_version -c > do_update
  .Sh AUTHOR
--- 175,190 ----
  .Pp
  The command below generates a file of commands to run to update the installed
  files.
! These commands must
  .Bf Em
  not
  .Ef
! be run without suitable editing.
! They should be treated as suggestions, and may need to be reordered 
! to account for dependencies between installed packages, or may need to
! be disregarded if multiple versions of an installed package can coexist.
! Blindly running the output of this command may leave a system in an
! unusable state.
  .Pp
  .Dl % pkg_version -c > do_update
  .Sh AUTHOR
***************
*** 151,172 ****
  .An Dominic Mitchell Aq dom@palmerharvey.co.uk ,
  .An Mark Ovens Aq marko@FreeBSD.org
  .Sh BUGS
- There should be a better way of dealing with packages that
- can have more than one installed version.
  .Pp
  Patch levels aren't handled
  very well (i.e. version numbers of the form 1.2p3 or 1.2pl3).
  .Pp
! Updates to packages
! that don't change the version number (e.g. small delta bugfixes in the
! package/port itself) aren't detected.
! .Pp
! Commands output doesn't know about dependencies between packages.
! For
! example, you might have two versions of Tcl installed because two other
! packages require the different versions.
! .Nm
! will suggest removing the out-of-date version.
  .Pp
  Commands output assumes you install new software using the ports system,
  rather than using
--- 194,211 ----
  .An Dominic Mitchell Aq dom@palmerharvey.co.uk ,
  .An Mark Ovens Aq marko@FreeBSD.org
  .Sh BUGS
  .Pp
  Patch levels aren't handled
  very well (i.e. version numbers of the form 1.2p3 or 1.2pl3).
  .Pp
! The commands output feature is 
! .Bf Em 
! not
! .Ef
! an automated ports/packages updating system.
! It does not even attempt to handle dependencies between installed 
! packages correctly, and can produce incorrect results if multiple
! versions of a package can coexist on a system.
  .Pp
  Commands output assumes you install new software using the ports system,
  rather than using
Index: pkg_version.pl
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/version/pkg_version.pl,v
retrieving revision 1.4.2.4
diff -c -r1.4.2.4 pkg_version.pl
*** pkg_version.pl	2000/09/20 08:53:55	1.4.2.4
--- pkg_version.pl	2000/10/05 14:02:21
***************
*** 31,36 ****
--- 31,37 ----
  # $FreeBSD: src/usr.sbin/pkg_install/version/pkg_version.pl,v 1.4.2.4 2000/09/20 08:53:55 jkh Exp $
  #
  
+ use Cwd;
  use Getopt::Std;
  
  #
***************
*** 40,47 ****
--- 41,51 ----
  $CurrentPackagesCommand = '/usr/sbin/pkg_info -aI';
  $CatProgram = "cat ";
  $FetchProgram = "fetch -o - ";
+ $OriginCommand = '/usr/sbin/pkg_info -qo';
+ $GetPortVersionCommand = 'make -V PORTVERSION';
  
  #$IndexFile = "ftp://ftp.freebsd.org/pub/FreeBSD/branches/-current/ports/INDEX";
+ $PortsDirectory = '/usr/ports';
  $IndexFile = '/usr/ports/INDEX';
  $ShowCommandsFlag = 0;
  $DebugFlag = 0;
***************
*** 235,241 ****
  }
  
  #
! # Slurp in files
  #
  if ($DebugFlag) {
      print STDERR "$CurrentPackagesCommand\n";
--- 239,245 ----
  }
  
  #
! # Get the current list of installed packages
  #
  if ($DebugFlag) {
      print STDERR "$CurrentPackagesCommand\n";
***************
*** 246,262 ****
      ($packageString, $rest) = split;
  
      ($packageName, $packageFullversion) = &GetNameAndVersion($packageString);
!     $currentPackages{$packageName}{'name'} = $packageName;
!     if (defined $currentPackages{$packageName}{'fullversion'}) {
! 	$currentPackages{$packageName}{'fullversion'} .= "|" . $packageFullversion;
!     }
!     else {
! 	$currentPackages{$packageName}{'fullversion'} = $packageFullversion;
!     }
!     $currentPackages{$packageName}{'refcount'}++;
  }
  close CURRENT;
  
  if ($DebugFlag) {
      print STDERR "$IndexPackagesCommand\n";
  }
--- 250,297 ----
      ($packageString, $rest) = split;
  
      ($packageName, $packageFullversion) = &GetNameAndVersion($packageString);
!     $currentPackages{$packageString}{'name'} = $packageName;
!     $currentPackages{$packageString}{'fullversion'} = $packageFullversion;
  }
  close CURRENT;
  
+ #
+ # Iterate over installed packages, get origin directory (if it
+ # exists) and PORTVERSION
+ #
+ $dir = cwd();
+ foreach $packageString (sort keys %currentPackages) {
+ 
+     open ORIGIN, "$OriginCommand $packageString|";
+     $origin = <ORIGIN>;
+     close ORIGIN;
+ 
+     # If there is an origin variable for this package, then store it.
+     if ($origin ne "") {
+ 	chomp $origin;
+ 
+ 	# Try to get the version out of the makefile.
+ 	# The chdir needs to be successful or our make -V invocation
+ 	# will fail.
+ 	chdir "$PortsDirectory/$origin" or next;
+ 
+ 	open VERSION, "$GetPortVersionCommand|";
+ 	$portversion = <VERSION>;
+ 	close VERSION;
+ 
+ 	if ($portversion ne "") {
+ 	    chomp $portversion;
+ 
+ 	    $currentPackages{$packageString}{'origin'} = $origin;
+ 	    $currentPackages{$packageString}{'portversion'} = $portversion;
+ 	}
+     }
+ }
+ chdir "$dir";
+ 
+ #
+ # Slurp in the index file
+ #
  if ($DebugFlag) {
      print STDERR "$IndexPackagesCommand\n";
  }
***************
*** 288,311 ****
  # to commas before we output anything so the reports look the
  # same as they did before.
  #
! foreach $packageName (sort keys %currentPackages) {
      $~ = "STDOUT_VERBOSE"  if $VerboseFlag;
      $~ = "STDOUT_COMMANDS" if $ShowCommandsFlag;
  
!     $packageNameVer = "$packageName-$currentPackages{$packageName}{'fullversion'}";
!     $packageNameVer =~ s/\|/,/g;
  
!     if (defined $indexPackages{$packageName}{'fullversion'}) {
  
! 	$indexVersion = $indexPackages{$packageName}{'fullversion'};
! 	$currentVersion = $currentPackages{$packageName}{'fullversion'};
  
  	$indexRefcount = $indexPackages{$packageName}{'refcount'};
! 	$currentRefcount = $currentPackages{$packageName}{'refcount'};
  
! 	$packagePath = $indexPackages{$packageName}{'path'};
! 	
! 	if (($indexRefcount > 1) || ($currentRefcount > 1)) {
  	    $versionCode = "*";
  	    $Comment = "multiple versions (index has $indexVersion)";
  	    $Comment =~ s/\|/,/g;
--- 323,373 ----
  # to commas before we output anything so the reports look the
  # same as they did before.
  #
! foreach $packageString (sort keys %currentPackages) {
      $~ = "STDOUT_VERBOSE"  if $VerboseFlag;
      $~ = "STDOUT_COMMANDS" if $ShowCommandsFlag;
  
!     $packageNameVer = $packageString;
!     $packageName = $currentPackages{$packageString}{'name'};
  
!     $currentVersion = $currentPackages{$packageString}{'fullversion'};
  
!     if (defined $currentPackages{$packageString}{'portversion'}) {
! 	$portVersion = $currentPackages{$packageString}{'portversion'};
! 
! 	$portPath = "$PortsDirectory/$currentPackages{$packageString}{'origin'}";
! 
! 	# Do the comparison
! 	$rc = &CompareVersions($currentVersion, $portVersion);
! 	    
! 	if ($rc == 0) {
! 	    next if $ShowCommandsFlag;
! 	    $versionCode = "=";
! 	    $Comment = "up-to-date with port";
! 	}
! 	elsif ($rc < 0) {
! 	    $versionCode = "<";
! 	    $Comment = "needs updating (port has $portVersion)";
! 	}
! 	elsif ($rc > 0) {
! 	    next if $ShowCommandsFlag;
! 	    $versionCode = ">";
! 	    $Comment = "succeeds port (port has $portVersion)";
! 	}
! 	else {
! 	    $versionCode = "!";
! 	    $Comment = "Comparison failed";
! 	}
!     }
  
+     elsif (defined $indexPackages{$packageName}{'fullversion'}) {
+ 
+ 	$indexVersion = $indexPackages{$packageName}{'fullversion'};
  	$indexRefcount = $indexPackages{$packageName}{'refcount'};
! 
! 	$portPath = $indexPackages{$packageName}{'path'};
  
! 	if ($indexRefcount > 1) {
  	    $versionCode = "*";
  	    $Comment = "multiple versions (index has $indexVersion)";
  	    $Comment =~ s/\|/,/g;
***************
*** 314,326 ****
  
  	    # Do the comparison
  	    $rc = 
! 		&CompareVersions($currentPackages{$packageName}{'fullversion'},
! 				 $indexPackages{$packageName}{'fullversion'});
  	    
  	    if ($rc == 0) {
  		next if $ShowCommandsFlag;
  		$versionCode = "=";
! 		$Comment = "up-to-date";
  	    }
  	    elsif ($rc < 0) {
  		$versionCode = "<";
--- 376,387 ----
  
  	    # Do the comparison
  	    $rc = 
! 		&CompareVersions($currentVersion, $indexVersion);
  	    
  	    if ($rc == 0) {
  		next if $ShowCommandsFlag;
  		$versionCode = "=";
! 		$Comment = "up-to-date with index";
  	    }
  	    elsif ($rc < 0) {
  		$versionCode = "<";
***************
*** 383,389 ****
  @<
  $CommentChar
  cd @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
! $packagePath
  make && pkg_delete -f @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                $packageNameVer
  make install
--- 444,450 ----
  @<
  $CommentChar
  cd @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
! $portPath
  make && pkg_delete -f @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                $packageNameVer
  make install




--==_Exmh_-994978211P
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.3 (FreeBSD)
Comment: Exmh version 2.2 06/23/2000

iD8DBQE53VSR2MoxcVugUsMRArDlAJ0XXJzvd6KjWwGtMWC+goJumO6SngCgl1Se
eX7DR2iL0s6PKPoXAsbptKw=
=ad28
-----END PGP SIGNATURE-----

--==_Exmh_-994978211P--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200010060426.e964Qvx70814>