PERFORCE change 178844 for review
Ivan Voras
ivoras at FreeBSD.org
Wed May 26 22:52:26 UTC 2010
http://p4web.freebsd.org/@@178844?ac=10
Change 178844 by ivoras at 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 <bsd.own.mk>
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 <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#include <paths.h>
#include <err.h>
#include <pkg.h>
@@ -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
More information about the p4-projects
mailing list