Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Jun 2010 01:02:11 GMT
From:      Ivan Voras <ivoras@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 179932 for review
Message-ID:  <201006200102.o5K12B9L023258@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@179932?ac=10

Change 179932 by ivoras@betelgeuse on 2010/06/20 01:01:40

	Start parsing +CONTENTS

Affected files ...

.. //depot/projects/soc2010/pkg_patch/src/patch/Makefile#14 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.c#4 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.h#4 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#13 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#13 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/main.c#14 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#12 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#12 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#12 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/support.c#11 edit

Differences ...

==== //depot/projects/soc2010/pkg_patch/src/patch/Makefile#14 (text+ko) ====


==== //depot/projects/soc2010/pkg_patch/src/patch/applypatch.c#4 (text+ko) ====

@@ -22,6 +22,7 @@
 
 #include <sys/param.h>
 #include <sys/utsname.h>
+#include <sys/queue.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -38,11 +39,11 @@
 enum PPMETHOD { PPMETHOD_UNKNOWN, PPMETHOD_CP, PPMETHOD_BSDIFF };
 
 
-SLIST_HEAD(pplist_head, pplist);
+STAILQ_HEAD(pplist_head, pplist);
 struct pplist {
 	char 			filename[PATH_MAX];
 	enum PPMETHOD		method;
-	SLIST_ENTRY(pplist)	linkage;
+	STAILQ_ENTRY(pplist)	linkage;
 };
 
 
@@ -70,10 +71,10 @@
 	if (fp == NULL)
 		err(1, "Cannot open file: %s", filename);
 	memset(pp, 0, sizeof(*pp));
-	SLIST_INIT(&pp->pp_add);
-	SLIST_INIT(&pp->pp_remove);
-	SLIST_INIT(&pp->pp_rmdir);
-	SLIST_INIT(&pp->pp_patch);
+	STAILQ_INIT(&pp->pp_add);
+	STAILQ_INIT(&pp->pp_remove);
+	STAILQ_INIT(&pp->pp_rmdir);
+	STAILQ_INIT(&pp->pp_patch);
 	
 	while (fgets(line, PATH_MAX, fp) != NULL) {
 		llen = strlen(line);
@@ -106,15 +107,15 @@
 		} 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);
+			STAILQ_INSERT_TAIL(&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);
+			STAILQ_INSERT_TAIL(&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);
+			STAILQ_INSERT_TAIL(&pp->pp_rmdir, pl, linkage);
 		} else if (strcmp(cmd, "@patch") == 0) {
 			pl = calloc(1, sizeof(*pl));
 			p2 = strchr(p, '[');
@@ -125,6 +126,7 @@
 				 */
 				char m[100], *pm, *p4, *p5;
 				
+				pm = m;
 				p3 = strchr(p2, ']');
 				assert(p3-p2 < (int)sizeof(m));
 				strlcpy(m, p2 + 1, p3 - p2);
@@ -132,7 +134,6 @@
 				while (*p3 == ' ')
 					p3++;
 				strlcpy(pl->filename, p3, PATH_MAX);
-				pm = m;
 				while ((p4 = strsep(&pm, ",")) != NULL) {
 					p5 = strchr(p4, '=');
 					if (p5 != NULL)
@@ -151,7 +152,7 @@
 				strlcpy(pl->filename, p, PATH_MAX);
 				pl->method = PPMETHOD_CP;
 			}
-			SLIST_INSERT_HEAD(&pp->pp_patch, pl, linkage);
+			STAILQ_INSERT_TAIL(&pp->pp_patch, pl, linkage);
 		} else
 			errx(1, "Unknown command: %s", cmd);
 		
@@ -186,6 +187,8 @@
 		    dpatch);
 
 	snprintf(tmp, PATH_MAX, "%s/%s", dpatch, PKGPATCH_FNAME);
+	
+	/* Step 1 - read the patch metadata */
 	read_pkgpatch_file(tmp, &pp);
 	if (pp.version_major != PKGPATCH_VERSION_MAJOR)
 		errx(1, "Invalid patch data format major version number: %d\n",
@@ -197,4 +200,6 @@
 		printf("Read patch data, version %d.%d for '%s' to '%s'\n",
 		    pp.version_major, pp.version_minor, pp.source, pp.target);
 	
+	/* Step 2 - read the existing (live system) package data */
+	
 }

==== //depot/projects/soc2010/pkg_patch/src/patch/applypatch.h#4 (text+ko) ====


==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#13 (text+ko) ====


==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#13 (text+ko) ====


==== //depot/projects/soc2010/pkg_patch/src/patch/main.c#14 (text+ko) ====

