From owner-p4-projects@FreeBSD.ORG Wed May 26 23:56:35 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 34E181065781; Wed, 26 May 2010 23:56:35 +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 D4C331065769 for ; Wed, 26 May 2010 23:56:34 +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 C1B078FC17 for ; Wed, 26 May 2010 23:56:34 +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 o4QNuYTL034030 for ; Wed, 26 May 2010 23:56:34 GMT (envelope-from ivoras@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o4QNuYSI034028 for perforce@freebsd.org; Wed, 26 May 2010 23:56:34 GMT (envelope-from ivoras@FreeBSD.org) Date: Wed, 26 May 2010 23:56:34 GMT Message-Id: <201005262356.o4QNuYSI034028@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 178849 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 23:56:35 -0000 http://p4web.freebsd.org/@@178849?ac=10 Change 178849 by ivoras@betelgeuse on 2010/05/26 23:56:08 Step 2: Calculate the lists of files to unconditionally add or remove Affected files ... .. //depot/projects/soc2010/pkg_patch/src/patch/Makefile#5 edit .. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#4 edit .. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#4 edit .. //depot/projects/soc2010/pkg_patch/src/patch/main.c#5 edit .. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#3 edit .. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#3 edit .. //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#3 edit .. //depot/projects/soc2010/pkg_patch/src/patch/support.c#2 edit Differences ... ==== //depot/projects/soc2010/pkg_patch/src/patch/Makefile#5 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#4 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#4 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/main.c#5 (text+ko) ==== @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -102,7 +101,7 @@ static void atexit_handler(void) { - //rm_rf(my_tmp); + rm_rf(my_tmp); } ==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#3 (text+ko) ==== @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -39,6 +38,9 @@ char fold[PATH_MAX], fnew[PATH_MAX], fpatch[PATH_MAX]; char dold[PATH_MAX], dnew[PATH_MAX]; struct pkgxjob xold, xnew; + struct filelist_head flold, flnew; + struct filelist_head fldiff_old_new, fldiff_new_old; + struct filelist *fl; if (argc < 3) errx(1, "Expecting 3 arguments: old_package_file " @@ -75,4 +77,22 @@ if (pkgxjob_finish(&xnew) != 0) err(1, "Cannot extract package %s to %s (finish)", dnew, fnew); + SLIST_INIT(&flold); + filelist_gather(dold, &flold); + SLIST_INIT(&flnew); + filelist_gather(dnew, &flnew); + + SLIST_INIT(&fldiff_old_new); + filelist_diff(&flold, &flnew, &fldiff_old_new); + SLIST_INIT(&fldiff_new_old); + filelist_diff(&flnew, &flold, &fldiff_new_old); + + if (verbose > 1) { + SLIST_FOREACH(fl, &fldiff_new_old, linkage) + printf("++ %s\n", fl->filename); + SLIST_FOREACH(fl, &fldiff_old_new, linkage) + printf("-- %s\n", fl->filename); + } + + } ==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#3 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#3 (text+ko) ==== @@ -27,8 +27,15 @@ enum PP_OP { PP_NONE, PP_MKPATCH }; struct pkgxjob { - char *filename; - FILE *fp; + char *filename; + FILE *fp; +}; + +SLIST_HEAD(filelist_head, filelist); +struct filelist { + char filename[PATH_MAX]; + struct stat st; + SLIST_ENTRY(filelist) linkage; }; #ifndef PKG_PATCH_MAIN @@ -44,5 +51,8 @@ int rm_rf(char *dir); int pkgxjob_start(struct pkgxjob *job, char *dir, char *filename); int pkgxjob_finish(struct pkgxjob *job); +int filelist_gather(char *dir, struct filelist_head *head); +int filelist_diff(struct filelist_head *fl1, struct filelist_head *fl2, + struct filelist_head *diff); #endif ==== //depot/projects/soc2010/pkg_patch/src/patch/support.c#2 (text+ko) ==== @@ -22,12 +22,13 @@ #include #include -#include +#include #include #include #include #include #include +#include #include #include "pkg_patch.h" @@ -60,8 +61,68 @@ return (0); } + int pkgxjob_finish(struct pkgxjob *job) { return (pclose(job->fp)); } + + +int +filelist_gather(char *dir, struct filelist_head *head) +{ + FTS *fts; + FTSENT *fe; + char *path_argv[] = { dir, NULL }; + size_t dir_len; + + fts = fts_open(path_argv, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL); + if (fts == NULL) + return (-1); + dir_len = strlen(dir); + + while ( (fe = fts_read(fts)) != NULL) { + struct filelist *fl; + + if (fe->fts_info == FTS_D || fe->fts_info == FTS_F || + fe->fts_info == FTS_SL || fe->fts_info == FTS_SLNONE) { + if (fe->fts_pathlen == dir_len) + continue; + fl = malloc(sizeof(*fl)); + strncpy(fl->filename, fe->fts_path + dir_len + 1, + PATH_MAX); + memcpy(&fl->st, fe->fts_statp, sizeof(fl->st)); + SLIST_INSERT_HEAD(head, fl, linkage); + } + } + + fts_close(fts); + + return (0); +} + + +int +filelist_diff(struct filelist_head *flist1, struct filelist_head *flist2, + struct filelist_head *fldiff) +{ + struct filelist *fl1, *fl2; + int found; + + SLIST_FOREACH(fl1, flist1, linkage) { + found = 0; + SLIST_FOREACH(fl2, flist2, linkage) { + if (strncmp(fl1->filename, fl2->filename, PATH_MAX) == 0) { + found = 1; + break; + } + } + if (!found) { + fl2 = malloc(sizeof(*fl2)); + memcpy(fl2, fl1, sizeof(*fl2)); + SLIST_INSERT_HEAD(fldiff, fl2, linkage); + } + } + return (0); +}