From owner-p4-projects@FreeBSD.ORG Sat Jun 19 23:39:38 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 14ADC1065692; Sat, 19 Jun 2010 23:39:38 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 798D7106566C for ; Sat, 19 Jun 2010 23:39:37 +0000 (UTC) (envelope-from ivoras@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 5263A8FC19 for ; Sat, 19 Jun 2010 23:39:37 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o5JNdbUC004965 for ; Sat, 19 Jun 2010 23:39:37 GMT (envelope-from ivoras@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o5JNdbbN004963 for perforce@freebsd.org; Sat, 19 Jun 2010 23:39:37 GMT (envelope-from ivoras@FreeBSD.org) Date: Sat, 19 Jun 2010 23:39:37 GMT Message-Id: <201006192339.o5JNdbbN004963@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to ivoras@FreeBSD.org using -f From: Ivan Voras To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 179904 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Jun 2010 23:39:38 -0000 http://p4web.freebsd.org/@@179904?ac=10 Change 179904 by ivoras@betelgeuse on 2010/06/19 23:39:06 Read patch metadata Affected files ... .. //depot/projects/soc2010/pkg_patch/src/patch/Makefile#13 edit .. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.c#3 edit .. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.h#3 edit .. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#12 edit .. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#12 edit .. //depot/projects/soc2010/pkg_patch/src/patch/main.c#13 edit .. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#11 edit .. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#11 edit .. //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#11 edit .. //depot/projects/soc2010/pkg_patch/src/patch/support.c#10 edit Differences ... ==== //depot/projects/soc2010/pkg_patch/src/patch/Makefile#13 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/applypatch.c#3 (text+ko) ==== @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -34,15 +35,12 @@ #include "hashjob.h" -enum PPACTION { PPACTION_UNKNOWN, PPACTION_ADD, PPACTION_REMOVE, - PPACTION_RMDIR, PPACTION_PATCH }; enum PPMETHOD { PPMETHOD_UNKNOWN, PPMETHOD_CP, PPMETHOD_BSDIFF }; SLIST_HEAD(pplist_head, pplist); struct pplist { char filename[PATH_MAX]; - enum PPACTION action; enum PPMETHOD method; SLIST_ENTRY(pplist) linkage; }; @@ -53,7 +51,10 @@ short int version_minor; char source[PATH_MAX]; char target[PATH_MAX]; - struct pplist_head pplist; + struct pplist_head pp_add; + struct pplist_head pp_remove; + struct pplist_head pp_rmdir; + struct pplist_head pp_patch; }; @@ -61,28 +62,96 @@ read_pkgpatch_file(char *filename, struct pkgpatch *pp) { FILE *fp; - char line[PATH_MAX], *p, *p2, *cmd; + char line[PATH_MAX], *p, *p2, *p3, *cmd; + int llen; + struct pplist *pl; fp = fopen(filename, "r"); if (fp == NULL) err(1, "Cannot open file: %s", filename); memset(pp, 0, sizeof(*pp)); - SLIST_INIT(&pp->pplist); + SLIST_INIT(&pp->pp_add); + SLIST_INIT(&pp->pp_remove); + SLIST_INIT(&pp->pp_rmdir); + SLIST_INIT(&pp->pp_patch); + while (fgets(line, PATH_MAX, fp) != NULL) { + llen = strlen(line); + if (line[llen-1] == '\n') { + line[llen-1] = '\0'; /* strip newline */ + llen--; + } + p = strchr(line, '#'); /* skip comments */ + if (p != NULL) + *p = '\0'; + if (line[0] == '\0') /* skip empty lines */ + continue; cmd = line; p = strchr(line, ' '); + if (p == NULL) + errx(1, "Invalid command format in %s", PKGPATCH_FNAME); *p++ = '\0'; if (strcmp(cmd, "@version") == 0) { p2 = strchr(p, '.'); + if (p2 == NULL) + errx(1, "Invalid version format in %s", + PKGPATCH_FNAME); *p2++ = '\0'; pp->version_major = atoi(p); pp->version_minor = atoi(p2); } else if (strcmp(cmd, "@source") == 0) { + strlcpy(pp->source, p, PATH_MAX); } else if (strcmp(cmd, "@target") == 0) { + strlcpy(pp->target, p, PATH_MAX); } else if (strcmp(cmd, "@add") == 0) { + pl = calloc(1, sizeof(*pl)); + strlcpy(pl->filename, p, PATH_MAX); + SLIST_INSERT_HEAD(&pp->pp_add, pl, linkage); } else if (strcmp(cmd, "@remove") == 0) { + pl = calloc(1, sizeof(*pl)); + strlcpy(pl->filename, p, PATH_MAX); + SLIST_INSERT_HEAD(&pp->pp_remove, pl, linkage); } else if (strcmp(cmd, "@rmdir") == 0) { + pl = calloc(1, sizeof(*pl)); + strlcpy(pl->filename, p, PATH_MAX); + SLIST_INSERT_HEAD(&pp->pp_rmdir, pl, linkage); } else if (strcmp(cmd, "@patch") == 0) { + pl = calloc(1, sizeof(*pl)); + p2 = strchr(p, '['); + if (p2 != NULL) { + /* + * Parse options block of the form + * \[name=value[,name=value...]\] + */ + char m[100], *pm, *p4, *p5; + + p3 = strchr(p2, ']'); + assert(p3-p2 < (int)sizeof(m)); + strlcpy(m, p2 + 1, p3 - p2); + p3++; + while (*p3 == ' ') + p3++; + strlcpy(pl->filename, p3, PATH_MAX); + pm = m; + while ((p4 = strsep(&pm, ",")) != NULL) { + p5 = strchr(p4, '='); + if (p5 != NULL) + *p5++ = '\0'; + if (strcmp(p4, "method") == 0) { + if (p5 == NULL) + errx(1, "patch option " + "error"); + if (strcmp(p5, "bsdiff") == 0) + pl->method = + PPMETHOD_BSDIFF; + } + } + } else { + /* Default options */ + strlcpy(pl->filename, p, PATH_MAX); + pl->method = PPMETHOD_CP; + } + SLIST_INSERT_HEAD(&pp->pp_patch, pl, linkage); } else errx(1, "Unknown command: %s", cmd); @@ -118,5 +187,14 @@ snprintf(tmp, PATH_MAX, "%s/%s", dpatch, PKGPATCH_FNAME); read_pkgpatch_file(tmp, &pp); + if (pp.version_major != PKGPATCH_VERSION_MAJOR) + errx(1, "Invalid patch data format major version number: %d\n", + pp.version_major); + if (pp.version_minor > PKGPATCH_VERSION_MINOR) + errx(1, "Invalid patch data format minor version number: %d\n", + pp.version_minor); + if (Verbose) + printf("Read patch data, version %d.%d for '%s' to '%s'\n", + pp.version_major, pp.version_minor, pp.source, pp.target); } ==== //depot/projects/soc2010/pkg_patch/src/patch/applypatch.h#3 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#12 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#12 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/main.c#13 (text+ko) ==== @@ -60,7 +60,7 @@ proc_args() { int ch; - while ((ch = getopt(argc, argv, "bchv")) != -1) { + while ((ch = getopt(argc, argv, "abchv")) != -1) { switch (ch) { case 'a': patch_op = PP_APPLY; ==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#11 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#11 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#11 (text+ko) ==== @@ -28,6 +28,8 @@ #endif #define PKGPATCH_FNAME "+PKGPATCH" +#define PKGPATCH_VERSION_MAJOR 1 +#define PKGPATCH_VERSION_MINOR 0 #define PKGPATCH_VERSION "1.0" enum PP_OP { PP_NONE, PP_MKPATCH, PP_APPLY }; ==== //depot/projects/soc2010/pkg_patch/src/patch/support.c#10 (text+ko) ====