summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/pkg_install/add/extract.c38
-rw-r--r--usr.sbin/pkg_install/create/pkg_create.114
-rw-r--r--usr.sbin/pkg_install/lib/file.c44
-rw-r--r--usr.sbin/pkg_install/lib/plist.c11
4 files changed, 72 insertions, 35 deletions
diff --git a/usr.sbin/pkg_install/add/extract.c b/usr.sbin/pkg_install/add/extract.c
index 902510e533a4..f3060e895db3 100644
--- a/usr.sbin/pkg_install/add/extract.c
+++ b/usr.sbin/pkg_install/add/extract.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: extract.c,v 1.14 1997/06/29 10:41:43 jkh Exp $";
+static const char *rcsid = "$Id: extract.c,v 1.15 1997/06/30 02:57:40 jkh Exp $";
#endif
/*
@@ -55,8 +55,7 @@ rollback(char *name, char *home, PackingList start, PackingList stop)
for (q = start; q != stop; q = q->next) {
if (q->type == PLIST_FILE) {
snprintf(try, FILENAME_MAX, "%s/%s", dir, q->name);
- snprintf(bup, FILENAME_MAX, "%s.%s", try, name);
- if (fexists(bup)) {
+ if (make_preserve_name(bup, FILENAME_MAX, name, try) && fexists(bup)) {
(void)chflags(try, 0);
(void)unlink(try);
if (rename(bup, try))
@@ -122,20 +121,19 @@ extract_plist(char *home, Package *pkg)
char try[FILENAME_MAX];
/* first try to rename it into place */
- sprintf(try, "%s/%s", Directory, p->name);
- if (preserve && fexists(try)) {
- char pf[FILENAME_MAX];
-
- if (!PkgName) {
- whinge("Package set preserve option but has no name - bailing out.");
- return;
- }
- snprintf(pf, FILENAME_MAX, "%s.%s", try, PkgName);
+ snprintf(try, FILENAME_MAX, "%s/%s", Directory, p->name);
+ if (fexists(try)) {
(void)chflags(try, 0); /* XXX hack - if truly immutable, rename fails */
- if (rename(try, pf)) {
- whinge("Unable to back up %s to %s, aborting pkg_add", try, pf);
- rollback(PkgName, home, pkg->head, p);
- return;
+ if (preserve && PkgName) {
+ char pf[FILENAME_MAX];
+
+ if (make_preserve_name(pf, FILENAME_MAX, PkgName, try)) {
+ if (rename(try, pf)) {
+ whinge("Unable to back up %s to %s, aborting pkg_add", try, pf);
+ rollback(PkgName, home, pkg->head, p);
+ return;
+ }
+ }
}
}
if (rename(p->name, try) == 0) {
@@ -143,9 +141,7 @@ extract_plist(char *home, Package *pkg)
if (p->name[0] == '/' || TOOBIG(p->name)) {
PUSHOUT(Directory);
}
- add_count = snprintf(&perm_args[perm_count],
- maxargs - perm_count,
- "%s ", p->name);
+ add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "%s ", p->name);
if (add_count > maxargs - perm_count)
barf("oops, miscounted strings!");
perm_count += add_count;
@@ -159,9 +155,7 @@ extract_plist(char *home, Package *pkg)
else if (p->name[0] == '/' || TOOBIG(p->name)) {
PUSHOUT(Directory);
}
- add_count = snprintf(&where_args[where_count],
- maxargs - where_count,
- " %s", p->name);
+ add_count = snprintf(&where_args[where_count], maxargs - where_count, " %s", p->name);
if (add_count > maxargs - where_count)
barf("oops, miscounted strings!");
where_count += add_count;
diff --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1
index 1d838b83f730..d2ccdb755b7b 100644
--- a/usr.sbin/pkg_install/create/pkg_create.1
+++ b/usr.sbin/pkg_install/create/pkg_create.1
@@ -15,7 +15,7 @@
.\"
.\"
.\" @(#)pkg_create.1
-.\" $Id: pkg_create.1,v 1.19 1997/05/02 22:00:05 max Exp $
+.\" $Id: pkg_create.1,v 1.20 1997/06/19 15:18:29 jkh Exp $
.\"
.\" hacked up by John Kohl for NetBSD--fixed a few bugs, extended keywords,
.\" added dependency tracking, etc.
@@ -278,6 +278,18 @@ Format is the same as that used by the
command (well, considering that it's later handed off to it, that's
no surprise). Use without an arg to set back to default (extraction)
permissions.
+.It Cm @option Ar option
+Sets internal package options, the only two currently supported ones
+being
+.Ar extract-in-place ,
+which tells the pkg_add command not to extract the package's tarball
+into a staging area but rather directly into the target
+hierarchy (this is typically meant to be used only by distributions
+or other special package types), and
+.Ar preserve ,
+which tells pkg_add to move any existing files out of the way,
+preserving the previous contents (which are also resurrected on
+pkg_delete, so caveat emptor).
.It Cm @owner Ar user
Sets default ownership for all subsequently extracted files to
.Ar user .
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
index 6a2e74610673..2748235a6d85 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$";
+static const char *rcsid = "$Id: file.c,v 1.27 1997/02/22 16:09:47 peter Exp $";
#endif
/*
@@ -338,6 +338,40 @@ fileGetContents(char *fname)
return contents;
}
+/* Takes a filename and package name, returning (in "try") the canonical "preserve"
+ * name for it.
+ */
+Boolean
+make_preserve_name(char *try, int max, char *name, char *file)
+{
+ int len, i;
+
+ if ((len = strlen(file)) == 0)
+ return FALSE;
+ else
+ i = len - 1;
+ strncpy(try, file, max);
+ if (try[i] == '/') /* Catch trailing slash early and save checking in the loop */
+ --i;
+ for (; i; i--) {
+ if (try[i] == '/') {
+ try[i + 1]= '.';
+ strncpy(&try[i + 2], &file[i + 1], max - i - 2);
+ break;
+ }
+ }
+ if (!i) {
+ try[0] = '.';
+ strncpy(try + 1, file, max - 1);
+ }
+ /* I should probably be called rude names for these inline assignments */
+ strncat(try, ".", max -= strlen(try));
+ strncat(try, name, max -= strlen(name));
+ strncat(try, ".", max--);
+ strncat(try, "backup", max -= 6);
+ return TRUE;
+}
+
/* Write the contents of "str" to a file */
void
write_file(char *name, char *str)
@@ -347,7 +381,7 @@ write_file(char *name, char *str)
fp = fopen(name, "w");
if (!fp)
- barf("Can't fopen '%s' for writing.", name);
+ barf("Cannot fopen '%s' for writing.", name);
len = strlen(str);
if (fwrite(str, 1, len, fp) != len)
barf("Short fwrite on '%s', tried to write %d bytes.", name, len);
@@ -365,7 +399,7 @@ copy_file(char *dir, char *fname, char *to)
else
snprintf(cmd, FILENAME_MAX, "cp -p -r %s/%s %s", dir, fname, to);
if (vsystem(cmd))
- barf("Couldn't perform '%s'", cmd);
+ barf("Could not perform '%s'", cmd);
}
void
@@ -378,7 +412,7 @@ move_file(char *dir, char *fname, char *to)
else
snprintf(cmd, FILENAME_MAX, "mv %s/%s %s", dir, fname, to);
if (vsystem(cmd))
- barf("Couldn't perform '%s'", cmd);
+ barf("Could not perform '%s'", cmd);
}
/*
@@ -408,7 +442,7 @@ copy_hierarchy(char *dir, char *fname, Boolean to)
printf("Using '%s' to copy trees.\n", cmd);
#endif
if (system(cmd))
- barf("copy_file: Couldn't perform '%s'", cmd);
+ barf("copy_file: Could not perform '%s'", cmd);
}
/* Unpack a tar file */
diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c
index 8440e3cdb4de..58907b33f0a0 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.20 1997/06/29 10:41:49 jkh Exp $";
+static const char *rcsid = "$Id: plist.c,v 1.21 1997/06/30 03:15:40 jkh Exp $";
#endif
/*
@@ -414,13 +414,10 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
whinge("Unable to completely remove file '%s'", tmp);
fail = FAIL;
}
- if (preserve) {
- if (!name)
- whinge("preserve set but no package name supplied!");
- else {
- char tmp2[FILENAME_MAX];
+ if (preserve && name) {
+ char tmp2[FILENAME_MAX];
- snprintf(tmp2, FILENAME_MAX, "%s.%s", tmp, name);
+ if (make_preserve_name(tmp2, FILENAME_MAX, name, tmp)) {
if (fexists(tmp2)) {
if (rename(tmp2, tmp))
whinge("preserve: Unable to restore %s as %s, errno = %d", tmp2, tmp, errno);