PERFORCE change 178849 for review
Ivan Voras
ivoras at FreeBSD.org
Wed May 26 23:56:35 UTC 2010
http://p4web.freebsd.org/@@178849?ac=10
Change 178849 by ivoras at 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 <sys/param.h>
#include <sys/utsname.h>
-#include <err.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -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 <sys/param.h>
#include <sys/utsname.h>
-#include <err.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -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 <sys/param.h>
#include <sys/utsname.h>
-#include <err.h>
+#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <paths.h>
#include <err.h>
+#include <fts.h>
#include <pkg.h>
#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);
+}
More information about the p4-projects
mailing list