From owner-p4-projects@FreeBSD.ORG Thu Jul 12 11:01:55 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id ABBA116A46E; Thu, 12 Jul 2007 11:01:55 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 4312016A46C for ; Thu, 12 Jul 2007 11:01:55 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 330D213C4AE for ; Thu, 12 Jul 2007 11:01:55 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l6CB1tsY012067 for ; Thu, 12 Jul 2007 11:01:55 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l6CB1s4x012064 for perforce@freebsd.org; Thu, 12 Jul 2007 11:01:55 GMT (envelope-from gcooper@FreeBSD.org) Date: Thu, 12 Jul 2007 11:01:55 GMT Message-Id: <200707121101.l6CB1s4x012064@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Cc: Subject: PERFORCE change 123369 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jul 2007 11:01:56 -0000 http://perforce.freebsd.org/chv.cgi?CH=123369 Change 123369 by gcooper@optimus-revised_pkgtools on 2007/07/12 11:01:40 create/perform.c: Move revision info to head of +CONTENTS file, where (IMO) it should belong. lib/plist.c: -Almost done with revised parser algorithm. Just a few kinks to work out in adding packages. -Also, cut down on command parsing time in plist_cmd by using improved search heuristics (if first char is 'd', search for 'isplay', 'irrm', etc). I'm trying to cut down on unnecessary looping which no doubt occurs in strcmp by unrolling the logic a bit. Affected files ... .. //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/create/perform.c#2 edit .. //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/plist.c#5 edit Differences ... ==== //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/create/perform.c#2 (text+ko) ==== @@ -206,6 +206,13 @@ /* Slurp in the packing list */ read_plist(&plist, pkg_in); + if (asprintf(&cp, "PKG_FORMAT_REVISION:%d.%d", PLIST_FMT_VER_MAJOR, + PLIST_FMT_VER_MINOR) == -1) { + errx(2, "%s: asprintf() failed", __func__); + } + add_plist_top(&plist, PLIST_COMMENT, cp); + free(cp); + /* Prefix should add an @cwd to the packing list */ if (Prefix) add_plist_top(&plist, PLIST_CWD, Prefix); @@ -221,13 +228,6 @@ if (find_plist(&plist, PLIST_NAME) == NULL) add_plist_top(&plist, PLIST_NAME, basename(pkg)); - if (asprintf(&cp, "PKG_FORMAT_REVISION:%d.%d", PLIST_FMT_VER_MAJOR, - PLIST_FMT_VER_MINOR) == -1) { - errx(2, "%s: asprintf() failed", __func__); - } - add_plist_top(&plist, PLIST_COMMENT, cp); - free(cp); - /* * We're just here for to dump out a revised plist for the FreeBSD ports * hack. It's not a real create in progress. ==== //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/plist.c#5 (text+ko) ==== @@ -309,55 +309,100 @@ } ++cp, ++sp; } + printf("COMMAND STRING: %s\nCMD: %s\nCP: %s\nSP: %s\n", s, cmd, cp, sp); + + if(!*(cmd+1)) + return FAIL; + if (arg) *arg = (char *)sp; - if (!strcmp(cmd, "cwd")) - return PLIST_CWD; - else if (!strcmp(cmd, "srcdir")) - return PLIST_SRC; - else if (!strcmp(cmd, "cd")) - return PLIST_CWD; + + if(*cmd == 'c') { + + if(!strcmp(cmd+1, "wd") || *(cmd+1) == 'd') { + printf("CWD IS: %s\n", sp); + return PLIST_CWD; + } + + else if(*(cmd+1) == 'o') { + + if(!strcmp(cmd+2, "mment")) { + if (!strncmp(*arg, "ORIGIN:", 7)) { + *arg += 7; + return PLIST_ORIGIN; + } else if (!strncmp(*arg, "DEPORIGIN:", 10)) { + *arg += 10; + return PLIST_DEPORIGIN; + } + return PLIST_COMMENT; + + } else if(!strcmp(cmd+2, "nflicts")) { + return PLIST_CONFLICTS; + } + + } + + } + 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")) - return PLIST_CHOWN; + else if(*cmd == 'i') { + + if (!strcmp(cmd+1, "gnore")) + return PLIST_IGNORE; + else if(!strcmp(cmd+1, "gnore_inst")) + return PLIST_IGNORE_INST; + + } + + else if (*cmd == 'd') { + + if (!strcmp(cmd+1, "irrm")) + return PLIST_DIR_RM; + else if(!strcmp(cmd+1, "isplay")) + return PLIST_DISPLAY; + + } + + else if (*cmd == 'n') { + + if (!strcmp(cmd+1, "oinst")) + return PLIST_NOINST; + else if(!strcmp(cmd+1, "ame")) + return PLIST_NAME; + + } + + else if (!strcmp(cmd, "srcdir")) + return PLIST_SRC; + + else if (*cmd == 'm') { + + if(!strcmp(cmd+1, "ode")) + return PLIST_CHMOD; + else if(!strcmp(cmd+1, "tree")) + return PLIST_MTREE; + + } + + else if (*cmd == 'o') { + + if(!strcmp(cmd+1, "wner")) + return PLIST_CHOWN; + else if (!strcmp(cmd+1, "ption")) + return PLIST_OPTION; + + } + else if (!strcmp(cmd, "group")) return PLIST_CHGRP; - else if (!strcmp(cmd, "noinst")) - return PLIST_NOINST; - else if (!strcmp(cmd, "comment")) { - if (!strncmp(*arg, "ORIGIN:", 7)) { - *arg += 7; - return PLIST_ORIGIN; - } else if (!strncmp(*arg, "DEPORIGIN:", 10)) { - *arg += 10; - return PLIST_DEPORIGIN; - } - return PLIST_COMMENT; - } else if (!strcmp(cmd, "ignore")) - return PLIST_IGNORE; - else if (!strcmp(cmd, "ignore_inst")) - return PLIST_IGNORE_INST; - else if (!strcmp(cmd, "name")) - return PLIST_NAME; - else if (!strcmp(cmd, "display")) - return PLIST_DISPLAY; else if (!strcmp(cmd, "pkgdep")) return PLIST_PKGDEP; - else if (!strcmp(cmd, "conflicts")) - return PLIST_CONFLICTS; - else if (!strcmp(cmd, "mtree")) - return PLIST_MTREE; - else if (!strcmp(cmd, "dirrm")) - return PLIST_DIR_RM; - else if (!strcmp(cmd, "option")) - return PLIST_OPTION; - else - return FAIL; + + return FAIL; + } void @@ -367,7 +412,7 @@ } void -read_plist_np_revised(Package *pkg, FILE *fp) +read_plist_np(Package *pkg, FILE *fp) { struct stat contents_stat; @@ -390,11 +435,13 @@ assert(contents_stat.st_size != 0); - plines = (char*) malloc(contents_stat.st_size); + plines = (char*) calloc(1, contents_stat.st_size); for(i = 0; !feof(fp) && i <= contents_stat.st_size; i++) *(plines+i) = fgetc(fp); +// printf("+CONTENTS DUMP: %s\n", plines); + /* Avoid strangely crafted files with zero-length, but non-zero size */ assert(i != 0); @@ -404,75 +451,83 @@ if(trim_end_whitespace(pline)) { - int major, minor; + if(*pline != CMD_CHAR) { + cmd = PLIST_FILE; + } + + else { + + int major, minor; + + pline++; + + cp = pline; - cp = pline; + cmd = plist_cmd(pline, &cp); - cmd = plist_cmd(pline, &cp); + if (cmd != PLIST_COMMENT) { + errx(-1, "First line of +CONTENTS file was invalid (should be a " + "package version signature)!\nLine was: %s", pline); + } - if (cmd == FAIL) { - warnx("%s: unknown command '%s' (package tools out of date?)", - __func__, cp); - } + if (cmd == PLIST_COMMENT && + sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n", &major, &minor) == 2) { - else if (*cp == '\0') { - cp = NULL; - } + pkg->fmtver_maj = major; + pkg->fmtver_mnr = minor; - else if (cmd == PLIST_COMMENT && sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n", - &major, &minor) == 2) { - pkg->fmtver_maj = major; - pkg->fmtver_mnr = minor; + /* + * If the version is greater than the version major.minor, we + * have a compatibility problem.. + */ + if (0 < verscmp(pkg, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR)) { + warnx("plist format revision (%d.%d) is higher than supported" + "(%d.%d)", pkg->fmtver_maj, pkg->fmtver_mnr, + PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR); - /* - * If the version is greater than the version major.minor, we - * have a compatibility problem.. - */ - if (0 < verscmp(pkg, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR)) { - warnx("plist format revision (%d.%d) is higher than supported" - "(%d.%d)", pkg->fmtver_maj, pkg->fmtver_mnr, - PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR); + if (pkg->fmtver_maj > PLIST_FMT_VER_MAJOR) { + cleanup(0); + exit(2); + } - if (pkg->fmtver_maj > PLIST_FMT_VER_MAJOR) { - cleanup(0); - exit(2); - } + } } + + } - } + } else + errx(-1, "Length of first line was 0. This shouldn't happen"); - } + add_plist(pkg, cmd, cp); /* Now let's iterate through the lines and parse the commands */ while( NULL != (pline = strtok(NULL, "\n")) ) { if(trim_end_whitespace(pline)) { - - if (*pline != CMD_CHAR) - cmd = PLIST_FILE; - else { + cp = pline; - cp = pline; + if(*pline == CMD_CHAR) { - cmd = plist_cmd(pline, &cp); + cmd = plist_cmd(pline+1, &cp); if (cmd == FAIL) { warnx("%s: unknown command '%s' (package tools out of date?)", __func__, cp); - } else if (*cp == '\0') { + } else if (*cp == '\0') cp = NULL; - } - add_plist(pkg, cmd, cp); + } else + cmd = PLIST_FILE; - } + add_plist(pkg, cmd, cp); } } + free(plines); } @@ -489,7 +544,7 @@ /* Read a packing list from a file */ void -read_plist_np(Package *pkg, FILE *fp) +read_plist_old_np(Package *pkg, FILE *fp) { #if BUFFER_TRY