Synch with main sources:

Changes by hubertf and seb; these changes tested on NetBSD, Linux and Irix.

Modified Files:
	src/usr.sbin/pkg_install/add: perform.c pkg_add.1

Log Message:
Implement remaining TODO item in pkg upgrade (pkg_add -u):
* Upgrade step 1/4: Check if the new version is ok with all pkgs
* (from +REQUIRED_BY) that require this pkg

Inspired by bsd.pkg.mk's upgrade(?) target.

Modified Files:
	src/usr.sbin/pkg_install/admin: main.c
	src/usr.sbin/pkg_install/info: main.c perform.c

Log Message:
Consistently check findmatchingname() return value for error condition.
Among other this fixes 'pkg_info -e whateverpkg' exit status when
/var/db/pkg is missing: it is now 1 and not 0.

Modified Files:
	src/usr.sbin/pkg_install/lib: version.h

Log Message:
Bump to "20030325" after today's changes from seb and me
This commit is contained in:
jschauma 2003-03-29 18:41:56 +00:00
parent 4422c0cce3
commit 43f0484488
7 changed files with 126 additions and 32 deletions

View file

@ -1,4 +1,4 @@
/* $NetBSD: perform.c,v 1.3 2003/01/14 15:18:32 jschauma Exp $ */
/* $NetBSD: perform.c,v 1.4 2003/03/29 18:41:56 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
@ -6,7 +6,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp";
#else
__RCSID("$NetBSD: perform.c,v 1.3 2003/01/14 15:18:32 jschauma Exp $");
__RCSID("$NetBSD: perform.c,v 1.4 2003/03/29 18:41:56 jschauma Exp $");
#endif
#endif
#endif
@ -330,18 +330,6 @@ pkg_do(const char *pkg)
(int)(s - PkgName) + 1, PkgName);
if (findmatchingname(dbdir, buf, note_whats_installed, installed) > 0) {
if (upgrade) {
/*
* Upgrade step 1/4: Check if the new version is ok with all pkgs
* that require this pkg
*/
/* TODO */
/*
* Upgrade step 2/4: Do the actual update by moving aside
* the +REQUIRED_BY file, deinstalling the old pkg, adding
* the new one and moving the +REQUIRED_BY file back
* into place (finished in step 3/4)
*/
snprintf(upgrade_from, sizeof(upgrade_from), "%s/%s/" REQUIRED_BY_FNAME,
dbdir, installed);
snprintf(upgrade_via, sizeof(upgrade_via), "%s/.%s." REQUIRED_BY_FNAME,
@ -353,6 +341,104 @@ pkg_do(const char *pkg)
printf("Upgrading %s to %s.\n", installed, PkgName);
if (fexists(upgrade_from)) { /* Are there any dependencies? */
/*
* Upgrade step 1/4: Check if the new version is ok with all pkgs
* (from +REQUIRED_BY) that require this pkg
*/
FILE *rb; /* +REQUIRED_BY file */
char pkg2chk[FILENAME_MAX];
rb = fopen(upgrade_from, "r");
if (! rb) {
warnx("Cannot open '%s' for reading%s", upgrade_from,
Force ? " (proceeding anyways)" : "");
if (Force)
goto ignore_upgrade_depends_check;
else
goto bomb;
}
while (fgets(pkg2chk, sizeof(pkg2chk), rb)) {
package_t depPlist;
FILE *depf;
plist_t *depp;
char depC[FILENAME_MAX];
s = strrchr(pkg2chk, '\n');
if (s)
*s = '\0'; /* strip trailing '\n' */
/*
* step into pkg2chk, read it's +CONTENTS file and see if
* all @pkgdep lines agree with PkgName (using pmatch())
*/
snprintf(depC, sizeof(depC), "%s/%s/%s", dbdir, pkg2chk, CONTENTS_FNAME);
depf = fopen(depC , "r");
if (depf == NULL) {
warnx("Cannot check depends in '%s'%s", depC,
Force ? " (proceeding anyways)" : "!" );
if (Force)
goto ignore_upgrade_depends_check;
else
goto bomb;
}
read_plist(&depPlist, depf);
fclose(depf);
for (depp = depPlist.head; depp; depp = depp->next) {
char base_new[FILENAME_MAX];
char base_exist[FILENAME_MAX];
char *s2;
if (depp->type != PLIST_PKGDEP)
continue;
/* Prepare basename (no versions) of both pkgs,
* to see if we want to compare against that
* one at all.
*/
strcpy(base_new, PkgName);
s2 = strpbrk(base_new, "<>[]?*{");
if (s2)
*s2 = '\0';
else {
s2 = strrchr(base_new, '-');
if (s2)
*s2 = '\0';
}
strcpy(base_exist, depp->name);
s2 = strpbrk(base_exist, "<>[]?*{");
if (s2)
*s2 = '\0';
else {
s2 = strrchr(base_exist, '-');
if (s2)
*s2 = '\0';
}
if (strcmp(base_new, base_exist) == 0) {
/* Same pkg, so do the interesting compare */
if (pmatch(depp->name, PkgName)) {
if (Verbose)
printf("@pkgdep check: %s is ok for %s (in %s pkg)\n",
PkgName, depp->name, pkg2chk);
} else {
printf("Package %s requires %s, \n\tCannot perform upgrade to %s%s\n",
pkg2chk, depp->name, PkgName,
Force? " (proceeding anyways)" : "!");
if (! Force)
goto bomb;
}
}
}
}
fclose(rb);
ignore_upgrade_depends_check:
/*
* Upgrade step 2/4: Do the actual update by moving aside
* the +REQUIRED_BY file, deinstalling the old pkg, adding
* the new one and moving the +REQUIRED_BY file back
* into place (finished in step 3/4)
*/
if (Verbose)
printf("mv %s %s\n", upgrade_from, upgrade_via);
rc = rename(upgrade_from, upgrade_via);

View file

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_add.1,v 1.1.1.1 2002/12/20 18:13:57 schmonz Exp $
.\" $NetBSD: pkg_add.1,v 1.2 2003/03/29 18:41:56 jschauma Exp $
.\"
.\" FreeBSD install - a package for the installation and maintainance
.\" of non-core utilities.
@ -271,9 +271,11 @@ option is not given.
If the
.Fl u
option is given, it's assumed the package should be upgraded instead.
This is prepared by moving an existing
Before doing so, all packages that depend on the pkg being upgraded
are checked if they also work with the new version. If that test is
successful, the upgrade is prepared by moving an existing
.Pa +REQUIRED_BY
file aside (if it exists), and by running
file aside (if it exists), and running
.Xr pkg_delete 1
on the installed package.
Installation then proceeds as if the package

View file

@ -1,9 +1,9 @@
/* $NetBSD: main.c,v 1.6 2003/03/16 19:44:09 jschauma Exp $ */
/* $NetBSD: main.c,v 1.7 2003/03/29 18:41:56 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: main.c,v 1.6 2003/03/16 19:44:09 jschauma Exp $");
__RCSID("$NetBSD: main.c,v 1.7 2003/03/29 18:41:56 jschauma Exp $");
#endif
#endif
@ -421,7 +421,7 @@ main(int argc, char *argv[])
while (*argv != NULL) {
if (ispkgpattern(*argv)) {
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, checkpattern_fn, NULL) == 0)
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, checkpattern_fn, NULL) <= 0)
errx(EXIT_FAILURE, "No matching pkg for %s.", *argv);
} else {
rc = chdir(*argv);

View file

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $ */
/* $NetBSD: main.c,v 1.3 2003/03/29 18:41:56 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
@ -6,7 +6,7 @@
#if 0
static char *rcsid = "from FreeBSD Id: main.c,v 1.14 1997/10/08 07:47:26 charnier Exp";
#else
__RCSID("$NetBSD: main.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $");
__RCSID("$NetBSD: main.c,v 1.3 2003/03/29 18:41:56 jschauma Exp $");
#endif
#endif
#endif
@ -253,7 +253,7 @@ main(int argc, char **argv)
errx(EXIT_FAILURE, "No matching pkg for %s.", *argv);
} else {
if (ispkgpattern(*argv)) {
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, add_to_list_fn, &pkgs) == 0)
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, add_to_list_fn, &pkgs) <= 0)
errx(EXIT_FAILURE, "No matching pkg for %s.", *argv);
} else {
lpp = alloc_lpkg(*argv);

View file

@ -1,4 +1,4 @@
/* $NetBSD: perform.c,v 1.6 2003/03/16 19:44:09 jschauma Exp $ */
/* $NetBSD: perform.c,v 1.7 2003/03/29 18:41:56 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
@ -6,7 +6,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp";
#else
__RCSID("$NetBSD: perform.c,v 1.6 2003/03/16 19:44:09 jschauma Exp $");
__RCSID("$NetBSD: perform.c,v 1.7 2003/03/29 18:41:56 jschauma Exp $");
#endif
#endif
#endif
@ -145,7 +145,7 @@ pkg_do(char *pkg)
char try[FILENAME_MAX];
snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkg);
if (findmatchingname(_pkgdb_getPKGDB_DIR(), try,
add_to_list_fn, &pkgs) != 0) {
add_to_list_fn, &pkgs) > 0) {
return 0; /* we've just appended some names to the pkgs list,
* they will be processed after this package. */
}
@ -293,7 +293,11 @@ CheckForPkg(char *pkgspec, char *dbdir)
if (strpbrk(pkgspec, "<>[]?*{")) {
/* expensive (pattern) match */
return !findmatchingname(dbdir, pkgspec, foundpkg, dbdir);
error = findmatchingname(dbdir, pkgspec, foundpkg, dbdir);
if (error == -1)
return 1;
else
return !error;
}
/* simple match */
(void) snprintf(buf, sizeof(buf), "%s/%s", dbdir, pkgspec);
@ -306,7 +310,7 @@ CheckForPkg(char *pkgspec, char *dbdir)
char try[FILENAME_MAX];
snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkgspec);
if (findmatchingname(dbdir, try, foundpkg, dbdir) != 0) {
if (findmatchingname(dbdir, try, foundpkg, dbdir) > 0) {
error = 0;
}
}

