Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-4]: src/usr.sbin/pkg_install/add Pull up revision 1.20:



details:   https://anonhg.NetBSD.org/src/rev/2368b91c9fef
branches:  netbsd-1-4
changeset: 469372:2368b91c9fef
user:      he <he%NetBSD.org@localhost>
date:      Mon Sep 13 21:10:29 1999 +0000

description:
Pull up revision 1.20:
  Bring closer to /usr/share/misc/style with the aid of indent(1).  (hubertf)

diffstat:

 usr.sbin/pkg_install/add/extract.c |  458 ++++++++++++++++++------------------
 1 files changed, 228 insertions(+), 230 deletions(-)

diffs (truncated from 501 to 300 lines):

diff -r 000150d1c8e6 -r 2368b91c9fef usr.sbin/pkg_install/add/extract.c
--- a/usr.sbin/pkg_install/add/extract.c        Mon Sep 13 21:07:37 1999 +0000
+++ b/usr.sbin/pkg_install/add/extract.c        Mon Sep 13 21:10:29 1999 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: extract.c,v 1.16.2.1 1999/08/22 17:25:06 he Exp $      */
+/*     $NetBSD: extract.c,v 1.16.2.2 1999/09/13 21:10:29 he Exp $      */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static const char *rcsid = "FreeBSD - Id: extract.c,v 1.17 1997/10/08 07:45:35 charnier Exp";
 #else
-__RCSID("$NetBSD: extract.c,v 1.16.2.1 1999/08/22 17:25:06 he Exp $");
+__RCSID("$NetBSD: extract.c,v 1.16.2.2 1999/09/13 21:10:29 he Exp $");
 #endif
 #endif
 
@@ -60,257 +60,255 @@
                    perm_count = 0;                                     \
        }
 
