From john.marshall@riverwillow.com.au  Wed Feb 12 03:37:16 2014
Return-Path: <john.marshall@riverwillow.com.au>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 9CF82A97
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Feb 2014 03:37:16 +0000 (UTC)
Received: from mail1.riverwillow.net.au (mail1.riverwillow.net.au [IPv6:2001:8000:1000:1801::36])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 12F1A1D7E
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Feb 2014 03:37:15 +0000 (UTC)
Received: from rwpc13.gfn.riverwillow.net.au (rwpc13.gfn.riverwillow.net.au [IPv6:2001:8000:1000:18e1:20c:76ff:fe05:fa0b])
	(authenticated bits=0)
	by mail1.riverwillow.net.au (8.14.8/8.14.8) with ESMTP id s1C3LXKN016778
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Feb 2014 14:21:34 +1100 (AEDT)
Received: from rwpc13.gfn.riverwillow.net.au (john@localhost [127.0.0.1])
	by rwpc13.gfn.riverwillow.net.au (8.14.7/8.14.7) with ESMTP id s1C3LXtZ066320
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Feb 2014 14:21:33 +1100 (AEDT)
	(envelope-from john.marshall@riverwillow.com.au)
Received: (from john@localhost)
	by rwpc13.gfn.riverwillow.net.au (8.14.7/8.14.7/Submit) id s1C3LX0Q066319;
	Wed, 12 Feb 2014 14:21:33 +1100 (AEDT)
	(envelope-from john)
Message-Id: <201402120321.s1C3LX0Q066319@rwpc13.gfn.riverwillow.net.au>
Date: Wed, 12 Feb 2014 14:21:33 +1100 (AEDT)
From: John Marshall <john.marshall@riverwillow.com.au>
Reply-To: John Marshall <john.marshall@riverwillow.com.au>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: ports-mgmt/pkg 1.2.6 pkg version ignores index argument
X-Send-Pr-Version: 3.114
X-GNATS-Notify:

>Number:         186671
>Category:       ports
>Synopsis:       ports-mgmt/pkg 1.2.6 pkg version ignores index argument
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    portmgr
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 12 03:40:00 UTC 2014
>Closed-Date:    
>Last-Modified:  Sat Mar 22 13:20:00 UTC 2014
>Originator:     John Marshall
>Release:        FreeBSD 9.2-RELEASE i386
>Organization:
Riverwillow Pty Ltd
>Environment:
System: FreeBSD rwpc13 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255918: Sat Sep 28 13:06:58 AEST 2013 root@rwpc13:/usr/obj/build/src/sys/RWPC13 i386


	
>Description:

pkg-version(8) usage shows [index] as its final and only non-option
argument.  It looks to me like pkg/version.c does not process this
argument at all but makes the assumption that use of the -I option
always means use an INDEX file in portsdir.

I'm hoping this is an oversight which might be fixed soon, and that I'll
be able to run reports like the following on systems that don't have a
ports tree - just like I could with pkg_version(1).

  pkg version -IvL '=' /path/to/current/INDEX

>How-To-Repeat:

rwpc13# cd /usr/ports
rwpc13# make fetchindex
/usr/ports/INDEX-9.bz2                        100% of 1711 kB   11 MBps 00m00s

rwpc13# pkg version -IvL '='
aalib-1.4.r5_6                     <   needs updating (index has 1.4.r5_8)
chromium-32.0.1700.77              <   needs updating (index has 32.0.1700.107)
docbook-xsl-1.76.1_1               <   needs updating (index has 1.76.1_2)
fusefs-libs-2.9.3_1                <   needs updating (index has 2.9.3_2)
nspluginwrapper-1.4.4_2            <   needs updating (index has 1.4.4_3)
p5-IO-Socket-IP-0.27               <   needs updating (index has 0.28)
p5-Module-Build-0.4203             <   needs updating (index has 0.4205)
qt4-moc-4.8.5                      <   needs updating (index has 4.8.5_1)
sqlite3-3.8.2_1                    <   needs updating (index has 3.8.3)
vte-0.26.2_5                       <   needs updating (index has 0.28.2)

rwpc13# mv INDEX-9 /var/tmp
rwpc13# pkg version -IvL '=' /var/tmp/INDEX-9
pkg: Unable to open /usr/ports/INDEX-9!: No such file or directory

rwpc13# cd ..
rwpc13# mv ports ports.hiding

rwpc13# pkg version -IvL '=' /var/tmp/INDEX-9
pkg: Unable to open ports directory /usr/ports: No such file or directory

