NetBSD Problem Report #21095

Received: (qmail 2576 invoked by uid 605); 11 Apr 2003 17:41:21 -0000
Message-Id: <19814-1050082877@rainier.reedmedia.net>
Date: Fri, 11 Apr 2003 10:41:17 -0700
From: reed@reedmedia.net
Sender: gnats-bugs-owner@netbsd.org
Reply-To: reed@reedmedia.net
To: gnats-bugs@gnats.netbsd.org
Subject: pkg_add upgrade in place (diff included)
X-Send-Pr-Version: 3.95

>Number:         21095
>Category:       pkg
>Synopsis:       allow pkg_add to upgrade without pkg_delete first
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    joerg
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Apr 11 17:42:01 +0000 2003
>Closed-Date:    Sun May 01 05:48:31 +0000 2016
>Last-Modified:  Sun May 01 05:48:31 +0000 2016
>Originator:     
>Release:        NetBSD 1.6
>Organization:
http://bsd.reedmedia.net/
>Environment:


System: NetBSD rainier.reedmedia.net 1.6 NetBSD 1.6 (JCR-20020927) #3: Sat Sep 28 13:40:20 PDT 2002 reed@rainier.reedmedia.net:/usr/src/sys/arch/i386/compile/JCR-20020927 i386
Architecture: i386
Machine: i386
>Description:
Please allow pkg_add to upgrade a package without deleting first.
This will make it useful to upgrade essential software that
may be used during the upgrade.
>How-To-Repeat:

>Fix:
Note that this patch changes the current -u to -r for replace
as discussed on tech-pkg list. This patch also includes
man page changes. (Why does this include formatted manpage too?)

Also this fixes pkgdb_remove_pkg() in files/lib/pkgdb.c which I
don't think worked in the first place.

This was made against pkgsrc before changes a few hours ago.

cvs server: Diffing pkgtools/pkg_install/files
cvs server: Diffing pkgtools/pkg_install/files/add
Index: pkgtools/pkg_install/files/add/main.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/add/main.c,v
retrieving revision 1.2
diff -b -u -r1.2 main.c
--- pkgtools/pkg_install/files/add/main.c	2003/01/14 15:18:32	1.2
+++ pkgtools/pkg_install/files/add/main.c	2003/04/11 16:25:30
@@ -56,7 +56,7 @@
 #include "add.h"
 #include "verify.h"

-static char Options[] = "IMRSVfhnp:s:t:uv";
+static char Options[] = "IMRSVfhnp:rs:t:uv";

 char   *Prefix = NULL;
 Boolean NoInstall = FALSE;
@@ -70,6 +70,7 @@
 char    FirstPen[FILENAME_MAX];
 add_mode_t AddMode = NORMAL;
 int	upgrade = 0;
+int	overwrite = 0;

 static void
 usage(void)
@@ -117,6 +118,10 @@
 			Verbose = TRUE;
 			break;

+		case 'r':
+			upgrade = 1; /* replace with pkg_delete first */
+			break;
+
 		case 's':
 			set_verification(optarg);
 			break;
@@ -139,7 +144,9 @@

 		case 'u':
 			upgrade = 1;
+			overwrite = 1; /* do not pkg_delete */
 			break;
+
 		case 'h':
 		case '?':
 		default:
Index: pkgtools/pkg_install/files/add/perform.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/add/perform.c,v
retrieving revision 1.4
diff -b -u -r1.4 perform.c
--- pkgtools/pkg_install/files/add/perform.c	2003/03/29 18:41:56	1.4
+++ pkgtools/pkg_install/files/add/perform.c	2003/04/11 16:25:32
@@ -56,6 +56,8 @@
 #include <sys/wait.h>
 #endif

+static char installed[FILENAME_MAX]; /* already installed package name */
+
 static char LogDir[FILENAME_MAX];
 static int zapLogDir;		/* Should we delete LogDir? */

@@ -134,6 +136,7 @@

 	errc = 0;
 	zapLogDir = 0;
+	installed[0] = '\0';
 	LogDir[0] = '\0';
 	strcpy(playpen, FirstPen);
 	inPlace = 0;