+
 static void
 rollback(char *name, char *home, plist_t *start, plist_t *stop)
 {
-    plist_t *q;
-    char try[FILENAME_MAX], bup[FILENAME_MAX], *dir;
+       plist_t *q;
+       char    try[FILENAME_MAX], bup[FILENAME_MAX], *dir;
 
-    dir = home;
-    for (q = start; q != stop; q = q->next) {
-       if (q->type == PLIST_FILE) {
-           (void) snprintf(try, sizeof(try), "%s/%s", dir, q->name);
-           if (make_preserve_name(bup, sizeof(bup), 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);
-           }
+       dir = home;
+       for (q = start; q != stop; q = q->next) {
+               if (q->type == PLIST_FILE) {
+                       (void) snprintf(try, sizeof(try), "%s/%s", dir, q->name);
+                       if (make_preserve_name(bup, sizeof(bup), 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;
+               }
        }
-       else if (q->type == PLIST_CWD) {
-           if (strcmp(q->name, "."))
-               dir = q->name;
-           else
-               dir = home;
-       }
-    }
 }
 
 void
 extract_plist(char *home, package_t *pkg)
 {
-    plist_t *p = pkg->head;
-    char *last_file;
-    char *where_args, *perm_args, *last_chdir;
-    int maxargs, where_count = 0, perm_count = 0, add_count;
-    Boolean preserve;
+       plist_t *p = pkg->head;
+       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 = alloca(maxargs);
-    if (!where_args) {
-       cleanup(0);
-       errx(2, "can't get argument list space");
-    }
-    perm_args = alloca(maxargs);
-    if (!perm_args) {
-       cleanup(0);
-       errx(2, "can't get argument list space");
-    }
-    strcpy(where_args, TAR_CMD);
-    strcat(where_args, TAR_ARGS);
-    where_count = sizeof(TAR_CMD) + sizeof(TAR_ARGS) - 2;
-    perm_args[0] = 0;
+       maxargs = sysconf(_SC_ARG_MAX) / 2;     /* Just use half the argument space */
+       where_args = alloca(maxargs);
+       if (!where_args) {
+               cleanup(0);
+               errx(2, "can't get argument list space");
+       }
+       perm_args = alloca(maxargs);
+       if (!perm_args) {
+               cleanup(0);
+               errx(2, "can't get argument list space");
+       }
+       strcpy(where_args, TAR_CMD);
+       strcat(where_args, TAR_ARGS);
+       where_count = sizeof(TAR_CMD) + sizeof(TAR_ARGS) - 2;
+       perm_args[0] = 0;
+
+       last_chdir = 0;
+       preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
+
+       /* Reset the world */
+       Owner = NULL;
+       Group = NULL;
+       Mode = NULL;
+       last_file = NULL;
+       Directory = home;
+
+       /* Open Package Database for writing */
+       if (pkgdb_open(0) == -1) {
+               cleanup(0);
+               err(1, "can't open pkgdb");
+       }
+       /* Do it */
+       while (p) {
+               char    cmd[FILENAME_MAX];
 
-    last_chdir = 0;
-    preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
+               switch (p->type) {
+               case PLIST_NAME:
+                       PkgName = p->name;
+                       if (Verbose)
+                               printf("extract: Package name is %s\n", p->name);
+                       break;
 
-    /* Reset the world */
-    Owner = NULL;
-    Group = NULL;
-    Mode = NULL;
-    last_file = NULL;
-    Directory = home;
+               case PLIST_FILE:
+                       last_file = p->name;
+                       if (Verbose)
+                               printf("extract: %s/%s\n", Directory, p->name);
+                       if (!Fake) {
+                               char    try[FILENAME_MAX];
+
+                               if (strrchr(p->name, '\'')) {
+                                       cleanup(0);
+                                       errx(2, "Bogus filename \"%s\"", p->name);
+                               }
 
-    /* Open Package Database for writing */
-    if (pkgdb_open(0) == -1) {
-       cleanup(0);
-       err(1, "can't open pkgdb");
-    }
-    
-    /* Do it */
-    while (p) {
-       char cmd[FILENAME_MAX];
+                               /* first try to rename it into place */
+                               (void) snprintf(try, sizeof(try), "%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];
 
-       switch(p->type) {
-       case PLIST_NAME:
-           PkgName = p->name;
-           if (Verbose)
-               printf("extract: Package name is %s\n", p->name);
-           break;
+                                               if (make_preserve_name(pf, sizeof(pf), 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) {
+                                       /* note in pkgdb */
+                                       {
+                                               char   *s, t[FILENAME_MAX];
+                                               int     rc;
 
-       case PLIST_FILE:
-           last_file = p->name;
-           if (Verbose)
-               printf("extract: %s/%s\n", Directory, p->name);
-           if (!Fake) {
-               char try[FILENAME_MAX];
+                                               (void) snprintf(t, sizeof(t), "%s/%s", Directory, p->name);
+
+                                               s = pkgdb_retrieve(t);
+#ifdef PKGDB_DEBUG
+                                               printf("pkgdb_retrieve(\"%s\")=\"%s\"\n", t, s);        /* pkgdb-debug - HF */
+#endif
+                                               if (s)
+                                                       warnx("Overwriting %s - pkg %s bogus/conflicting?", t, s);
+                                               else {
+                                                       rc = pkgdb_store(t, PkgName);
+#ifdef PKGDB_DEBUG
+                                                       printf("pkgdb_store(\"%s\", \"%s\") = %d\n", t, PkgName, rc);   /* pkgdb-debug - HF */
+#endif
+
+                                               }
+                                       }
 
-               if (strrchr(p->name,'\'')) {
-                 cleanup(0);
-                 errx(2, "Bogus filename \"%s\"", p->name);
-               }
-               
-               /* first try to rename it into place */
-               (void) snprintf(try, sizeof(try), "%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];
+                                       /* try to add to list of perms to be changed and run in bulk. */
+                                       if (p->name[0] == '/' || TOOBIG(p->name)) {
+                                               PUSHOUT(Directory);
+                                       }
+                                       add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name);
+                                       if (add_count > maxargs - perm_count) {
+                                               cleanup(0);
+                                               errx(2, "oops, miscounted strings!");
+                                       }
+                                       perm_count += add_count;
+                               } else {
+                                       /* rename failed, try copying with a big tar command */
+                                       if (last_chdir != Directory) {
+                                               PUSHOUT(last_chdir);
+                                               last_chdir = Directory;
+                                       } else if (p->name[0] == '/' || TOOBIG(p->name)) {
+                                               PUSHOUT(Directory);
+                                       }
+                                       add_count = snprintf(&where_args[where_count], maxargs - where_count, " '%s'", p->name);
+                                       if (add_count > maxargs - where_count) {
+                                               cleanup(0);
+                                               errx(2, "oops, miscounted strings!");
+                                       }
+                                       where_count += add_count;
+                                       add_count = snprintf(&perm_args[perm_count],
+                                           maxargs - perm_count,
+                                           "'%s' ", p->name);
+                                       if (add_count > maxargs - perm_count) {
+                                               cleanup(0);
+                                               errx(2, "oops, miscounted strings!");
+                                       }
+                                       perm_count += add_count;
 
-                       if (make_preserve_name(pf, sizeof(pf), 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;
-                           }
+                                       /* note in pkgdb */
+                                       /* XXX would be better to store in PUSHOUT, but
+                                        * that would probably affect too much code I prefer
+                                        * not to touch - HF */
+                                       {
+                                               char   *s, t[FILENAME_MAX], *u;
+                                               int     rc;
+
+                                               if (p->name[0] == '/')
+                                                       u = p->name;
+                                               else {
+                                                       (void) snprintf(t, sizeof(t), "%s/%s", Directory, p->name);
+                                                       u = t;
+                                               }
+
+                                               s = pkgdb_retrieve(t);
+#ifdef PKGDB_DEBUG
+                                               printf("pkgdb_retrieve(\"%s\")=\"%s\"\n", t, s);        /* pkgdb-debug - HF */
+#endif
+                                               if (s)
+                                                       warnx("Overwriting %s - pkg %s bogus/conflicting?", t, s);
+                                               else {
+                                                       rc = pkgdb_store(t, PkgName);
+#ifdef PKGDB_DEBUG
+                                                       printf("pkgdb_store(\"%s\", \"%s\") = %d\n", t, PkgName, rc);   /* pkgdb-debug - HF */
+#endif
+                                               }
+                                       }
+                               }



Home | Main Index | Thread Index | Old Index