summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/lib
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1997-06-29 10:41:49 +0000
committerjkh <jkh@FreeBSD.org>1997-06-29 10:41:49 +0000
commit4bb6ae9575ad1b207a84af41097dcd0249b9de7e (patch)
treeb9903527c441fd7785b80009ee38cd263f262eef /usr.sbin/pkg_install/lib
parent4e5976e2979afbe2791f220e6d21e6456590f3c6 (diff)
downloadFreeBSD-src-4bb6ae9575ad1b207a84af41097dcd0249b9de7e.zip
FreeBSD-src-4bb6ae9575ad1b207a84af41097dcd0249b9de7e.tar.gz
Add support for @option preserve - moves existing files out of the way
before replacing them (using pkgname to make this hopefully unique). Delete also moves them back, if they exist, resulting in a package which can be "backed out" with reasonable safety.
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r--usr.sbin/pkg_install/lib/plist.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c
index 72db68e..5380187 100644
--- a/usr.sbin/pkg_install/lib/plist.c
+++ b/usr.sbin/pkg_install/lib/plist.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id$";
+static const char *rcsid = "$Id: plist.c,v 1.19 1997/02/22 16:09:51 peter Exp $";
#endif
/*
@@ -23,6 +23,7 @@ static const char *rcsid = "$Id$";
*/
#include "lib.h"
+#include <errno.h>
#include <md5.h>
/* Add an item to a packing list */
@@ -352,10 +353,16 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
PackingList p;
char *Where = ".", *last_file = "";
Boolean fail = SUCCESS;
- char tmp[FILENAME_MAX];
+ Boolean preserve;
+ char tmp[FILENAME_MAX], *name = NULL;
+ preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
for (p = pkg->head; p; p = p->next) {
switch (p->type) {
+ case PLIST_NAME:
+ name = p->name;
+ break;
+
case PLIST_IGNORE:
p = p->next;
break;
@@ -401,8 +408,22 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
}
if (Verbose)
printf("Delete file %s\n", tmp);
-
- if (!Fake && delete_hierarchy(tmp, ign_err, nukedirs)) {
+ if (!Fake && preserve) {
+ if (!name)
+ whinge("preserve set but no package name supplied!");
+ else {
+ char tmp2[FILENAME_MAX];
+
+ snprintf(tmp2, FILENAME_MAX, "%s.%s", tmp, name);
+ if (fexists(tmp2)) {
+ (void)chflags(tmp, 0);
+ delete_hierarchy(tmp, TRUE, TRUE);
+ if (rename(tmp2, tmp))
+ whinge("preserve: Unable to restore %s as %s, errno = %d", tmp2, tmp, errno);
+ }
+ }
+ }
+ else if (!Fake && delete_hierarchy(tmp, ign_err, nukedirs)) {
whinge("Unable to completely remove file '%s'", tmp);
fail = FAIL;
}
OpenPOWER on IntegriCloud