>Fix:

	


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->portmgr 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Wed Feb 12 04:24:11 UTC 2014 
Responsible-Changed-Why:  
Over to maintainer (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=186671 

From: Baptiste Daroussin <bapt@freebsd.org>
To: bug-followup@freebsd.org, john.marshall@riverwillow.com.au
Cc:  
Subject: Re: ports/186671: ports-mgmt/pkg 1.2.6 pkg version ignores index argument
Date: Wed, 12 Feb 2014 08:31:36 +0100

 Why would you need an INDEX at all if you have no ports tree.
 
 I guess if you have no ports tree it means you are running your own
 repo. which means you can direct run pkg version against the
 repository without the need for an index at all.
 
 Bapt

From: John Marshall <john.marshall@riverwillow.com.au>
To: Baptiste Daroussin <bapt@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: ports/186671: ports-mgmt/pkg 1.2.6 pkg version ignores index
 argument
Date: Thu, 13 Feb 2014 17:30:32 +1100

 --H+4ONPRPur6+Ovig
 Content-Type: text/plain; charset=utf-8
 Content-Disposition: inline
 
 On Wed, 12 Feb 2014, 08:31 +0100, Baptiste Daroussin wrote:
 > I guess if you have no ports tree it means you are running your own
 > repo. which means you can direct run pkg version against the
 > repository without the need for an index at all.
 
 ...which is an obvious thing to do if the repository reflects the
 current ports tree.  If the repository, as in this case, is only built
 as necessary for upgrades, it will usually lag the current ports tree.
 
 I am not a programmer so it has taken me a long time to produce this
 patch which "works for me".  I am sorry if it doesn't do things in the
 right way but a programmer should be able to correct it easily.
 
 The patch:
 
  - removes the requirement for /usr/ports when using an index (-I)
 
  - reads and uses the optional index file argument which, if present,
    will supersede the default file in /usr/ports.
 
 --- pkg/version.c.orig	2014-02-02 05:33:30.000000000 +1100
 +++ pkg/version.c	2014-02-13 15:34:07.000000000 +1100
 @@ -318,7 +318,7 @@
  				opt |= VERSION_SOURCE_REMOTE;
  		}
  
 -		if (!have_ports && (opt & (VERSION_SOURCE_INDEX|VERSION_SOURCE_PORTS)))
 +		if (!have_ports && (opt & VERSION_SOURCE_PORTS))
  			err(1, "Unable to open ports directory %s", portsdir);
  
  		/* Only force remote mode if looking up remote, otherwise
 @@ -341,9 +341,13 @@
  			goto cleanup;
  
  		if (opt & VERSION_SOURCE_INDEX) {
 -			uname(&u);
 -			rel_major_ver = (int) strtol(u.release, NULL, 10);
 -			snprintf(indexpath, sizeof(indexpath), "%s/INDEX-%d", portsdir, rel_major_ver);
 +			if (argc == 1) {
 +				snprintf(indexpath, sizeof(indexpath), "%s", argv[0]);
 +			} else {
 +				uname(&u);
 +				rel_major_ver = (int) strtol(u.release, NULL, 10);
 +				snprintf(indexpath, sizeof(indexpath), "%s/INDEX-%d", portsdir, rel_major_ver);
 +			}
  			indexfile = fopen(indexpath, "r");
  			if (!indexfile)
  				err(EX_SOFTWARE, "Unable to open %s!", indexpath);
 
 I have attached a patch to the ports tree which provides this fix by
 adding the above patch into the port's files directory.
 
 -- 
 John Marshall
 
 --H+4ONPRPur6+Ovig
 Content-Type: text/x-diff; charset=utf-8
 Content-Disposition: attachment; filename="pkg-1.2.6_r344040.diff"
 
 Index: ports-mgmt/pkg/files/patch-pkg_version.c
 ===================================================================
 --- ports-mgmt/pkg/files/patch-pkg_version.c	(revision 0)
 +++ ports-mgmt/pkg/files/patch-pkg_version.c	(working copy)
 @@ -0,0 +1,28 @@
 +--- pkg/version.c.orig	2014-02-02 05:33:30.000000000 +1100
 ++++ pkg/version.c	2014-02-13 15:34:07.000000000 +1100
 +@@ -318,7 +318,7 @@
 + 				opt |= VERSION_SOURCE_REMOTE;
 + 		}
 + 
 +-		if (!have_ports && (opt & (VERSION_SOURCE_INDEX|VERSION_SOURCE_PORTS)))
 ++		if (!have_ports && (opt & VERSION_SOURCE_PORTS))
 + 			err(1, "Unable to open ports directory %s", portsdir);
 + 
 + 		/* Only force remote mode if looking up remote, otherwise
 +@@ -341,9 +341,13 @@
 + 			goto cleanup;
 + 
 + 		if (opt & VERSION_SOURCE_INDEX) {
 +-			uname(&u);
 +-			rel_major_ver = (int) strtol(u.release, NULL, 10);
 +-			snprintf(indexpath, sizeof(indexpath), "%s/INDEX-%d", portsdir, rel_major_ver);
 ++			if (argc == 1) {
 ++				snprintf(indexpath, sizeof(indexpath), "%s", argv[0]);
 ++			} else {
 ++				uname(&u);
 ++				rel_major_ver = (int) strtol(u.release, NULL, 10);
 ++				snprintf(indexpath, sizeof(indexpath), "%s/INDEX-%d", portsdir, rel_major_ver);
 ++			}
 + 			indexfile = fopen(indexpath, "r");
 + 			if (!indexfile)
 + 				err(EX_SOFTWARE, "Unable to open %s!", indexpath);
 
 Property changes on: ports-mgmt/pkg/files/patch-pkg_version.c
 ___________________________________________________________________
 Added: svn:mime-type
 ## -0,0 +1 ##
 +text/plain
 \ No newline at end of property
 Added: fbsd:nokeywords
 ## -0,0 +1 ##
 +yes
 \ No newline at end of property
 Added: svn:eol-style
 ## -0,0 +1 ##
 +native
 \ No newline at end of property
 
 --H+4ONPRPur6+Ovig--

From: John Marshall <john.marshall@riverwillow.com.au>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: ports/186671: ports-mgmt/pkg 1.2.6 pkg version ignores index
 argument
Date: Sat, 15 Feb 2014 21:03:52 +1100

 --OXfL5xGRrasGEqWY
 Content-Type: text/plain; charset=utf-8
 Content-Disposition: inline
 
 My previous patch worked fine with the '-I' option.  I disovered, after
 the Friday night periodic weekly jobs had run, that the new weekly
 400.status-pkg job didn't give me the expected result.  It turns out
 that this job passes the index file argument without setting -I.  The
 original pkg_install version of this job does the same thing.
 
 I checked the old pkg_version code and saw that it uses the index
 argument (with no -I option) as a fallback if it cannot find a ports
 tree.  I have attached a new patch for pkg/version.c to restore this
 functionality.  With the attached patch, the version source selection
 precedence, if not overridden by any of (-IPR), is as follows:
 
  - use ports tree if present
  - fall back to index if index argument is present and file readable
  - fall back to remote repository
 
 In the absence of an index file argument, the precedence is unaltered:
 
  - use ports tree if present
  - fall back to remote repository
 
 No doubt a programmer would find a more elegant way of doing this.  I
 have tried my best.
 
 -- 
 John Marshall
 
 --OXfL5xGRrasGEqWY
 Content-Type: text/x-diff; charset=utf-8
 Content-Disposition: attachment; filename="pkg_r344328.diff"
 
 Index: ports-mgmt/pkg/files/patch-pkg_version.c
 ===================================================================
 --- ports-mgmt/pkg/files/patch-pkg_version.c	(revision 0)
 +++ ports-mgmt/pkg/files/patch-pkg_version.c	(working copy)
 @@ -0,0 +1,68 @@
 +--- pkg/version.c.orig	2014-02-02 05:33:30.000000000 +1100
 ++++ pkg/version.c	2014-02-15 15:11:37.000000000 +1100
 +@@ -167,6 +167,7 @@
 + 	const char *reponame = NULL;
 + 	const char *version_remote = NULL;
 + 	bool have_ports;
 ++	bool use_arg_index;
 + 	bool auto_update;
 + 	match_t match = MATCH_ALL;
 + 	char *pattern=NULL;
 +@@ -309,16 +310,39 @@
 + 
 + 		have_ports = (stat(portsdirmakefile, &sb) == 0 && S_ISREG(sb.st_mode));
 + 
 +-		/* If none of -IPR were specified, and portsdir exists use that,
 +-		   otherwise fallback to remote. */
 ++		/*
 ++		 * If an index file name has been passed, and neither -P
 ++		 * nor -R were specified, try to use it.  If -I was
 ++		 * specified, a bad index filename is fatal.
 ++		 */
 ++		if (argc == 1 && (opt & (VERSION_SOURCE_PORTS|VERSION_SOURCE_REMOTE)) == 0) {
 ++			snprintf(indexpath, sizeof(indexpath), "%s", argv[0]);
 ++			if (stat(indexpath, &sb) == 0 && S_ISREG(sb.st_mode))
 ++				use_arg_index = true;
 ++			else if (opt & VERSION_SOURCE_INDEX)
 ++				err(1, "Cannot use index %s", indexpath);
 ++			else {
 ++				warn("Ignoring index %s", indexpath);
 ++				use_arg_index = false;
 ++			}
 ++		} else
 ++			use_arg_index = false;
 ++
 ++		/*
 ++		 * If none of -IPR were specified, and portsdir exists use that,
 ++		 * otherwise fallback to remote unless the index file argument
 ++		 * is present and that index file exists.
 ++		 */
 + 		if ((opt & (VERSION_SOURCE_PORTS|VERSION_SOURCE_REMOTE|VERSION_SOURCE_INDEX)) == 0) {
 + 			if (have_ports)
 + 				opt |= VERSION_SOURCE_PORTS;
 ++			else if (use_arg_index)
 ++				opt |= VERSION_SOURCE_INDEX;
 + 			else
 + 				opt |= VERSION_SOURCE_REMOTE;
 + 		}
 + 
 +-		if (!have_ports && (opt & (VERSION_SOURCE_INDEX|VERSION_SOURCE_PORTS)))
 ++		if (!have_ports && (opt & VERSION_SOURCE_PORTS))
 + 			err(1, "Unable to open ports directory %s", portsdir);
 + 
 + 		/* Only force remote mode if looking up remote, otherwise
 +@@ -341,9 +365,11 @@
 + 			goto cleanup;
 + 
 + 		if (opt & VERSION_SOURCE_INDEX) {
 +-			uname(&u);
 +-			rel_major_ver = (int) strtol(u.release, NULL, 10);
 +-			snprintf(indexpath, sizeof(indexpath), "%s/INDEX-%d", portsdir, rel_major_ver);
 ++			if (!use_arg_index) {
 ++				uname(&u);
 ++				rel_major_ver = (int) strtol(u.release, NULL, 10);
 ++				snprintf(indexpath, sizeof(indexpath), "%s/INDEX-%d", portsdir, rel_major_ver);
 ++			}
 + 			indexfile = fopen(indexpath, "r");
 + 			if (!indexfile)
 + 				err(EX_SOFTWARE, "Unable to open %s!", indexpath);
 
 Property changes on: ports-mgmt/pkg/files/patch-pkg_version.c
 ___________________________________________________________________
 Added: svn:mime-type
 ## -0,0 +1 ##
 +text/plain
 \ No newline at end of property
 Added: fbsd:nokeywords
 ## -0,0 +1 ##
 +yes
 \ No newline at end of property
 Added: svn:eol-style
 ## -0,0 +1 ##
 +native
 \ No newline at end of property
 
 --OXfL5xGRrasGEqWY--

From: Mario Pavlov <mario.g.pavlov@gmail.com>
To: bug-followup@FreeBSD.org, john.marshall@riverwillow.com.au
Cc:  
Subject: Re: ports/186671: ports-mgmt/pkg 1.2.6 pkg version ignores index argument
Date: Sat, 22 Mar 2014 15:14:48 +0200

 --001a11c2a24072dc5f04f531c95a
 Content-Type: multipart/alternative; boundary=001a11c2a24072dc5c04f531c958
 
 --001a11c2a24072dc5c04f531c958
 Content-Type: text/plain; charset=ISO-8859-1
 
 Hi,
 I would like to propose a slightly different fix.
 
 The pkg version man page clearly indicates what are the defaults when
 running
 
 pkg version
 
 and how these defaults are overridden. Based on that I think it is OK to
 leave the old pkg-version behaviour and have pkgng ignore the index file
 unless -I is specified.
 
 Please find attached a patch that addresses the issue of pkg version
 ignoring the user specified index file.
 
 --001a11c2a24072dc5c04f531c958
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 <div dir=3D"ltr"><div>Hi,<br>I would like to propose a slightly different f=
 ix.<br><br></div><div>The pkg version man page clearly indicates what are t=
 he defaults when running<br><br></div><div>pkg version<br><br></div><div>an=
 d how these defaults are overridden. Based on that I think it is OK to leav=
 e the old pkg-version behaviour and have pkgng ignore the index file unless=
  -I is specified.<br>
 <br></div><div>Please find attached a patch that addresses the issue of pkg=
  version ignoring the user specified index file.<br><br><br></div></div>
 
 --001a11c2a24072dc5c04f531c958--
 --001a11c2a24072dc5f04f531c95a
 Content-Type: text/plain; charset=US-ASCII; name="pkg-version.patch.txt"
 Content-Disposition: attachment; filename="pkg-version.patch.txt"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_ht2x2d8f0
 
 ZGlmZiAtLWdpdCBhL3NyYy92ZXJzaW9uLmMgYi9zcmMvdmVyc2lvbi5jCmluZGV4IDY2MGVhODMu
 LmE2YTE4MGMgMTAwNjQ0Ci0tLSBhL3NyYy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