Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Nov 2007 04:35:13 GMT
From:      Garrett Cooper <gcooper@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 129672 for review
Message-ID:  <200711280435.lAS4ZDWS036846@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=129672

Change 129672 by gcooper@shiina-ibook on 2007/11/28 04:34:41

	Finish off post deinstall scripts..
	
	The way that it was I had to split the deinstall script up into pre and post portions because pkg_install(1) has that functionality. I'm not sure why you would really want to do pre and post deinstall deinstall checks, because it seems extremely overkill.. but whatever.. gotta be backwards compatible..

Affected files ...

.. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg.h#2 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db_freebsd.c#4 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_freebsd.c#3 edit

Differences ...

==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg.h#2 (text+ko) ====

@@ -102,7 +102,8 @@
 	pkg_script_mtree,		/**< Mtree */
 	pkg_script_require,		/**< Requirement check */
 	pkg_script_require_deinstall,	/**< Removal Requirement check */
-	pkg_script_deinstall,		/**< Deinstall check */
+	pkg_script_deinstall_pre,	/**< Pre-deinstall check */
+	pkg_script_deinstall_post,	/**< Post-deinstall check */
 	pkg_script_pre_deinstall,	/**< Pre-removal */
 	pkg_script_post_deinstall	/**< Post-removal */
 } pkg_script;

==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db_freebsd.c#4 (text+ko) ====

@@ -522,7 +522,7 @@
 
 			/* Try +DEINSTALL */
 			if (pkg_run_script(real_pkg, NULL,
-				pkg_script_deinstall) != 0 &&
+				pkg_script_deinstall_pre) != 0 &&
 		    	    errno != ENOFILE && force == 0) {
 		    	    warnx("deinstall +REQUIRE script execution failed");
 		    	    return -1;
@@ -578,13 +578,28 @@
 		return -1;
 	}
 
+	/* Let's run the scripts at the end of the deinstall, mmk? */
 	if (fake == 0 && exec_pkg_scripts == 1) {
-		/** @todo Run +POST-DEINSTALL <pkg-name>/+DEINSTALL <pkg-name> POST-DEINSTALL */
-		if (pkg_run_script(real_pkg, NULL, pkg_script_post_deinstall) != 0 &&
-		    force != 0) {
-		    warnx("post-deinstall script execution failed");
+
+		/* Run post-deinstall script.. */
+		if (pkg_run_script(real_pkg, NULL,
+			pkg_script_post_deinstall) != 0 &&
+		    errno != ENOFILE && force != 0) {
+		    warnx("post deinstall script execution failed");
 		    return -1;
 		}
+		/* Try deinstall script with POST-DEINSTALL arguments.. */
+		else if(errno == ENOFILE) {
+
+		    if (pkg_run_script(real_pkg, NULL,
+			    pkg_script_deinstall_post) != 0 &&
+			errno != ENOFILE && force != 0) {
+			warnx("post deinstall script execution failed");
+			return -1;
+		    }
+
+		}
+
 	}
 
 	return 0;

==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_freebsd.c#3 (text+ko) ====

@@ -968,7 +968,10 @@
 		data = pkgfile_get_data(control[pos]);
 		if (data != NULL) {
 			str1 = data;
-			/* @todo Write comment on what this does */
+			/*
+			 * Split lines tokenized by newlines
+			 * and attempt to add packages..
+			 */
 			while ((str2 = strchr(str1, '\n')) != NULL) {
 				unsigned int len = str2-str1;
 				strncpy(pkg_name, str1, len);
@@ -977,6 +980,10 @@
 				str1 = str2+1;
 			}
 
+			/*
+			 * @Todo: what the heck does this do
+			 * (in the big picture, that is..)?
+			 */
 			size = pkgfile_get_size(control[pos]);
 			if ((unsigned int)(str1 - data) != size) {
 				unsigned int len = data + size - str1;
@@ -1037,7 +1044,12 @@
 		}
 		break;
 	case pkg_script_pre_deinstall:
+		script_file = pkg_get_control_file(pkg, "+PRE-DEINSTALL");
+		snprintf(arg, FILENAME_MAX, "PRE-DEINSTALL");
+		break;
 	case pkg_script_post_deinstall:
+		script_file = pkg_get_control_file(pkg, "+POST-DEINSTALL");
+		snprintf(arg, FILENAME_MAX, "POST-DEINSTALL");
 		break;
 	case pkg_script_mtree:
 		assert(script_file == NULL);
@@ -1052,9 +1064,14 @@
 			snprintf(arg, FILENAME_MAX, "DEINSTALL");
 		}
 		break;
-	case pkg_script_deinstall:
+	case pkg_script_deinstall_pre:
+	case pkg_script_deinstall_post:
 		script_file = pkg_get_control_file(pkg, "+DEINSTALL");
-		snprintf(arg, FILENAME_MAX, "DEINSTALL");
+		if (script == pkg_script_deinstall_pre)
+			snprintf(arg, FILENAME_MAX, "DEINSTALL");
+		} else {
+			snprintf(arg, FILENAME_MAX, "DEINSTALL POST-DEINSTALL");
+		}
 		break;
 	case pkg_script_noop:
 		return -1;
@@ -1067,21 +1084,41 @@
 	}
 
 	if (fpkg->pkg_type == fpkg_from_file) {
+
 		/**
-		 * @todo Add a lock around mkdtemp as
-		 * arc4random is not thread safe
+		 * Andrew Turner: @todo Add a lock around
+		 * mkdtemp as arc4random is not thread safe
+		 *
+		 * Garrett Cooper: What? Do you mean use
+		 * flock(1), or another randomizing algorithm
+		 * to produce a filename in place of "XXXXXXX"?
+		 * *confused*...
 		 */
 		snprintf(dir, FILENAME_MAX, "/tmp/libpkg_XXXXXXX");
-		mkdtemp(dir);
+
+		/*
+		 * mkdtemp(3) returns NULL if the directory
+		 * couldn't be created..
+		 */
+		if(mkdtemp(dir) != NULL) {
+
+			/*
+			 * Change to the temp dir and back up the
+			 * current dir to return here
+			 */
+			cwd = getcwd(NULL, 0);
+			chdir(dir);
+
+			/* Extract the script */
+			pkgfile_write(script_file);
 
-		/* Change to the temp dir and back up the current dir to return here */
-		cwd = getcwd(NULL, 0);
-		chdir(dir);
+		}
 
-		/* Extract the script */
-		pkgfile_write(script_file);
 	}
 
+	/*
+	 * Now, to execute the script...
+	 */
 	switch(script) {
 	case pkg_script_mtree:
 	{
@@ -1097,7 +1134,8 @@
 	case pkg_script_require_deinstall:
 	case pkg_script_pre_deinstall:
 	case pkg_script_post_deinstall:
-	case pkg_script_deinstall:
+	case pkg_script_deinstall_pre:
+	case pkg_script_deinstall_post:
 		/* Check the script has the execute bit set */
 		pkg_chmod_file(pkgfile_get_name(script_file));
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200711280435.lAS4ZDWS036846>