View file

@ -1,9 +1,9 @@
/* $NetBSD: pkgdb.c,v 1.8 2003/03/16 19:44:10 jschauma Exp $ */
/* $NetBSD: pkgdb.c,v 1.9 2003/03/29 18:41:57 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: pkgdb.c,v 1.8 2003/03/16 19:44:10 jschauma Exp $");
__RCSID("$NetBSD: pkgdb.c,v 1.9 2003/03/29 18:41:57 jschauma Exp $");
#endif
#endif
@ -183,6 +183,7 @@ pkgdb_retrieve(const char *key)
void
pkgdb_dump(void)
{
#if defined(HAVE_DBOPEN)
DBT key;
DBT val;
int type;
@ -195,6 +196,7 @@ pkgdb_dump(void)
}
pkgdb_close();
}
#endif
}
/*

View file

@ -1,4 +1,4 @@
/* $NetBSD: version.h,v 1.5 2003/03/16 19:44:10 jschauma Exp $ */
/* $NetBSD: version.h,v 1.6 2003/03/29 18:41:57 jschauma Exp $ */
/*
* Copyright (c) 2001 Thomas Klausner. All rights reserved.
@ -33,6 +33,6 @@
#ifndef _INST_LIB_VERSION_H_
#define _INST_LIB_VERSION_H_
#define PKGTOOLS_VERSION "20030315"
#define PKGTOOLS_VERSION "20030325"
#endif /* _INST_LIB_VERSION_H_ */