@@ -320,7 +323,6 @@

 		if ((s = strrchr(PkgName, '-')) != NULL) {
 			char    buf[FILENAME_MAX];
-			char    installed[FILENAME_MAX];

 			/*
 			 * See if the pkg is already installed. If so, we might
@@ -338,7 +340,7 @@
 						 dbdir, PkgName);

 					if (Verbose)
-						printf("Upgrading %s to %s.\n", installed, PkgName);
+						printf("Replacing %s with %s.\n", installed, PkgName);

 					if (fexists(upgrade_from)) {  /* Are there any dependencies? */
 					  	/*
@@ -447,10 +449,16 @@
 						upgrading = 1;
 					}

+					if (overwrite) {
+						if (Verbose) {
+							printf("Upgrading by overwriting '%s' with '%s'.\n", installed, PkgName);
+						}
+					}
+					else {
 					if (Verbose)
 						printf("pkg_delete '%s'\n", installed);
 					vsystem("%s/sbin/pkg_delete '%s'\n", PREFIX, installed);
-					
+					}		
 				} else {
 					warnx("other version '%s' already installed", installed);

@@ -463,7 +471,7 @@

 	/* See if there are conflicting packages installed */
 	for (p = Plist.head; p; p = p->next) {
-		char    installed[FILENAME_MAX];
+		char    also_installed[FILENAME_MAX];

 		if (p->type != PLIST_PKGCFL)
 			continue;
@@ -472,9 +480,9 @@

 		/* was: */
 		/* if (!vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) { */
-		if (findmatchingname(dbdir, p->name, note_whats_installed, installed) > 0) {
-			warnx("Conflicting package `%s'installed, please use\n"
-			      "\t\"pkg_delete %s\" first to remove it!", installed, installed);
+		if (findmatchingname(dbdir, p->name, note_whats_installed, also_installed) > 0) {
+			warnx("Conflicting package `%s' installed, please use\n"
+			      "\t\"pkg_delete %s\" first to remove it!", also_installed, also_installed);
 			++errc;
 		}
 	}
@@ -483,14 +491,14 @@
 	 * (e.g. version X is installed, but version Y is required)
 	 */
 	for (p = Plist.head; p; p = p->next) {
-		char installed[FILENAME_MAX];
+		char also_installed[FILENAME_MAX];

 		if (p->type != PLIST_PKGDEP)
 			continue;
 		if (Verbose)
 			printf("Depends pre-scan: `%s' required.\n", p->name);
 		/* if (vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) { */
-		if (findmatchingname(dbdir, p->name, note_whats_installed, installed) <= 0) {
+		if (findmatchingname(dbdir, p->name, note_whats_installed, also_installed) <= 0) {
 			/* 
 			 * required pkg not found. look if it's available with a more liberal
 			 * pattern. If so, this will lead to problems later (check on "some
@@ -517,15 +525,15 @@
 				(void) snprintf(buf, sizeof(buf),
 				    skip ? "%.*s[0-9]*" : "%.*s-[0-9]*",
 				    (int)(s - p->name) + skip, p->name);
-				if (findmatchingname(dbdir, buf, note_whats_installed, installed) > 0) {
+				if (findmatchingname(dbdir, buf, note_whats_installed, also_installed) > 0) {
 					warnx("pkg `%s' required, but `%s' found installed.",
-					      p->name, installed);
+					      p->name, also_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);
+						       "the upgrade case.\n", also_installed);
 					}

 					if (Force) {
@@ -543,7 +551,6 @@

 	/* Now check the packing list for dependencies */
 	for (exact = NULL, p = Plist.head; p; p = p->next) {
-		char    installed[FILENAME_MAX];

 		if (p->type == PLIST_BLDDEP) {
 			exact = p->name;
@@ -601,8 +608,23 @@
 		}
 	}

+	/* remove old package entries from database */
+	if (!Fake && overwrite && installed[0]) {
+
+		/* Open Package Database for writing */
+		if (!pkgdb_open(ReadWrite))
+			warnx("can't open pkgdb");
+		else {
+                       	if (pkgdb_remove_pkg(installed))
+				printf("Removed previous package entries from pkgdb.\n");
+			else
+				warnx("couldn't remove previous package entries from pkgdb.\n");
+		}
+		pkgdb_close();
+	}
+	
 	/* If we're really installing, and have an installation file, run it */
-	if (!NoInstall && fexists(INSTALL_FNAME)) {
+	if (!NoInstall && !overwrite && fexists(INSTALL_FNAME)) {
 		vsystem("%s +x %s", CHMOD_CMD, INSTALL_FNAME);	/* make sure */
 		if (Verbose)
 			printf("Running install with PRE-INSTALL for %s.\n", PkgName);
@@ -634,7 +656,7 @@
 	}

 	/* Run the installation script one last time? */
-	if (!NoInstall && fexists(INSTALL_FNAME)) {
+	if (!NoInstall && !overwrite && fexists(INSTALL_FNAME)) {
 		if (Verbose)
 			printf("Running install with POST-INSTALL for %s.\n", PkgName);
 		if (!Fake && vsystem("./%s %s POST-INSTALL", INSTALL_FNAME, PkgName)) {
@@ -644,6 +666,18 @@
 		}
 	}

+	/* Run the installation script if upgrading */
+	if (overwrite && !NoInstall && fexists(INSTALL_FNAME)) {
+		vsystem("%s +x %s", CHMOD_CMD, INSTALL_FNAME);	/* make sure */
+		if (Verbose)
+			printf("Running install with UPGRADE for %s.\n", PkgName);
+		if (!Fake && vsystem("./%s %s UPGRADE", INSTALL_FNAME, PkgName)) {
+			warnx("install script returned error status");
+			errc = 1;
+			goto fail;
+		}
+	}
+
 	/* Time to record the deed? */
 	if (!NoRecord && !Fake) {
 		char    contents[FILENAME_MAX];
@@ -739,6 +773,97 @@
 			printf("Package %s registered in %s\n", PkgName, LogDir);
 	}

+	/*
+	 * When upgrading, look at old +CONTENTS and make sure
+	 * that files and directories existing in old but not
+	 * new are removed.
+	*/
+	if (overwrite && installed[0]) {
+		static package_t old_Plist;
+		static char old_contents[FILENAME_MAX];
+
+		(void) snprintf(old_contents, sizeof(old_contents), "%s/%s/" CONTENTS_FNAME, dbdir, installed);
+		cfile = fopen(old_contents, "r");
+
+		if (!cfile)
+			warnx("unable to open table of contents file of old package `%s'.",
+			      old_contents);
+		else {
+			plist_t *p;
+			char    *s, try[FILENAME_MAX], t[FILENAME_MAX];
+			char    *old_Directory = ".";	
+
+			if (Verbose)
+				printf("Comparing previous CONTENTS: %s\n",
+					old_contents);
+			read_plist(&old_Plist, cfile);
+			fclose(cfile);
+
+			/* Open Package Database for reading */
+			if (!pkgdb_open(ReadOnly))
+				warnx("can't open pkgdb");
+			else {
+
+				for (p = old_Plist.head; p; p = p->next) {
+
+					switch (p->type) {
+
+					case PLIST_IGNORE:
+						p = p->next;
+						break;
+
+					case PLIST_CWD:
+						old_Directory = p->name;
+						break;
+
+					case PLIST_FILE:
+		/*	last_file = p->name; */
+		/*		char    try[FILENAME_MAX]; */
+
+						if (strrchr(p->name, '\''))
+							warnx("Bogus filename \"%s\"", p->name);
+						else {
+
+							(void) snprintf(t, sizeof(t), "%s/%s", old_Directory, p->name);
+							if (fexists(t)) {
+								/* remove file if not in database for new package */
+								s = pkgdb_retrieve(t);
+#ifdef PKGDB_DEBUG
+								printf("pkgdb_retrieve(\"%s\")=\"%s\"\n", t, s);	/* pkgdb-debug - HF */
+#endif
+								/* file exists */
+								if (!s) {
+									if (Verbose)
+										printf("%s is not in pkgdb; deleting.\n", t);
+
+									if (!Fake) 
+										vsystem("%s %s", RM, t);
+								}
+							}
+						}
+					}
+				}
+				pkgdb_close();
+				if (!Fake && old_contents[0])
+					vsystem("%s %s", RM, old_contents);
+			}
+		}
+		/* TODO -- get rid of old directories? */
+	} /* checks for files no longer part of new package during overwrite */
+
+	/* remove old package data files under /var/db/pkg */
+	if (overwrite && installed[0]) {
+		static char PreviousLogDir[FILENAME_MAX];
+		(void) snprintf(PreviousLogDir, sizeof(PreviousLogDir), "%s/%s", dbdir, installed);
+		if (isdir(PreviousLogDir) || islinktodir(PreviousLogDir)) {
+			if (Verbose)
+				printf("Removing old package data: %s\n", PreviousLogDir);
+			if (!Fake && PreviousLogDir[0])
+				vsystem("%s -rf %s", RM, PreviousLogDir);
+		}
+
+	}
+
 	if ((p = find_plist(&Plist, PLIST_DISPLAY)) != NULL) {
 		FILE   *fp;
 		char    buf[BUFSIZ];
@@ -776,6 +901,8 @@
 		 * Upgrade step 3/4: move back +REQUIRED_BY file
 		 * (see also step 2/4)
 		 */
+		if (Verbose)
+			printf("Move back +REQUIRED_BY file: %s\n", upgrade_to);
 		rc = rename(upgrade_via, upgrade_to);
 		assert(rc == 0);

Index: pkgtools/pkg_install/files/add/pkg_add.1
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/add/pkg_add.1,v
retrieving revision 1.2
diff -b -u -r1.2 pkg_add.1
--- pkgtools/pkg_install/files/add/pkg_add.1	2003/03/29 18:41:56	1.2
+++ pkgtools/pkg_install/files/add/pkg_add.1	2003/04/11 16:25:33
@@ -25,7 +25,7 @@
 .Nd a utility for installing and upgrading software package distributions
 .Sh SYNOPSIS
 .Nm ""
-.Op Fl fIMnRSuVv
+.Op Fl fIMnRrSuVv
 .Bk -words
 .Op Fl s Ar verification-type
 .Ek
@@ -157,6 +157,15 @@
 Do not record the installation of a package.
 This means that you cannot deinstall it later, so only use this option if
 you know what you are doing!
+.It Fl r
+Replace currently installed package with a newer version.
+This uses
+.Xr pkg_delete 1
+to remove the old package.
+See below for a more detailed description of the process.
+Use the
+.Fl u
+flag to upgrade without deleting files first.
 .It Fl S
 Run in
 .Cm SLAVE
@@ -216,9 +225,12 @@
 file installation; often this is
 .Pa /usr .
 .It Fl u
-If the package that's being installed is already installed, either
-in the same or a different version, an update is performed.
+Upgrade a package to a newer version without deleting the currently
+installed files first. This upgrade option overwrites files.
 See below for a more detailed description of the process.
+Use the
+.Fl r
+flag instead to replace a package by cleanly deleting the files first.
 .It Fl V
 Print version number and exit.
 .It Fl v
@@ -269,19 +281,27 @@
 option is not given.
 .Pp
 If the
+.Fl r
+option or the
 .Fl u
-option is given, it's assumed the package should be upgraded instead.
+option is given, it's assumed the package should be replaced or upgraded
+instead.
 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 running
-.Xr pkg_delete 1
-on the installed package.
-Installation then proceeds as if the package
-was not installed, and restores the
+file aside (if it exists).
+When the
+.Fl u
+option is not used, then the installed package is removed with
+.Xr pkg_delete 1 .
+Installation then proceeds as if the package was not installed.
+The upgrade option overwrites files.
+Also, the upgrade option will delete any files from the previous package
+that no longer exist in the newly-installed version.
+Then, the
 .Pa +REQUIRED_BY
-file afterwards.
+file is restored.
 .It
 A check is made to determine if the package conflicts (from
 .Cm @pkgcfl
@@ -334,7 +354,9 @@
 .It
 If the package contains an
 .Ar install
-script, it is executed with the following arguments:
+script and an upgrade
+.Fl ( u )
+is not being done, it is executed with the following arguments:
 .Bl -tag -width indentindent
 .It Ar pkg-name
 The name of the package being installed.
@@ -380,13 +402,31 @@
 .It
 If an
 .Ar install
-script exists for the package, it is executed with the following arguments:
+script exists for the package
+script and an upgrade  
+.Fl ( u )
+is not being done, it is executed with the following arguments:
 .Bl -tag -width indentindent
 .It Ar pkg_name
 The name of the package being installed.
 .It Cm POST-INSTALL
 Keyword denoting that the script is to perform any actions needed
 after the package has been installed.
+.El
+.It
+During an upgrade
+.Fl ( u ) ,
+if an
+.Ar install
+script exists for the package,
+it is executed with the following arguments:
+.Bl -tag -width indentindent
+.It Ar pkg_name
+The name of the package being installed.
+.It Cm UPGRADE
+Keyword denoting that the script is to perform any actions needed
+after the package has been upgraded (i.e., the previous package
+was not cleanly uninstalled first).
 .El
 .It
 After installation is complete, a copy of the packing list,
Index: pkgtools/pkg_install/files/add/pkg_add.cat1
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/add/pkg_add.cat1,v
retrieving revision 1.1.1.1
diff -b -u -r1.1.1.1 pkg_add.cat1
--- pkgtools/pkg_install/files/add/pkg_add.cat1	2002/12/20 18:13:58	1.1.1.1
+++ pkgtools/pkg_install/files/add/pkg_add.cat1	2003/04/11 16:25:34
@@ -5,7 +5,7 @@
      butions

 SSYYNNOOPPSSIISS
-     ppkkgg__aadddd [--ffIIMMnnRRSSuuVVvv] [--ss _v_e_r_i_f_i_c_a_t_i_o_n_-_t_y_p_e] [--tt _t_e_m_p_l_a_t_e] [--pp _p_r_e_f_i_x]
+     ppkkgg__aadddd [--ffIIMMnnRRrrSSuuVVvv] [--ss _v_e_r_i_f_i_c_a_t_i_o_n_-_t_y_p_e] [--tt _t_e_m_p_l_a_t_e] [--pp _p_r_e_f_i_x]
              [ftp://[_u_s_e_r[:_p_a_s_s_w_o_r_d_]@]_h_o_s_t[:_p_o_r_t]][/_p_a_t_h_/]pkg-name ...

 DDEESSCCRRIIPPTTIIOONN
@@ -79,6 +79,11 @@
              cannot deinstall it later, so only use this option if you know
              what you are doing!

+     --rr      Replace currently installed package with a newer version.  This
+             uses pkg_delete(1) to remove the old package.  See below for a
+             more detailed description of the process.  Use the --uu flag to up-
+             grade without deleting files first.
+
      --SS      Run in SSLLAAVVEE mode.  This is a very specialized mode for running
              ppkkgg__aadddd and is meant to be run in conjunction with MMAASSTTEERR mode.
              When run in this mode, ppkkgg__aadddd expects the release contents to be
@@ -116,9 +121,11 @@
              _t_e_m_p_l_a_t_e to reside on the same disk partition as target directo-
              ries for package file installation; often this is _/_u_s_r.

-     --uu      If the package that's being installed is already installed, ei-
-             ther in the same or a different version, an update is performed.
-             See below for a more detailed description of the process.
+     --uu      Upgrade a package to a newer version without deleting the cur-
+             rently installed files first. This upgrade option overwrites
+             files.  See below for a more detailed description of the process.
+             Use the --rr flag instead to replace a package by cleanly deleting
+             the files first.

      --VV      Print version number and exit.

@@ -145,12 +152,18 @@
                 of it is already recorded as installed.  If it is, installa-
                 tion is terminated if the --uu option is not given.

-                If the --uu option is given, it's assumed the package should be
-                upgraded instead.  This is prepared by moving an existing
-                _+_R_E_Q_U_I_R_E_D___B_Y file aside (if it exists), and by running
-                pkg_delete(1) on the installed package.  Installation then
-                proceeds as if the package was not installed, and restores the
-                _+_R_E_Q_U_I_R_E_D___B_Y file afterwards.
+                If the --rr option or the --uu option is given, it's assumed the
+                package should be replaced or upgraded instead.  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
+                _+_R_E_Q_U_I_R_E_D___B_Y file aside (if it exists).  When the --uu option is
+                not used, then the installed package is removed with
+                pkg_delete(1).  Installation then proceeds as if the package
+                was not installed.  The upgrade option overwrites files.  Al-
+                so, the upgrade option will delete any files from the previous
+                package that no longer exist in the newly-installed version.
+                Then, the _+_R_E_Q_U_I_R_E_D___B_Y file is restored.

            2.   A check is made to determine if the package conflicts (from
                 @@ppkkggccffll directives, see pkg_create(1)) with an already record-
@@ -186,8 +199,9 @@
                 If the _r_e_q_u_i_r_e script exits with a non-zero status code, the
                 installation is terminated.

-           7.   If the package contains an _i_n_s_t_a_l_l script, it is executed with
-                the following arguments:
+           7.   If the package contains an _i_n_s_t_a_l_l script and an upgrade (--uu)
+                is not being done, it is executed with the following argu-
+                ments:

                 _p_k_g_-_n_a_m_e      The name of the package being installed.

@@ -210,16 +224,27 @@
                 or, if no --pp flag was specified, the name of the first direc-
                 tory named by a @@ccwwdd directive within this package.

-           10.  If an _i_n_s_t_a_l_l script exists for the package, it is executed
-                with the following arguments:
+           10.  If an _i_n_s_t_a_l_l script exists for the package script and an up-
+                grade (--uu) is not being done, it is executed with the follow-
+                ing arguments:

                 _p_k_g___n_a_m_e      The name of the package being installed.

                 PPOOSSTT--IINNSSTTAALLLL  Keyword denoting that the script is to perform
                               any actions needed after the package has been
                               installed.
+
+           11.  During an upgrade (--uu), if an _i_n_s_t_a_l_l script exists for the
+                package, it is executed with the following arguments:
+
+                _p_k_g___n_a_m_e      The name of the package being installed.
+
+                UUPPGGRRAADDEE       Keyword denoting that the script is to perform
+                              any actions needed after the package has been
+                              upgraded (i.e., the previous package was not
+                              cleanly uninstalled first).

-           11.  After installation is complete, a copy of the packing list,
+           12.  After installation is complete, a copy of the packing list,
                 _d_e_i_n_s_t_a_l_l script, description, and display files are copied
                 into _/_v_a_r_/_d_b_/_p_k_g_/_<_p_k_g_-_n_a_m_e_> for subsequent possible use by
                 pkg_delete(1).  Any package dependencies are recorded in the
@@ -227,9 +252,9 @@
                 the environment variable PKG_DBDIR is set, this overrides the
                 _/_v_a_r_/_d_b_/_p_k_g_/ path shown above).

-           12.  The staging area is deleted and the program terminates.
+           13.  The staging area is deleted and the program terminates.

-           13.  Finally, if we were upgrading a package, any _+_R_E_Q_U_I_R_E_D___B_Y file
+           14.  Finally, if we were upgrading a package, any _+_R_E_Q_U_I_R_E_D___B_Y file
                 that was moved aside before upgrading was started is now moved
                 back into place.

cvs server: Diffing pkgtools/pkg_install/files/admin
cvs server: Diffing pkgtools/pkg_install/files/create
cvs server: Diffing pkgtools/pkg_install/files/delete
cvs server: Diffing pkgtools/pkg_install/files/info
cvs server: Diffing pkgtools/pkg_install/files/lib
Index: pkgtools/pkg_install/files/lib/lib.h.in
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/lib/lib.h.in,v
retrieving revision 1.4
diff -b -u -r1.4 lib.h.in
--- pkgtools/pkg_install/files/lib/lib.h.in	2003/03/16 19:44:10	1.4
+++ pkgtools/pkg_install/files/lib/lib.h.in	2003/04/11 16:25:35
@@ -449,6 +449,7 @@
 extern Boolean Fake;
 extern Boolean Force;
 extern int upgrade;
+extern int overwrite;

 /* We include it at the end, because it uses TAILQ_* */
 #include "path.h"
Index: pkgtools/pkg_install/files/lib/pkgdb.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/lib/pkgdb.c,v
retrieving revision 1.9
diff -b -u -r1.9 pkgdb.c
--- pkgtools/pkg_install/files/lib/pkgdb.c	2003/03/29 18:41:57	1.9
+++ pkgtools/pkg_install/files/lib/pkgdb.c	2003/04/11 16:25:36
@@ -240,7 +240,7 @@
 	if (pkgdbp == NULL) {
 		return 0;
 	}
-	cc = strlen(pkg);
+	cc = strlen(pkg) + 1;
 	for (ret = 1, type = R_FIRST; (*pkgdbp->seq)(pkgdbp, &key, &data, type) == 0 ; type = R_NEXT) {
 		if (cc == data.size && strncmp(data.data, pkg, cc) == 0) {
 			if (Verbose) {
>Release-Note:
>Audit-Trail:

From: fredb@immanent.net (Frederick Bruckman)
To: reed@reedmedia.net, netbsd-bugs@netbsd.org, gnats-bugs@gnats.netbsd.org
Cc:  
Subject: Re: pkg/21095: pkg_add upgrade in place (diff included)
Date: Fri, 11 Apr 2003 13:59:39 -0500 (CDT)

 In article <19814-1050082877@rainier.reedmedia.net>,
 	reed@reedmedia.net writes:

 > Note that this patch changes the current -u to -r for replace
 > as discussed on tech-pkg list. This patch also includes
 > man page changes. (Why does this include formatted manpage too?)

 I don't recall any significant discussion of this on tech-pkg.

 I don't think you've thought this out very well. What happens
 when you upgrade a package containing shared libraries? It looks
 like the old shared library will end up not being registered to
 any package, and therefore, in the case of a soname change, the
 preserved +REQUIRED_BY will be a complete lie (not that the 
 present "pkg_delete -u" does any better).

 I've proposed a trick, where the delta files gets registered to
 a package with a transformed name and the dependencies get shifted 
 to that package, and implemented it as a wrapper around the package
 tools. Please see PR pkg/10835, and follow the references therein.

 Frederick


From: "Jeremy C. Reed" <reed@reedmedia.net>
To: Frederick Bruckman <fredb@immanent.net>
Cc: netbsd-bugs@netbsd.org, <gnats-bugs@gnats.netbsd.org>
Subject: Re: pkg/21095: pkg_add upgrade in place (diff included)
Date: Fri, 11 Apr 2003 12:28:32 -0700 (PDT)

 On Fri, 11 Apr 2003, Frederick Bruckman wrote:

 > I don't recall any significant discussion of this on tech-pkg.

 Sometimes a send-pr gets the discussion going. Maybe I should have
 submitted to the other PR.

 > I don't think you've thought this out very well. What happens
 > when you upgrade a package containing shared libraries? It looks
 > like the old shared library will end up not being registered to
 > any package, and therefore, in the case of a soname change, the

 I am not sure what you mean. If the old shared library has a different
 filename and was also registered in the +CONTENTS, then it will be
 removed. So the problem with not being registered won't matter, because
 the file should not exist.

 For example, my libcrack is required by PAM. In particular,
 /usr/lib/security/pam_cracklib.so uses:
  libcrack.so.2 => /usr/lib/libcrack.so.2 (0x2aab3000)
 If that /usr/lib/libcrack.so.2 was missing in a new version of libcrack,
 then I hope that version was changed enough and that PAM's DEPENDS for
 libcrack was more precise (so not just like libcrack>=2.7 but something
 like libcrack-2.*).

 I do understand if another package needed that library and now it is
 missing, that software will be broken. One idea would be have a dependency
 based on an actual filename. Or make sure the dependency for another
 package providing the library is very specific, so if the shared library
 changes, then it won't allow the upgrade.

 I think if the DEPENDS were more precise, then this should not matter,
 because pkg_add wouldn't let the upgrade happen.

 > preserved +REQUIRED_BY will be a complete lie (not that the
 > present "pkg_delete -u" does any better).

 Also, I see noted in the code:

                 /*
                  * Upgrade step 4/4: Fix pkgs that depend on us to
                  * depend on the new version instead of the old
                  * one by fixing @pkgdep lines in +CONTENTS files.
                  */
                 /* TODO */

 > I've proposed a trick, where the delta files gets registered to
 > a package with a transformed name and the dependencies get shifted
 > to that package, and implemented it as a wrapper around the package
 > tools. Please see PR pkg/10835, and follow the references therein.

 I have briefly looked at pkg_hack. I will look again. Thanks.

    Jeremy C. Reed
    http://bsd.reedmedia.net/


From: Frederick Bruckman <fredb@immanent.net>
To: "Jeremy C. Reed" <reed@reedmedia.net>
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: pkg/21095: pkg_add upgrade in place (diff included)
Date: Sat, 12 Apr 2003 06:10:17 -0500 (CDT)

 On Fri, 11 Apr 2003, Jeremy C. Reed wrote:

 > On Fri, 11 Apr 2003, Frederick Bruckman wrote:
 >
 > > I don't think you've thought this out very well. What happens
 > > when you upgrade a package containing shared libraries? It looks
 > > like the old shared library will end up not being registered to
 > > any package, and therefore, in the case of a soname change, the
 >
 > I am not sure what you mean. If the old shared library has a different
 > filename and was also registered in the +CONTENTS, then it will be
 > removed. So the problem with not being registered won't matter, because
 > the file should not exist.

 Oh... but that would be even worse, wouldn't it?

 > For example, my libcrack is required by PAM. In particular,
 > /usr/lib/security/pam_cracklib.so uses:
 >  libcrack.so.2 => /usr/lib/libcrack.so.2 (0x2aab3000)
 > If that /usr/lib/libcrack.so.2 was missing in a new version of libcrack,
 > then I hope that version was changed enough and that PAM's DEPENDS for
 > libcrack was more precise (so not just like libcrack>=2.7 but something
 > like libcrack-2.*).

 Of course, then, if you upgrade in place to a package that provides
 only libcrack.so.3, you lose, no matter what the dependencies say.
 There's actually no way to express the requirement for a shared
 library of a particular soname with the current package system anyhow.
 We could use something like that, though, perhaps auto-generated at
 "pkg_create" from the result of "ldd". Without that, you can't do it,
 as you can ever know, in advance, which future versions of a package
 will provide which version of the ABI.

 > I do understand if another package needed that library and now it is
 > missing, that software will be broken. One idea would be have a dependency
 > based on an actual filename. Or make sure the dependency for another
 > package providing the library is very specific, so if the shared library
 > changes, then it won't allow the upgrade.

 ...but that's the most interesting case! More to the point, there's no
 need to ever break the dependent programs. Since the package system
 has already ensured that the shared libraries they need were installed
 at the time the binaries were, all we need to do is keep those shared
 libraries around.

 Reflect on what happens when there is no package system, and no
 recorded dependencies, as in the base system. Programs built against
 the base system don't (typically) break when upgrading, because the
 upgrade doesn't delete obsolete shared libraries. Simple. What I
 proposed provides the same thing for the package system, but without
 losing track of them, and without losing track of the dependencies.
 There may well be better ways to do it, but it's pretty clear that
 we need to preserve the shared libraries somehow.

 > I think if the DEPENDS were more precise, then this should not matter,
 > because pkg_add wouldn't let the upgrade happen.

 That would rule out 99% of the times were you would want to upgrade in
 place. On the other hand, if you do keep the "deltas" around, then the
 upstream DEPENDS don't matter. (You still have to check the DEPENDS in
 the package you're installing.)

 > > I've proposed a trick, where the delta files gets registered to
 > > a package with a transformed name and the dependencies get shifted
 > > to that package, and implemented it as a wrapper around the package
 > > tools. Please see PR pkg/10835, and follow the references therein.
 >
 > I have briefly looked at pkg_hack. I will look again. Thanks.

 Bear in mind that it's intended to be a demonstration of a design
 change, not the complete solution to the upgrade-in-place problem. A
 complete solution would involve changes to the package tools and to
 pkgsrc. I don't mean to be hard on you, but I really think it would be
 disastrous to start tweaking on "pkg_add" without (re-)considering the
 whole design, as taking a step in the wrong direction would no doubt
 lead to ever more ill-considered changes.

 Frederick



From: "Jeremy C. Reed" <reed@reedmedia.net>
To: gnats-bugs@netbsd.org
Cc:  
Subject: pkg/21095
Date: Wed, 11 Jun 2003 10:58:04 -0700 (PDT)

 This patch has a bug where it also removes the database entries for the
 packages that it depends on too. (So then it removes the files too!)
 So it is broken for working with packages that have dependencies.
 I fixed this and I am importing to pkgsrc-wip for testing.

    Jeremy C. Reed
    http://bsd.reedmedia.net/


Responsible-Changed-From-To: pkg-manager->joerg
Responsible-Changed-By: joerg@netbsd.org
Responsible-Changed-When: Mon, 02 Oct 2006 19:16:18 +0000
Responsible-Changed-Why:
pkg_install request.


State-Changed-From-To: open->feedback
State-Changed-By: joerg@NetBSD.org
State-Changed-When: Wed, 21 May 2008 21:47:32 +0000
State-Changed-Why:
Does this change request still apply?
I could do something like this relatively easy after the next
run to refactor the pkg_delete code. I'm not convinced that 
the added complexity is really justified.


From: "Jeremy C. Reed" <reed@reedmedia.net>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: pkg/21095 (allow pkg_add to upgrade without pkg_delete first)
Date: Wed, 21 May 2008 17:28:25 -0500 (CDT)

 On Wed, 21 May 2008, joerg@NetBSD.org wrote:

 > State-Changed-From-To: open->feedback
 > State-Changed-By: joerg@NetBSD.org
 > State-Changed-When: Wed, 21 May 2008 21:47:32 +0000
 > State-Changed-Why:
 > Does this change request still apply?
 > I could do something like this relatively easy after the next
 > run to refactor the pkg_delete code. I'm not convinced that 
 > the added complexity is really justified.

 Let's keep this open a little longer.

 The situation is I use pkg_add on systems where all software is from 
 pkgsrc binary packages and no pkgsrc building. In some cases in multi-user 
 usage, I don't want to pkg_delete and remove software on an update, but 
 prefer to overwrite.

State-Changed-From-To: feedback->open
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Thu, 22 May 2008 16:24:13 +0000
State-Changed-Why:
feedback arrived.


State-Changed-From-To: open->feedback
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 09 Aug 2015 23:18:51 +0000
State-Changed-Why:
Doesn't pkg_add -U cover this?


State-Changed-From-To: feedback->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 01 May 2016 05:48:31 +0000
State-Changed-Why:
As far as I can tell pkg_add -U covers this case.
If not, please explain how and I'll reopen the PR.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.