summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/lib
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1995-11-12 04:55:40 +0000
committerjkh <jkh@FreeBSD.org>1995-11-12 04:55:40 +0000
commit9109257a8a8ad0586cdffb23f0a57867e8346d57 (patch)
treece93b1d4f10c4f035a65aa2e14c6eba70aa2a8f8 /usr.sbin/pkg_install/lib
parent4b9555d70cffed7161182736b4955899d3daa55a (diff)
downloadFreeBSD-src-9109257a8a8ad0586cdffb23f0a57867e8346d57.zip
FreeBSD-src-9109257a8a8ad0586cdffb23f0a57867e8346d57.tar.gz
Bring my pkg_install improvements forward from 2.1.
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r--usr.sbin/pkg_install/lib/file.c79
-rw-r--r--usr.sbin/pkg_install/lib/plist.c36
2 files changed, 54 insertions, 61 deletions
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
index ce17e97..ac98530 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.17 1995/10/25 15:38:32 jkh Exp $";
+static const char *rcsid = "$Id: file.c,v 1.18 1995/10/31 20:30:18 jkh Exp $";
#endif
/*
@@ -174,7 +174,7 @@ fileGetURL(char *base, char *spec)
{
char host[HOSTNAME_MAX], file[FILENAME_MAX], dir[FILENAME_MAX];
char pword[HOSTNAME_MAX + 40], *uname, *cp, *rp, *tmp;
- char fname[511];
+ char fname[FILENAME_MAX];
char pen[FILENAME_MAX];
struct passwd *pw;
FTP_t ftp;
@@ -182,39 +182,40 @@ fileGetURL(char *base, char *spec)
int fd, fd2, i, len = 0;
char ch;
time_t start, stop;
+ char *hint;
rp = NULL;
+ /* Special tip that sysinstall left for us */
+ hint = getenv("PKG_ADD_BASE");
if (!isURL(spec)) {
int len;
- if (!base)
+ if (!base && !hint)
return NULL;
/* We've been given an existing URL (that's known-good) and now we need
to construct a composite one out of that and the basename we were
handed as a dependency. */
- strncpy(fname, base, 511);
- fname[511] = '\0';
- cp = strrchr(fname, '/');
- if (cp) {
- *cp = '\0'; /* Eliminate the filename portion */
- len = strlen(fname);
- /* Special case for the all category */
- if (len > 3 && !strcmp(cp - 3, "All"))
- sprintf(cp, "/%s", spec);
- else {
- /* Replace category with All */
- if ((cp = strrchr(fname, '/')) != NULL) {
- strcat(cp + 1, "All/");
- strcat(cp + 4, spec);
- }
- else {
- strcat(fname, "All/");
- strcat(fname, spec);
- }
+ if (base) {
+ strcpy(fname, base);
+ /* Advance back two slashes to get to the root of the package hierarchy */
+ cp = strrchr(fname, '/');
+ if (cp) {
+ *cp = '\0'; /* chop name */
+ cp = strrchr(fname, '/');
+ }
+ if (cp) {
+ *(cp + 1) = '\0';
+ strcat(cp, "All/");
+ strcat(cp, spec);
}
+ else
+ return NULL;
+ }
+ else {
+ /* Otherwise, we've been given an environment variable hinting at the right location from sysinstall */
+ strcpy(fname, hint);
+ strcat(fname, spec);
}
- else
- return NULL;
}
else
strcpy(fname, spec);
@@ -298,7 +299,6 @@ fileFindByPath(char *base, char *fname)
{
static char tmp[FILENAME_MAX];
char *cp;
- int len;
if (fexists(fname) && isfile(fname)) {
strcpy(tmp, fname);
@@ -306,28 +306,19 @@ fileFindByPath(char *base, char *fname)
}
if (base) {
strcpy(tmp, base);
- cp = strchr(tmp, '/');
- len = strlen(tmp);
+ cp = strrchr(fname, '/');
if (cp) {
- /* Special case for the all category */
- if (len > 3 && !strncmp(cp - 3, "All/", 4))
- strcat(cp + 1, fname);
- else {
- *cp = '\0';
- /* Replace category with All */
- if ((cp = strrchr(tmp, '/')) != NULL) {
- strcat(cp + 1, "All/");
- strcat(cp, fname);
- }
- else {
- strcat(tmp, "All/");
- strcat(tmp, fname);
- }
- }
+ *cp = '\0'; /* chop name */
+ cp = strrchr(fname, '/');
+ }
+ if (cp) {
+ *(cp + 1) = '\0';
+ strcat(cp, "All/");
+ strcat(cp, fname);
+ if (fexists(tmp))
+ return tmp;
}
- if (fexists(tmp))
- return tmp;
}
cp = getenv("PKG_PATH");
diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c
index bc497ad..132c6e1 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.13 1995/05/30 03:50:07 rgrimes Exp $";
+static const char *rcsid = "$Id: plist.c,v 1.14 1995/07/28 01:50:35 ache Exp $";
#endif
/*
@@ -287,18 +287,15 @@ write_plist(Package *pkg, FILE *fp)
break;
case PLIST_CHMOD:
- fprintf(fp, "%cmode %s\n", CMD_CHAR,
- plist->name ? plist->name : "");
+ fprintf(fp, "%cmode %s\n", CMD_CHAR, plist->name ? plist->name : "");
break;
case PLIST_CHOWN:
- fprintf(fp, "%cowner %s\n", CMD_CHAR,
- plist->name ? plist->name : "");
+ fprintf(fp, "%cowner %s\n", CMD_CHAR, plist->name ? plist->name : "");
break;
case PLIST_CHGRP:
- fprintf(fp, "%cgroup %s\n", CMD_CHAR,
- plist->name ? plist->name : "");
+ fprintf(fp, "%cgroup %s\n", CMD_CHAR, plist->name ? plist->name : "");
break;
case PLIST_COMMENT:
@@ -355,6 +352,8 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
char *Where = ".", *last_file = "";
Boolean fail = SUCCESS;
+ if (!p)
+ return FAIL;
while (p) {
if (p->type == PLIST_CWD) {
Where = p->name;
@@ -378,14 +377,18 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
char full_name[FILENAME_MAX];
sprintf(full_name, "%s/%s", Where, p->name);
- if (Verbose)
- printf("Delete%s %s\n",
- p->type == PLIST_FILE ? "" : " directory", full_name);
-
- if (!Fake && delete_hierarchy(full_name, ign_err,
- p->type == PLIST_DIR_RM ? FALSE : nukedirs)) {
- whinge("Unable to completely remove file '%s'", full_name);
- fail = FAIL;
+ if (isdir(full_name) && p->type == PLIST_FILE) {
+ warn("Attempting to delete directory `%s' as a file\n"
+ "This packing list is incorrect - ignoring delete request.\n", full_name);
+ }
+ else {
+ if (Verbose)
+ printf("Delete %s %s\n", !isdir(full_name) ? "file" : " directory", full_name);
+
+ if (!Fake && delete_hierarchy(full_name, ign_err, p->type == PLIST_DIR_RM ? FALSE : nukedirs)) {
+ whinge("Unable to completely remove file '%s'", full_name);
+ fail = FAIL;
+ }
}
last_file = p->name;
}
@@ -411,8 +414,7 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
cp1 = cp2 = dir;
if (!fexists(dir)) {
if (!ign_err)
- whinge("%s `%s' doesn't really exist.",
- isdir(dir) ? "Directory" : "File", dir);
+ whinge("%s `%s' doesn't really exist.", isdir(dir) ? "Directory" : "File", dir);
} else if (nukedirs) {
if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
return 1;
OpenPOWER on IntegriCloud