From owner-p4-projects@FreeBSD.ORG Wed May 26 22:52:26 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5FD861065676; Wed, 26 May 2010 22:52:25 +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 23606106566C for ; Wed, 26 May 2010 22:52:25 +0000 (UTC) (envelope-from ivoras@FreeBSD.org) Received: from repoman.freebsd.org (unknown [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 0FE5E8FC17 for ; Wed, 26 May 2010 22:52:25 +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 o4QMqNkD028201 for ; Wed, 26 May 2010 22:52:23 GMT (envelope-from ivoras@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o4QMqNHg028199 for perforce@freebsd.org; Wed, 26 May 2010 22:52:23 GMT (envelope-from ivoras@FreeBSD.org) Date: Wed, 26 May 2010 22:52:23 GMT Message-Id: <201005262252.o4QMqNHg028199@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 178844 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: Wed, 26 May 2010 22:52:26 -0000 http://p4web.freebsd.org/@@178844?ac=10 Change 178844 by ivoras@betelgeuse on 2010/05/26 22:51:56 Step 1: Extract old and new packages, prepare for comparison Affected files ... .. //depot/projects/soc2010/pkg_patch/src/patch/Makefile#4 edit .. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#3 edit .. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#3 edit .. //depot/projects/soc2010/pkg_patch/src/patch/main.c#4 edit .. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#2 edit .. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#2 edit .. //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#2 edit .. //depot/projects/soc2010/pkg_patch/src/patch/support.c#1 add Differences ... ==== //depot/projects/soc2010/pkg_patch/src/patch/Makefile#4 (text+ko) ==== @@ -3,7 +3,7 @@ .include PROG= pkg_patch -SRCS= main.c mkpatch.c hashjob.c +SRCS= main.c mkpatch.c support.c hashjob.c WARNS?= 4 WFORMAT?= 1 ==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#3 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#3 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/main.c#4 (text+ko) ==== @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -37,10 +38,14 @@ int argc; char **argv; enum PP_OP patch_op = PP_NONE; +char *my_tmp = NULL; +int verbose = 1; static void usage_short(void); static void proc_args(void); +static void proc_setup(void); +static void atexit_handler(void); static void @@ -53,7 +58,7 @@ proc_args() { int ch; - while ((ch = getopt(argc, argv, "mh")) != -1) { + while ((ch = getopt(argc, argv, "hmv")) != -1) { switch (ch) { case 'm': patch_op = PP_MKPATCH; @@ -62,6 +67,9 @@ usage_short(); exit(0); break; + case 'v': + verbose++; + break; default: usage_short(); exit(1); @@ -72,9 +80,36 @@ } +/* + * Process early setup things like making sure the environment is sane and + * creating the work directory. + */ void +proc_setup() +{ + if (access(_PATH_RM, X_OK) != 0) + errx(1, "Cannot execute %s", _PATH_RM); + if (access(_PATH_TAR, X_OK) != 0) + errx(1, "Cannot execute %s", _PATH_TAR); + asprintf(&my_tmp, "%spkg_patch.%d.%d", _PATH_TMP, getpid(), time(NULL)); + if (mkdir(my_tmp, 0700) != 0) + errx(1, "Cannot create working directory: %s", my_tmp); + if (verbose) + printf("Using temporary directory: %s\n", my_tmp); +} + + +static void +atexit_handler(void) +{ + //rm_rf(my_tmp); +} + + +void cleanup(int __unused sig) { + printf("cleanup() called\n"); } @@ -86,6 +121,8 @@ proc_args(); if (patch_op == PP_NONE) errx(1, "No operation switch given"); + atexit(atexit_handler); + proc_setup(); switch (patch_op) { case PP_MKPATCH: ==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#2 (text+ko) ==== @@ -36,8 +36,43 @@ void perform_mkpatch() { - char *file1 = argv[0]; - char *file2 = argv[1]; + char fold[PATH_MAX], fnew[PATH_MAX], fpatch[PATH_MAX]; + char dold[PATH_MAX], dnew[PATH_MAX]; + struct pkgxjob xold, xnew; + + if (argc < 3) + errx(1, "Expecting 3 arguments: old_package_file " + "new_package_file patch_file"); + if (realpath(argv[0], fold) == NULL) + err(1, "Error resolving path: %s", argv[0]); + if (realpath(argv[1], fnew) == NULL) + err(1, "Error resolving path: %s", argv[1]); + if (realpath(argv[2], fpatch) == NULL) + err(1, "Error resolving path: %s", argv[2]); + + if (access(fold, F_OK) != 0) + err(1, "File not found: %s", fold); + if (access(fnew, F_OK) != 0) + err(1, "File not found: %s", fnew); + if (access(fold, R_OK) != 0) + err(1, "Access error reading file: %s", fold); + if (access(fnew, R_OK) != 0) + err(1, "Access error reading file: %s", fnew); + + sprintf(dold, "%s/old", my_tmp); + if (mkdir(dold, 0700) != 0) + err(1, "Cannot create directory: %s", dold); + sprintf(dnew, "%s/new", my_tmp); + if (mkdir(dnew, 0700) != 0) + err(1, "Cannot create directory: %s", dnew); + + if (pkgxjob_start(&xold, dold, fold) != 0) + err(1, "Cannot extract package %s to %s (start)", fold, dold); + if (pkgxjob_start(&xnew, dnew, fnew) != 0) + err(1, "Cannot extract package %s to %s (start)", dnew, fnew); + if (pkgxjob_finish(&xold) != 0) + err(1, "Cannot extract package %s to %s (finish)", fold, dold); + if (pkgxjob_finish(&xnew) != 0) + err(1, "Cannot extract package %s to %s (finish)", dnew, fnew); - printf("file1=%s, file2=%s\n", file1, file2); } ==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#2 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#2 (text+ko) ==== @@ -20,14 +20,29 @@ #ifndef _PKG_PATCH_H_ #define _PKG_PATCH_H_ +#ifndef _PATH_TAR +#define _PATH_TAR "/usr/bin/tar" +#endif + enum PP_OP { PP_NONE, PP_MKPATCH }; +struct pkgxjob { + char *filename; + FILE *fp; +}; + #ifndef PKG_PATCH_MAIN extern int argc; extern char **argv; extern enum PP_OP patch_op; +extern char *my_tmp; +extern int verbose; #endif +int rm_rf(char *dir); +int pkgxjob_start(struct pkgxjob *job, char *dir, char *filename); +int pkgxjob_finish(struct pkgxjob *job); + #endif