diff options
author | jkh <jkh@FreeBSD.org> | 1993-09-18 03:39:50 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1993-09-18 03:39:50 +0000 |
commit | 14f46efaad7cbf35d71371ee36e6dea380ecc3b6 (patch) | |
tree | df3e5110c881894a7d75609acee5c3149906a41b /usr.sbin/pkg_install/lib | |
parent | c8b21d348caf8859889cddf47bfacd774107faac (diff) | |
download | FreeBSD-src-14f46efaad7cbf35d71371ee36e6dea380ecc3b6.zip FreeBSD-src-14f46efaad7cbf35d71371ee36e6dea380ecc3b6.tar.gz |
Added code for doing % sequence expansion, added new @unexec command.
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 61 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/plist.c | 22 |
3 files changed, 84 insertions, 5 deletions
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index 2b69bbf..698fd87 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: file.c,v 1.6 1993/09/04 05:06:48 jkh Exp $"; +static const char *rcsid = "$Id: file.c,v 1.4 1993/09/06 23:28:42 jkh Exp $"; #endif /* @@ -171,3 +171,62 @@ unpack(char *pkg, char *flist) } return 0; } + +/* Using fmt, replace all instances of: + * + * %F With the parameter "name" + * %D With the parameter "dir" + * %B Return the directory part ("base") of %D/%F + * %f Return the filename part of %D/%F + * + * Does not check for overflow - caution! + * + */ +void +format_cmd(char *buf, char *fmt, char *dir, char *name) +{ + char *cp, scratch[FILENAME_MAX * 2]; + + while (*fmt) { + if (*fmt == '%') { + switch (*++fmt) { + case 'F': + strcpy(buf, name); + buf += strlen(name); + break; + + case 'D': + strcpy(buf, dir); + buf += strlen(dir); + break; + + case 'B': + sprintf(scratch, "%s/%s", dir, name); + cp = &scratch[strlen(scratch) - 1]; + while (cp != scratch && *cp != '/') + --cp; + *cp = '\0'; + strcpy(buf, scratch); + buf += strlen(scratch); + break; + + case 'f': + sprintf(scratch, "%s/%s", dir, name); + cp = &scratch[strlen(scratch) - 1]; + while (cp != scratch && *(cp - 1) != '/') + --cp; + strcpy(buf, cp); + buf += strlen(cp); + break; + + default: + *buf++ = *fmt; + break; + } + ++fmt; + } + else + *buf++ = *fmt++; + } + *buf = '\0'; +} diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 682687c..f84c31b 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.5 1993/09/04 05:06:49 jkh Exp $ */ +/* $Id: lib.h,v 1.3 1993/09/05 04:54:21 jkh Exp $ */ /* * FreeBSD install - a package for the installation and maintainance @@ -66,10 +66,11 @@ #define CMD_CHAR '@' /* prefix for extended PLIST cmd */ + enum _plist_t { PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD, PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, - PLIST_IGNORE, PLIST_NAME + PLIST_IGNORE, PLIST_NAME, PLIST_UNEXEC }; typedef enum _plist_t plist_t; @@ -114,6 +115,7 @@ void copy_file(char *, char *, char *); void copy_hierarchy(char *, char *, Boolean); int delete_hierarchy(char *, Boolean); int unpack(char *, char *); +void format_cmd(char *, char *, char *, char *); /* Msg */ void upchuck(const char *); diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c index 1f2e09f..6c54e66 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.6 1993/09/04 05:06:52 jkh Exp $"; +static const char *rcsid = "$Id: plist.c,v 1.4 1993/09/12 20:45:53 jkh Exp $"; #endif /* @@ -184,6 +184,8 @@ plist_cmd(char *s, char **arg) return PLIST_CWD; else if (!strcmp(cmd, "exec")) return PLIST_CMD; + else if (!strcmp(cmd, "unexec")) + return PLIST_UNEXEC; else if (!strcmp(cmd, "mode")) return PLIST_CHMOD; else if (!strcmp(cmd, "owner")) @@ -219,6 +221,8 @@ read_plist(Package *pkg, FILE *fp) cmd = plist_cmd(pline + 1, &cp); if (cmd == FAIL) barf("Bad command '%s'", pline); + if (*cp == '\0') + cp = NULL; } else cmd = PLIST_FILE; @@ -246,6 +250,10 @@ write_plist(Package *pkg, FILE *fp) fprintf(fp, "%cexec %s\n", CMD_CHAR, plist->name); break; + case PLIST_UNEXEC: + fprintf(fp, "%cunexec %s\n", CMD_CHAR, plist->name); + break; + case PLIST_CHMOD: fprintf(fp, "%cmode %s\n", CMD_CHAR, plist->name ? plist->name : ""); @@ -286,7 +294,7 @@ void delete_package(Boolean ign_err, Package *pkg) { PackingList p = pkg->head; - char *Where = "."; + char *Where = ".", *last_file = ""; while (p) { if (p->type == PLIST_CWD) { @@ -294,6 +302,15 @@ delete_package(Boolean ign_err, Package *pkg) if (Verbose) printf("(CWD to %s)\n", Where); } + else if (p->type == PLIST_UNEXEC) { + char cmd[FILENAME_MAX]; + + format_cmd(cmd, p->name, Where, last_file); + if (Verbose) + printf("unexec command: %s\n", cmd); + if (!Fake && system(cmd)) + whinge("unexec '%s' failed.", cmd); + } else if (p->type == PLIST_IGNORE) p = p->next; else if (p->type == PLIST_FILE) { @@ -305,6 +322,7 @@ delete_package(Boolean ign_err, Package *pkg) if (!Fake && delete_hierarchy(full_name, ign_err)) whinge("Unable to completely remove file '%s'", full_name); + last_file = p->name; } p = p->next; } |