aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_install/lib
diff options
context:
space:
mode:
authorJordan K. Hubbard <jkh@FreeBSD.org>1996-07-30 10:48:20 +0000
committerJordan K. Hubbard <jkh@FreeBSD.org>1996-07-30 10:48:20 +0000
commit50f56e483ad735716aa51d0ba798a096cd772bc7 (patch)
tree88293eee6032bf226b091c9261848f0aae12de17 /usr.sbin/pkg_install/lib
parent3a45e50f3984797654e5dd9a9d0d740c525dc746 (diff)
Notes
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r--usr.sbin/pkg_install/lib/global.c3
-rw-r--r--usr.sbin/pkg_install/lib/lib.h25
-rw-r--r--usr.sbin/pkg_install/lib/plist.c92
3 files changed, 78 insertions, 42 deletions
diff --git a/usr.sbin/pkg_install/lib/global.c b/usr.sbin/pkg_install/lib/global.c
index d411f5e28550..17d0026ca62a 100644
--- a/usr.sbin/pkg_install/lib/global.c
+++ b/usr.sbin/pkg_install/lib/global.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: global.c,v 1.1.1.1 1993/08/26 01:19:55 jkh Exp $";
+static const char *rcsid = "$Id: global.c,v 1.2 1994/04/05 14:08:45 jkh Exp $";
#endif
/*
@@ -28,6 +28,7 @@ static const char *rcsid = "$Id: global.c,v 1.1.1.1 1993/08/26 01:19:55 jkh Exp
/* These are global for all utils */
Boolean Verbose = FALSE;
Boolean Fake = FALSE;
+Boolean Force = FALSE;
int AutoAnswer = FALSE;
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h
index 95ac9a1a034d..6abf95f7f392 100644
--- a/usr.sbin/pkg_install/lib/lib.h
+++ b/usr.sbin/pkg_install/lib/lib.h
@@ -1,4 +1,4 @@
-/* $Id: lib.h,v 1.20 1996/06/08 00:46:32 alex Exp $ */
+/* $Id: lib.h,v 1.21 1996/06/20 18:33:53 jkh Exp $ */
/*
* FreeBSD install - a package for the installation and maintainance
@@ -62,25 +62,25 @@
#define PKG_DBDIR "PKG_DBDIR"
/* The names of our "special" files */
-#define CONTENTS_FNAME "+CONTENTS"
-#define COMMENT_FNAME "+COMMENT"
-#define DESC_FNAME "+DESC"
-#define INSTALL_FNAME "+INSTALL"
-#define DEINSTALL_FNAME "+DEINSTALL"
-#define REQUIRE_FNAME "+REQUIRE"
+#define CONTENTS_FNAME "+CONTENTS"
+#define COMMENT_FNAME "+COMMENT"
+#define DESC_FNAME "+DESC"
+#define INSTALL_FNAME "+INSTALL"
+#define DEINSTALL_FNAME "+DEINSTALL"
+#define REQUIRE_FNAME "+REQUIRE"
#define REQUIRED_BY_FNAME "+REQUIRED_BY"
-#define DISPLAY_FNAME "+DISPLAY"
-#define MTREE_FNAME "+MTREE_DIRS"
+#define DISPLAY_FNAME "+DISPLAY"
+#define MTREE_FNAME "+MTREE_DIRS"
-#define CMD_CHAR '@' /* prefix for extended PLIST cmd */
+#define CMD_CHAR '@' /* prefix for extended PLIST cmd */
/* The name of the "prefix" environment variable given to scripts */
#define PKG_PREFIX_VNAME "PKG_PREFIX"
enum _plist_t {
PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD,
- PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT,
- PLIST_IGNORE, PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
+ PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE,
+ PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
PLIST_PKGDEP, PLIST_MTREE, PLIST_DIR_RM, PLIST_IGNORE_INST,
PLIST_OPTION
};
@@ -171,6 +171,7 @@ int pkg_perform(char **);
/* Externs */
extern Boolean Verbose;
extern Boolean Fake;
+extern Boolean Force;
extern int AutoAnswer;
#endif /* _INST_LIB_LIB_H_ */
diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c
index 2a5c67460451..b9f3e1673e57 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: plist.c,v 1.15 1995/11/12 04:55:40 jkh Exp $";
+static const char *rcsid = "$Id: plist.c,v 1.16 1996/06/20 18:33:55 jkh Exp $";
#endif
/*
@@ -23,6 +23,7 @@ static const char *rcsid = "$Id: plist.c,v 1.15 1995/11/12 04:55:40 jkh Exp $";
*/
#include "lib.h"
+#include <md5.h>
/* Add an item to a packing list */
void
@@ -238,11 +239,11 @@ read_plist(Package *pkg, FILE *fp)
int cmd;
while (fgets(pline, FILENAME_MAX, fp)) {
- int len = strlen(pline) - 1;
+ int len = strlen(pline);
- while (isspace(pline[len]))
- pline[len--] = '\0';
- if (len <= 0)
+ while (len && isspace(pline[len - 1]))
+ pline[--len] = '\0';
+ if (!len)
continue;
cp = pline;
if (pline[0] == CMD_CHAR) {
@@ -348,51 +349,84 @@ write_plist(Package *pkg, FILE *fp)
int
delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
{
- PackingList p = pkg->head;
+ PackingList p;
char *Where = ".", *last_file = "";
Boolean fail = SUCCESS;
+ char tmp[FILENAME_MAX];
- if (!p)
- return FAIL;
- while (p) {
- if (p->type == PLIST_CWD) {
+ for (p = pkg->head; p; p = p->next) {
+ switch (p->type) {
+ case PLIST_IGNORE:
+ p = p->next;
+ break;
+
+ case PLIST_CWD:
Where = p->name;
if (Verbose)
printf("Change working directory to %s\n", Where);
- }
- else if (p->type == PLIST_UNEXEC) {
- char cmd[FILENAME_MAX];
+ break;
- format_cmd(cmd, p->name, Where, last_file);
+ case PLIST_UNEXEC:
+ format_cmd(tmp, p->name, Where, last_file);
if (Verbose)
- printf("Execute `%s'\n", cmd);
- if (!Fake && system(cmd)) {
- whinge("unexec command for `%s' failed.", cmd);
+ printf("Execute `%s'\n", tmp);
+ if (!Fake && system(tmp)) {
+ whinge("unexec command for `%s' failed.", tmp);
fail = FAIL;
}
- }
- else if (p->type == PLIST_IGNORE)
- p = p->next;
- else if (p->type == PLIST_FILE || p->type == PLIST_DIR_RM) {
- char full_name[FILENAME_MAX];
+ break;
- sprintf(full_name, "%s/%s", Where, p->name);
- if (isdir(full_name) && p->type == PLIST_FILE) {
+ case PLIST_FILE:
+ sprintf(tmp, "%s/%s", Where, p->name);
+ if (isdir(tmp)) {
whinge("Attempting to delete directory `%s' as a file\n"
- "This packing list is incorrect - ignoring delete request.\n", full_name);
+ "This packing list is incorrect - ignoring delete request.\n", tmp);
}
else {
+ if (p->next && p->next->type == PLIST_COMMENT && !strncmp(p->next->name, "MD5:", 4)) {
+ char *cp, buf[33];
+
+ if ((cp = MD5File(tmp, buf)) != NULL) {
+ /* Mismatch? */
+ if (strcmp(cp, p->next->name + 4)) {
+ if (Verbose)
+ printf("%s fails original MD5 checksum - %s\n",
+ tmp, Force ? "deleted anyway." : "not deleted.");
+ if (!Force) {
+ fail = FAIL;
+ continue;
+ }
+ }
+ }
+ }
if (Verbose)
- printf("Delete %s %s\n", !isdir(full_name) ? "file" : " directory", full_name);
+ printf("Delete file %s\n", tmp);
+
+ if (!Fake && delete_hierarchy(tmp, ign_err, nukedirs)) {
+ whinge("Unable to completely remove file '%s'", tmp);
+ fail = FAIL;
+ }
+ }
+ last_file = p->name;
+ break;
- if (!Fake && delete_hierarchy(full_name, ign_err, p->type == PLIST_DIR_RM ? FALSE : nukedirs)) {
- whinge("Unable to completely remove file '%s'", full_name);
+ case PLIST_DIR_RM:
+ sprintf(tmp, "%s/%s", Where, p->name);
+ if (!isdir(tmp)) {
+ whinge("Attempting to delete file `%s' as a directory\n"
+ "This packing list is incorrect - ignoring delete request.\n", tmp);
+ }
+ else {
+ if (Verbose)
+ printf("Delete directory %s\n", tmp);
+ if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) {
+ whinge("Unable to completely remove directory '%s'", tmp);
fail = FAIL;
}
}
last_file = p->name;
+ break;
}
- p = p->next;
}
return fail;
}