diff options
| author | hubertf <hubertf@NetBSD.org> | 1997-10-16 00:50:20 +0000 |
|---|---|---|
| committer | hubertf <hubertf@NetBSD.org> | 1997-10-16 00:50:20 +0000 |
| commit | 508ee08a3437c4e7d719a2bdcede65bf82af1830 (patch) | |
| tree | c6b9b663df9bc38110d31d2e0b5c228942535465 | |
| parent | a35a2a56e452797b0a27b6a9675750f96ce37a72 (diff) | |
Second part of intrgration of FreeBSD pkg_install as of 971013.
This patch adds @option preserve and handling for -s (SrcDir)
option.
| -rw-r--r-- | usr.sbin/pkg_install/add/extract.c | 56 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/add/perform.c | 9 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/create.h | 5 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/main.c | 13 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/perform.c | 13 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/pkg_create.1 | 14 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 38 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/plist.c | 30 |
8 files changed, 146 insertions, 32 deletions
diff --git a/usr.sbin/pkg_install/add/extract.c b/usr.sbin/pkg_install/add/extract.c index b5988fc8bb4..29e2839c860 100644 --- a/usr.sbin/pkg_install/add/extract.c +++ b/usr.sbin/pkg_install/add/extract.c @@ -1,10 +1,10 @@ -/* $NetBSD: extract.c,v 1.4 1997/10/16 00:31:32 hubertf Exp $ */ +/* $NetBSD: extract.c,v 1.5 1997/10/16 00:50:20 hubertf Exp $ */ #ifndef lint #if 0 static const char *rcsid = "FreeBSD - Id: extract.c,v 1.17 1997/10/08 07:45:35 charnier Exp"; #else -static const char *rcsid = "$NetBSD: extract.c,v 1.4 1997/10/16 00:31:32 hubertf Exp $"; +static const char *rcsid = "$NetBSD: extract.c,v 1.5 1997/10/16 00:50:20 hubertf Exp $"; #endif #endif @@ -53,6 +53,32 @@ static const char *rcsid = "$NetBSD: extract.c,v 1.4 1997/10/16 00:31:32 hubertf perm_count = 0; \ } +static void +rollback(char *name, char *home, PackingList start, PackingList stop) +{ + PackingList q; + char try[FILENAME_MAX], bup[FILENAME_MAX], *dir; + + dir = home; + for (q = start; q != stop; q = q->next) { + if (q->type == PLIST_FILE) { + snprintf(try, FILENAME_MAX, "%s/%s", dir, q->name); + if (make_preserve_name(bup, FILENAME_MAX, name, try) && fexists(bup)) { + (void)chflags(try, 0); + (void)unlink(try); + if (rename(bup, try)) + warnx("rollback: unable to rename %s back to %s", bup, try); + } + } + else if (q->type == PLIST_CWD) { + if (strcmp(q->name, ".")) + dir = q->name; + else + dir = home; + } + } +} + void extract_plist(char *home, Package *pkg) { @@ -60,12 +86,13 @@ extract_plist(char *home, Package *pkg) char *last_file; char *where_args, *perm_args, *last_chdir; int maxargs, where_count = 0, perm_count = 0, add_count; + Boolean preserve; maxargs = sysconf(_SC_ARG_MAX) / 2; /* Just use half the argument space */ - where_args = malloc(maxargs); + where_args = alloca(maxargs); if (!where_args) cleanup(0), errx(2, "can't get argument list space"); - perm_args = malloc(maxargs); + perm_args = alloca(maxargs); if (!perm_args) cleanup(0), errx(2, "can't get argument list space"); @@ -74,6 +101,7 @@ extract_plist(char *home, Package *pkg) perm_args[0] = 0; last_chdir = 0; + preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE; /* Reset the world */ Owner = NULL; @@ -101,7 +129,23 @@ extract_plist(char *home, Package *pkg) char try[FILENAME_MAX]; /* first try to rename it into place */ - sprintf(try, "%s/%s", Directory, p->name); + snprintf(try, FILENAME_MAX, "%s/%s", Directory, p->name); + if (fexists(try)) { + (void)chflags(try, 0); /* XXX hack - if truly immutable, rename fails */ + if (preserve && PkgName) { + char pf[FILENAME_MAX]; + + if (make_preserve_name(pf, FILENAME_MAX, PkgName, try)) { + if (rename(try, pf)) { + warnx( + "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) { /* try to add to list of perms to be changed and run in bulk. */ if (p->name[0] == '/' || TOOBIG(p->name)) { @@ -186,6 +230,4 @@ extract_plist(char *home, Package *pkg) p = p->next; } PUSHOUT(Directory); - free(where_args); - free(perm_args); } diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index 4e8b4f3fe5c..fc779b4f84c 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -1,10 +1,10 @@ -/* $NetBSD: perform.c,v 1.4 1997/10/16 00:31:41 hubertf Exp $ */ +/* $NetBSD: perform.c,v 1.5 1997/10/16 00:50:24 hubertf Exp $ */ #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp"; #else -static const char *rcsid = "$NetBSD: perform.c,v 1.4 1997/10/16 00:31:41 hubertf Exp $"; +static const char *rcsid = "$NetBSD: perform.c,v 1.5 1997/10/16 00:50:24 hubertf Exp $"; #endif #endif @@ -477,11 +477,6 @@ cleanup(int signo) { if (signo) printf("Signal %d received, cleaning up..\n", signo); - if (Plist.head) { - if (!Fake) - delete_package(FALSE, FALSE, &Plist); - free_plist(&Plist); - } if (!Fake && LogDir[0]) vsystem("%s -rf %s", REMOVE_CMD, LogDir); leave_playpen(Home); diff --git a/usr.sbin/pkg_install/create/create.h b/usr.sbin/pkg_install/create/create.h index 1672b15fb59..702a05e0fa3 100644 --- a/usr.sbin/pkg_install/create/create.h +++ b/usr.sbin/pkg_install/create/create.h @@ -1,4 +1,4 @@ -/* $NetBSD: create.h,v 1.3 1997/10/16 00:31:49 hubertf Exp $ */ +/* $NetBSD: create.h,v 1.4 1997/10/16 00:50:28 hubertf Exp $ */ /* from FreeBSD Id: create.h,v 1.13 1997/10/08 07:46:19 charnier Exp */ @@ -33,10 +33,11 @@ extern char *Install; extern char *DeInstall; extern char *Contents; extern char *Require; -extern char PlayPen[]; +extern char *SrcDir; extern char *ExcludeFrom; extern char *Mtree; extern char *Pkgdeps; +extern char PlayPen[]; extern int Dereference; extern int PlistOnly; diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c index 46b5f33b9cc..109704bd947 100644 --- a/usr.sbin/pkg_install/create/main.c +++ b/usr.sbin/pkg_install/create/main.c @@ -1,10 +1,10 @@ -/* $NetBSD: main.c,v 1.3 1997/10/16 00:31:51 hubertf Exp $ */ +/* $NetBSD: main.c,v 1.4 1997/10/16 00:50:31 hubertf Exp $ */ #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: main.c,v 1.17 1997/10/08 07:46:23 charnier Exp"; #else -static const char *rcsid = "$NetBSD: main.c,v 1.3 1997/10/16 00:31:51 hubertf Exp $"; +static const char *rcsid = "$NetBSD: main.c,v 1.4 1997/10/16 00:50:31 hubertf Exp $"; #endif #endif @@ -23,20 +23,21 @@ static const char *rcsid = "$NetBSD: main.c,v 1.3 1997/10/16 00:31:51 hubertf Ex #include "lib.h" #include "create.h" -static char Options[] = "YNOhvf:p:P:c:d:i:k:r:t:X:D:m:"; +static char Options[] = "YNOhvf:p:P:c:d:i:k:r:t:X:D:m:s:"; char *Prefix = NULL; char *Comment = NULL; char *Desc = NULL; +char *SrcDir = NULL; char *Display = NULL; char *Install = NULL; char *DeInstall = NULL; char *Contents = NULL; char *Require = NULL; -char PlayPen[FILENAME_MAX]; char *ExcludeFrom = NULL; char *Mtree = NULL; char *Pkgdeps = NULL; +char PlayPen[FILENAME_MAX]; int Dereference = 0; int PlistOnly = 0; @@ -71,6 +72,10 @@ main(int argc, char **argv) Prefix = optarg; break; + case 's': + SrcDir = optarg; + break; + case 'f': Contents = optarg; break; diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index 924e2479d31..2c41292ca38 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -1,10 +1,10 @@ -/* $NetBSD: perform.c,v 1.3 1997/10/16 00:31:53 hubertf Exp $ */ +/* $NetBSD: perform.c,v 1.4 1997/10/16 00:50:34 hubertf Exp $ */ #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.38 1997/10/13 15:03:51 jkh Exp"; #else -static const char *rcsid = "$NetBSD: perform.c,v 1.3 1997/10/16 00:31:53 hubertf Exp $"; +static const char *rcsid = "$NetBSD: perform.c,v 1.4 1997/10/16 00:50:34 hubertf Exp $"; #endif #endif @@ -90,6 +90,14 @@ pkg_perform(char **pkgs) if (Verbose && !PlistOnly) printf(".\n"); } + + /* If a SrcDir override is set, add it now */ + if (SrcDir) { + if (Verbose && !PlistOnly) + printf("Using SrcDir value of %s\n", SrcDir); + add_plist(&plist, PLIST_SRC, SrcDir); + } + /* Slurp in the packing list */ read_plist(&plist, pkg_in); @@ -110,6 +118,7 @@ pkg_perform(char **pkgs) * hack. It's not a real create in progress. */ if (PlistOnly) { + check_list(home, &plist); write_plist(&plist, stdout); exit(0); } diff --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1 index 520a4bc71a7..20e8b367a46 100644 --- a/usr.sbin/pkg_install/create/pkg_create.1 +++ b/usr.sbin/pkg_install/create/pkg_create.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_create.1,v 1.5 1997/10/16 00:31:56 hubertf Exp $ +.\" $NetBSD: pkg_create.1,v 1.6 1997/10/16 00:50:37 hubertf Exp $ .\" .\" FreeBSD install - a package for the installation and maintainance .\" of non-core utilities. @@ -268,6 +268,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 +Set 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 Set 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 a901b41796f..ee5e275abee 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -1,10 +1,10 @@ -/* $NetBSD: file.c,v 1.3 1997/10/16 00:32:19 hubertf Exp $ */ +/* $NetBSD: file.c,v 1.4 1997/10/16 00:50:41 hubertf Exp $ */ #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp"; #else -static const char *rcsid = "$NetBSD: file.c,v 1.3 1997/10/16 00:32:19 hubertf Exp $"; +static const char *rcsid = "$NetBSD: file.c,v 1.4 1997/10/16 00:50:41 hubertf Exp $"; #endif #endif @@ -346,6 +346,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) diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c index ef2a6a9503f..8477afca595 100644 --- a/usr.sbin/pkg_install/lib/plist.c +++ b/usr.sbin/pkg_install/lib/plist.c @@ -1,10 +1,10 @@ -/* $NetBSD: plist.c,v 1.3 1997/10/16 00:32:28 hubertf Exp $ */ +/* $NetBSD: plist.c,v 1.4 1997/10/16 00:50:46 hubertf Exp $ */ #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp"; #else -static const char *rcsid = "$NetBSD: plist.c,v 1.3 1997/10/16 00:32:28 hubertf Exp $"; +static const char *rcsid = "$NetBSD: plist.c,v 1.4 1997/10/16 00:50:46 hubertf Exp $"; #endif #endif @@ -360,10 +360,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; @@ -385,6 +391,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg) break; case PLIST_FILE: + last_file = p->name; sprintf(tmp, "%s/%s", Where, p->name); if (isdir(tmp)) { warnx("attempting to delete directory `%s' as a file\n" @@ -409,13 +416,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)) { - warn("preserve: unable to completely remove file '%s'", tmp); + if (!Fake) { + if (delete_hierarchy(tmp, ign_err, nukedirs)) fail = FAIL; + if (preserve && name) { + char tmp2[FILENAME_MAX]; + + if (make_preserve_name(tmp2, FILENAME_MAX, name, tmp)) { + if (fexists(tmp2)) { + if (rename(tmp2, tmp)) + warn("preserve: unable to restore %s as %s", + tmp2, tmp); + } + } + } } } - last_file = p->name; break; case PLIST_DIR_RM: |
