Add -u switch to pkg_add to do a very rudimentare form of pkg upgrading:
When invoked with 'pkg_add -u ...', and the package to be installed is found already being installed, the old (installed) package is removed with pkg_delete, and the new one is installed. A very crude handling of dependencies is done (by moving the +REQUIRED_BY file aside before pkg_delete, and back into place after the new pkg is installed). This needs a lot more work to TRT, but it's a first start.
This commit is contained in:
parent
1fae55f3ae
commit
648fa44a28
@ -1,11 +1,11 @@
|
||||
/* $NetBSD: main.c,v 1.18 2001/03/05 16:53:13 wiz Exp $ */
|
||||
/* $NetBSD: main.c,v 1.19 2001/03/18 03:20:28 hubertf Exp $ */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char *rcsid = "from FreeBSD Id: main.c,v 1.16 1997/10/08 07:45:43 charnier Exp";
|
||||
#else
|
||||
__RCSID("$NetBSD: main.c,v 1.18 2001/03/05 16:53:13 wiz Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.19 2001/03/18 03:20:28 hubertf Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -35,7 +35,7 @@ __RCSID("$NetBSD: main.c,v 1.18 2001/03/05 16:53:13 wiz Exp $");
|
||||
#include "lib.h"
|
||||
#include "add.h"
|
||||
|
||||
static char Options[] = "hVvIRfnp:SMt:";
|
||||
static char Options[] = "hVvIRfnp:SMt:u";
|
||||
|
||||
char *Prefix = NULL;
|
||||
Boolean NoInstall = FALSE;
|
||||
@ -48,12 +48,13 @@ char *PkgName = NULL;
|
||||
char *Directory = NULL;
|
||||
char FirstPen[FILENAME_MAX];
|
||||
add_mode_t AddMode = NORMAL;
|
||||
int upgrade = 0;
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "%s\n%s\n",
|
||||
"usage: pkg_add [-hVvInfRMS] [-t template] [-p prefix]",
|
||||
"usage: pkg_add [-hVvInfRMSu] [-t template] [-p prefix]",
|
||||
" pkg-name [pkg-name ...]");
|
||||
exit(1);
|
||||
}
|
||||
@ -110,6 +111,9 @@ main(int argc, char **argv)
|
||||
show_version();
|
||||
/* NOTREACHED */
|
||||
|
||||
case 'u':
|
||||
upgrade = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
|
@ -1,11 +1,11 @@
|
||||
/* $NetBSD: perform.c,v 1.56 2000/12/13 03:17:53 hubertf Exp $ */
|
||||
/* $NetBSD: perform.c,v 1.57 2001/03/18 03:20:28 hubertf Exp $ */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#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.56 2000/12/13 03:17:53 hubertf Exp $");
|
||||
__RCSID("$NetBSD: perform.c,v 1.57 2001/03/18 03:20:28 hubertf Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -29,6 +29,7 @@ __RCSID("$NetBSD: perform.c,v 1.56 2000/12/13 03:17:53 hubertf Exp $");
|
||||
*
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include "lib.h"
|
||||
#include "add.h"
|
||||
@ -83,6 +84,10 @@ pkg_do(char *pkg)
|
||||
char pkg_fullname[FILENAME_MAX];
|
||||
char playpen[FILENAME_MAX];
|
||||
char extract_contents[FILENAME_MAX];
|
||||
char upgrade_from[FILENAME_MAX];
|
||||
char upgrade_via[FILENAME_MAX];
|
||||
char upgrade_to[FILENAME_MAX];
|
||||
int upgrading = 0;
|
||||
char *where_to, *tmp, *extract;
|
||||
char *dbdir;
|
||||
FILE *cfile;
|
||||
@ -90,6 +95,7 @@ pkg_do(char *pkg)
|
||||
plist_t *p;
|
||||
struct stat sb;
|
||||
int inPlace;
|
||||
int rc;
|
||||
|
||||
code = 0;
|
||||
zapLogDir = 0;
|
||||
@ -152,7 +158,7 @@ pkg_do(char *pkg)
|
||||
return 1;
|
||||
|
||||
if ((strstr(pkg, ".tgz") != NULL) || (strstr(pkg, ".tbz") != NULL)) {
|
||||
/* There already is a ".tgz" - give up
|
||||
/* There already is a ".t[bg]z" - give up
|
||||
* (We don't want to pretend to be exceedingly
|
||||
* clever - the user should give something sane!)
|
||||
*/
|
||||
@ -325,9 +331,35 @@ pkg_do(char *pkg)
|
||||
(void) snprintf(buf, sizeof(buf), "%.*s[0-9]*",
|
||||
(int)(s - PkgName) + 1, PkgName);
|
||||
if (findmatchingname(dbdir, buf, note_whats_installed, installed) > 0) {
|
||||
warnx("other version '%s' already installed", installed);
|
||||
code = 1;
|
||||
goto success; /* close enough for government work */
|
||||
if (upgrade) {
|
||||
snprintf(upgrade_from, sizeof(upgrade_from), "%s/%s/" REQUIRED_BY_FNAME,
|
||||
dbdir, installed);
|
||||
snprintf(upgrade_via, sizeof(upgrade_via), "%s/.%s." REQUIRED_BY_FNAME,
|
||||
dbdir, installed);
|
||||
snprintf(upgrade_to, sizeof(upgrade_to), "%s/%s/" REQUIRED_BY_FNAME,
|
||||
dbdir, PkgName);
|
||||
|
||||
if (Verbose)
|
||||
printf("Upgrading %s to %s.\n", installed, PkgName);
|
||||
|
||||
if (fexists(upgrade_from)) {
|
||||
if (0 && Verbose)
|
||||
printf("HF: mv %s %s\n", upgrade_from, upgrade_via);
|
||||
rc = rename(upgrade_from, upgrade_via);
|
||||
assert(rc == 0);
|
||||
|
||||
if (0 && Verbose)
|
||||
printf("HF: pkg_delete '%s'\n", installed);
|
||||
vsystem("pkg_delete '%s'\n", installed);
|
||||
|
||||
upgrading = 1;
|
||||
}
|
||||
} else {
|
||||
warnx("other version '%s' already installed", installed);
|
||||
|
||||
code = 1;
|
||||
goto success; /* close enough for government work */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -391,6 +423,14 @@ pkg_do(char *pkg)
|
||||
if (findmatchingname(dbdir, buf, note_whats_installed, installed) > 0) {
|
||||
warnx("pkg `%s' required, but `%s' found installed.",
|
||||
p->name, installed);
|
||||
|
||||
if (upgrading) {
|
||||
printf("HF: upgrade note -- could 'pkg_delete %s', and let the normal\n"
|
||||
"dependency handling reinstall the updated package, assuming one IS\n"
|
||||
"available. But then I'd expect proper binary pkgs being available for\n"
|
||||
"the upgrade case.\n", installed);
|
||||
}
|
||||
|
||||
if (Force) {
|
||||
warnx("Proceeding anyways.");
|
||||
} else {
|
||||
@ -713,6 +753,12 @@ success:
|
||||
/* delete the packing list contents */
|
||||
free_plist(&Plist);
|
||||
leave_playpen(Home);
|
||||
|
||||
if (upgrading) {
|
||||
rc = rename(upgrade_via, upgrade_to);
|
||||
assert(rc == 0);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: pkg_add.1,v 1.23 2001/03/13 18:25:30 hubertf Exp $
|
||||
.\" $NetBSD: pkg_add.1,v 1.24 2001/03/18 03:20:28 hubertf Exp $
|
||||
.\"
|
||||
.\" FreeBSD install - a package for the installation and maintainance
|
||||
.\" of non-core utilities.
|
||||
@ -22,10 +22,10 @@
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm pkg_add
|
||||
.Nd a utility for installing software package distributions
|
||||
.Nd a utility for installing and upgrading software package distributions
|
||||
.Sh SYNOPSIS
|
||||
.Nm ""
|
||||
.Op Fl fIMnRSVv
|
||||
.Op Fl fIMnRSuVv
|
||||
.Bk -words
|
||||
.Op Fl t Ar template
|
||||
.Ek
|
||||
@ -36,8 +36,8 @@
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
command is used to extract packages that have been previously created
|
||||
with the
|
||||
command is used to extract and upgrade packages that have been
|
||||
previously created with the
|
||||
.Xr pkg_create 1
|
||||
command.
|
||||
Packages are prepared collections of pre-built binaries, documentation,
|
||||
@ -224,7 +224,19 @@ of the package:
|
||||
A check is made to determine if the package or another version of it
|
||||
is already recorded as installed.
|
||||
If it is,
|
||||
installation is terminated.
|
||||
installation is terminated if the
|
||||
.Fl u
|
||||
option is not given.
|
||||
.Pp
|
||||
If the
|
||||
.Fl u
|
||||
option is given, it's assumed the package should be upgraded instead.
|
||||
This is prepared by moving an existing
|
||||
.Pa +REQUIRED_BY
|
||||
file aside (if it exists), and by running
|
||||
.Xr pkg_delete 1
|
||||
on the installed package. Installation then procedes as if the package
|
||||
was not installed.
|
||||
.It
|
||||
A check is made to determine if the package conflicts (from
|
||||
.Cm @pkgcfl
|
||||
@ -345,7 +357,12 @@ file
|
||||
.Pa /var/db/pkg/
|
||||
path shown above).
|
||||
.It
|
||||
Finally, the staging area is deleted and the program terminates.
|
||||
The staging area is deleted and the program terminates.
|
||||
.It
|
||||
Finally, if we were upgrading a package, any
|
||||
.Pa +REQUIRED_BY
|
||||
file that was moved aside before upgrading was started is now moved
|
||||
back into place.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
@ -397,7 +414,7 @@ Initial work and ongoing development.
|
||||
refinements.
|
||||
.It "Hubert Feyrer"
|
||||
.Nx
|
||||
wildcard dependency processing, pkgdb, etc.
|
||||
wildcard dependency processing, pkgdb, upgrading, etc.
|
||||
.El
|
||||
.Sh BUGS
|
||||
Hard links between files in a distribution are only preserved if either
|
||||
@ -413,4 +430,6 @@ invocations due to exec argument-space limitations--this depends on the
|
||||
value returned by
|
||||
.Fn sysconf _SC_ARG_MAX ) .
|
||||
.Pp
|
||||
Pkg upgrading needs a lot more work to be really universal.
|
||||
.Pp
|
||||
Sure to be others.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: lib.h,v 1.32 2001/03/05 16:53:14 wiz Exp $ */
|
||||
/* $NetBSD: lib.h,v 1.33 2001/03/18 03:20:29 hubertf Exp $ */
|
||||
|
||||
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
|
||||
|
||||
@ -256,5 +256,6 @@ int pkg_perform(lpkg_head_t *);
|
||||
extern Boolean Verbose;
|
||||
extern Boolean Fake;
|
||||
extern Boolean Force;
|
||||
extern int upgrade;
|
||||
|
||||
#endif /* _INST_LIB_LIB_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user