@@ -60,7 +60,7 @@
 proc_args() {
 	int ch;
 	
-	while ((ch = getopt(argc, argv, "abchv")) != -1) {
+	while ((ch = getopt(argc, argv, "abcfhv")) != -1) {
 		switch (ch) {
 		case 'a':
 			patch_op = PP_APPLY;
@@ -71,6 +71,9 @@
 		case 'c':
 			patch_op = PP_MKPATCH;
 			break;
+		case 'f':
+			Force++;
+			break;
 		case 'h':
 			usage_short();
 			exit(0);

==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#12 (text+ko) ====


==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#12 (text+ko) ====


==== //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#12 (text+ko) ====

@@ -21,10 +21,10 @@
 #define _PKG_PATCH_H_
 
 #ifndef _PATH_TAR
-#define _PATH_TAR "/usr/bin/tar"
+#define _PATH_TAR 	"/usr/bin/tar"
 #endif
 #ifndef _PATH_BSDIFF
-#define _PATH_BSDIFF "/usr/bin/bsdiff"
+#define _PATH_BSDIFF 	"/usr/bin/bsdiff"
 #endif
 
 #define PKGPATCH_FNAME		"+PKGPATCH"
@@ -32,6 +32,11 @@
 #define PKGPATCH_VERSION_MINOR	0
 #define PKGPATCH_VERSION 	"1.0"
 
+#ifndef PKG_DBDIR
+/* So much cruft... */
+#define PKG_DBDIR 	LOG_DIR
+#endif
+
 enum PP_OP { PP_NONE, PP_MKPATCH, PP_APPLY };
 
 struct pkgxjob {
@@ -46,6 +51,22 @@
 	SLIST_ENTRY(filelist) 	linkage;
 };
 
+STAILQ_HEAD(pkg_plist_head, pkg_plist);
+struct pkg_plist {
+	char		name[PATH_MAX];
+	plist_t		type;
+	STAILQ_ENTRY(pkg_plist)	linkage;
+};
+
+struct pkg_metadata {
+	char		name[PATH_MAX];
+	char		origin[PATH_MAX];
+	char		pkg_format_revision[16];
+	char		prefix[PATH_MAX];
+	struct pkg_plist_head	plist;
+};
+
+
 #ifndef PKG_PATCH_MAIN
 
 extern int argc;
@@ -70,5 +91,6 @@
 int copy_file_absolute(char *from, char *to);
 int copy_file_attrs(char *from, struct stat *st_from, char *to);
 int replicate_dirtree(char *from, char *to);
+int read_package(char *name, struct pkg_metadata *pkg);
 
 #endif

==== //depot/projects/soc2010/pkg_patch/src/patch/support.c#11 (text+ko) ====

@@ -217,23 +217,23 @@
 		assert(from != NULL);
 		if (lstat(from, &st2) < 0) {
 			warn("copy_file_attrs: lstat(%s) failed", from);
-			return (errno);
+			return (-errno);
 		}
 		st = &st2;
 	}
 	if (chown(to, st->st_uid, st->st_gid) < 0) {
 		warn("copy_file_attrs: chown() failed");
-		return (errno);
+		return (-errno);
 	}
 	tv[0].tv_usec = tv[1].tv_usec = 0;
 	tv[0].tv_sec = tv[1].tv_sec = st->st_mtime;
 	if (lutimes(to, tv) < 0) {
 		warn("copy_file_attrs: lutimes(%s,%d) failed", to, st->st_mtime);
-		return (errno);
+		return (-errno);
 	}
 	if (lchmod(to, st->st_mode) < 0) {
 		warn("copy_file_attrs: lchmod(%o) failed", st->st_mode);
-		return (errno);
+		return (-errno);
 	}
 	return (0);
 }
@@ -322,12 +322,12 @@
 			if (access(new_dir, F_OK) == 0)
 				continue;
 			if (mkdir(new_dir, 0700) < 0) {
-				rval = errno;
+				rval = -errno;
 				goto end;
 			}
 			if (copy_file_attrs(fe->fts_path, fe->fts_statp,
 			    new_dir) != 0) {
-				rval = errno;
+				rval = -errno;
 				goto end;
 			}
 		}
@@ -337,3 +337,64 @@
 		return (-1);
 	return (rval);
 }
+
+
+/*
+ * Reads the package metadata for the given package name in the package database
+ * structure. The name is a full package name, e.g. "sqlite3-3.6.19".
+ * Hopefully, one day, someone will make a canonical way to do this instead
+ * of reinwenting the wheel. The actual format of +CONTENTS is very lame.
+ */
+int
+read_package(char *name, struct pkg_metadata *pkg)
+{
+	char pfilename[PATH_MAX], line[PATH_MAX];
+	FILE *fp;
+	struct pkg_plist *pl;
+	int llen, rval;
+	
+	snprintf(pfilename, PATH_MAX, "%s/%s/%s", PKG_DBDIR, name,
+	    CONTENTS_FNAME);
+	if (access(pfilename, R_OK) != 0) {
+		warn("Cannot access %s for reading.", pfilename);
+		return (-errno);
+	}
+	fp = fopen(pfilename, "r");
+	if (fp == NULL)
+		return (-errno);
+	
+	rval = 0;
+	while (fgets(line, PATH_MAX, fp) != NULL) {
+		char *p, *cmd;
+		
+		llen = strlen(line);
+		if (line[llen-1] == '\n') {
+			line[llen-1] = '\0';	/* strip newline */
+			llen--;
+		}
+		if (line[0] == '\0')
+			continue;
+		if (line[0] == CMD_CHAR) {
+			cmd = line + 1;
+			p = strchr(line, ' ');
+			if (p == NULL) {
+				rval = -1;
+				goto error;
+			}
+			*p++ = '\0';
+			if (strcmp(cmd, "comment") == 0) {
+			}
+		} else {
+			pl = calloc(1, sizeof(*pl));
+			pl->type = PLIST_FILE;
+			STAILQ_INSERT_TAIL(&pkg->plist, pl, linkage);
+		}
+	}
+	
+	return (0);
+error:
+	if (fp != NULL)
+		fclose(fp);
+	return (rval);
+}
+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006200102.o5K12B9L023258>