Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Reorder the priorities for choosing the what to compare the installed package set against, when not explicitly specified.
Matthew Seaman committed 12 years ago
commit 7fdc14b0f9ac0630f206b96b1b1081f61e89c0ac
parent e689e05
2 files changed +68 -27
modified docs/pkg-version.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd April 18, 2014
+
.Dd April 26, 2014
.Dt PKG-VERSION 8
.Os
.Sh NAME
@@ -40,13 +40,21 @@
is used for generating a report of packages installed by
.Xr pkg 8 .
.Pp
-
By default, if a ports tree exists it is used to compare versions.
-
If it does not exist, the remote repository catalogue is used.
-
These defaults can be overridden by specifying one of
+
The database of available packages and versions to compare against the
+
installed packages may be chosen by specifying one of
.Fl P ,
.Fl R
or
.Fl I .
+
If not specified then the ports index file
+
will be used if it exists
+
.Fl ( I ) .
+
Otherwise, should a ports tree exist that will be used to compare
+
versions
+
.Fl ( P ) .
+
Failing either of those two choices, the repository catalogue will be
+
used
+
.Fl ( R ) .
.Pp
When
.Fl I
@@ -114,15 +122,18 @@ file for determining if a package is out of date.
If no
.Pa index
file name is specified, uses the default index file.
+
This is the default, if the index file exists.
.It Fl P
Use ports for determining if a package is out of date.
-
This is the default if a ports tree exists.
+
This is the default if the index file is not present and a ports tree
+
exists.
The tree used can be overridden by PORTSDIR, see
.Xr pkg 5
for more information.
.It Fl R
Use repository catalogue for determining if a package is out of date.
-
This is the default if no ports tree exists.
+
This is the default if neither the ports index nor the ports tree
+
exists.
.It Fl U
Suppress the automatic update of the local copy of the repository catalogue
from remote.
@@ -232,9 +243,9 @@ relative to that directory.
If
.Ev INDEXFILE
is not set, the default file name is
-
.Pa INDEX- Sy N
+
.Pa INDEX-N
where
-
.Sy N
+
.Cm N
is the OS major version number.
.Sh FILES
See
modified src/version.c
@@ -340,33 +340,46 @@ free_index(struct index_entry *indexhead)
	return;
}

+
static bool
+
have_indexfile(const char **indexfile, char *filebuf, size_t filebuflen,
+
	       int argc, char ** restrict argv)
+
{
+
	bool		have_indexfile = true;
+
	struct stat	sb;
+

+
	/* If there is a remaining command line argument, take
+
	   that as the name of the INDEX file to use.  Otherwise,
+
	   search for INDEX-N within the ports tree */
+

+
	if (argc == 0)
+
		*indexfile = indexfilename(filebuf, filebuflen);
+
	else
+
		*indexfile = argv[0];
+

+
	if (stat(*indexfile, &sb) == -1) {
+
		have_indexfile = false;
+
		warn("Can't access %s", *indexfile);
+
	}
+
	
+
	return (have_indexfile);
+
}
+

static int
do_source_index(unsigned int opt, char limchar, char *pattern, match_t match,
-
		int argc, char ** restrict argv, const char *matchorigin)
+
	        const char *matchorigin, const char *indexfile)
{
-
	char			 filebuf[MAXPATHLEN];
	struct index_entry	*indexhead;
	struct index_entry	*entry;
	struct pkgdb		*db = NULL;
	struct pkgdb_it		*it = NULL;
	struct pkg		*pkg = NULL;
-
	const char		*indexfile;
	const char		*origin;

-
	if ( (opt & VERSION_SOURCES) != VERSION_SOURCE_INDEX || argc > 1 ) {
+
	if ( (opt & VERSION_SOURCES) != VERSION_SOURCE_INDEX) {
		usage_version();
		return (EX_USAGE);
	}

-
	/* If there is a remaining command line argument, take
-
	   that as the name of the INDEX file to use.  Otherwise,
-
	   search for INDEX-N within the ports tree */
-

-
	if (argc == 0)
-
		indexfile = indexfilename(filebuf, sizeof(filebuf));
-
	else
-
		indexfile = argv[0];
-

	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
		return (EX_IOERR);

@@ -651,6 +664,8 @@ exec_version(int argc, char **argv)
	const char	*matchorigin = NULL;
	const char	*reponame = NULL;
	const char	*portsdir;
+
	const char	*indexfile;
+
	char		 filebuf[MAXPATHLEN];
	bool		 auto_update;
	match_t		 match = MATCH_ALL;
	char		*pattern = NULL;
@@ -758,9 +773,19 @@ exec_version(int argc, char **argv)
		}
	}

-
	if ( (opt & VERSION_SOURCE_INDEX) == VERSION_SOURCE_INDEX )
-
		return (do_source_index(opt, limchar, pattern, match,
-
			    argc, argv, matchorigin));
+
	if (argc > 1) {
+
		usage_version();
+
		return (EX_USAGE);
+
	}
+

+
	if ( (opt & VERSION_SOURCE_INDEX) == VERSION_SOURCE_INDEX ) {
+
		if (!have_indexfile(&indexfile, filebuf, sizeof(filebuf),
+
                         argc, argv))
+
			return (EX_SOFTWARE);
+
		else
+
			return (do_source_index(opt, limchar, pattern, match,
+
				    matchorigin, indexfile));
+
	}

	if ( (opt & VERSION_SOURCE_REMOTE) == VERSION_SOURCE_REMOTE )
		return (do_source_remote(opt, limchar, pattern, match,
@@ -774,10 +799,15 @@ exec_version(int argc, char **argv)
				    match, matchorigin, portsdir));
	}

-
	/* If none of -IPR were specified, and portsdir exists use
-
	   that, otherwise fallback to remote. */
+
	/* If none of -IPR were specified, and INDEX exists use that.
+
	   Failing that, if portsdir exists and is valid, use that
+
	   (slow) otherwise fallback to remote. */

-
	if (have_ports(&portsdir)) {
+
	if (have_indexfile(&indexfile, filebuf, sizeof(filebuf), argc, argv)) {
+
		opt |= VERSION_SOURCE_INDEX;
+
		return (do_source_index(opt, limchar, pattern, match,
+
			    matchorigin, indexfile));
+
	} else if (have_ports(&portsdir)) {
		opt |= VERSION_SOURCE_PORTS;
		return (do_source_ports(opt, limchar, pattern, match,
			    matchorigin, portsdir));