PERFORCE change 182286 for review

Ivan Voras ivoras at FreeBSD.org
Thu Aug 12 00:22:23 UTC 2010


http://p4web.freebsd.org/@@182286?ac=10

Change 182286 by ivoras at ursaminor on 2010/08/12 00:21:19

	Introduce and use pkg_repo_url in PKGPATCHINDEX

Affected files ...

.. //depot/projects/soc2010/pkg_patch/src/patch/Makefile#33 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.c#23 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.h#23 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#32 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#32 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/main.c#33 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#31 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#31 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatchdir.c#16 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatchdir.h#15 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.1#4 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#31 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/support.c#30 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/updateweb.c#11 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/updateweb.h#11 edit

Differences ...

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


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


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


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


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


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

@@ -42,6 +42,7 @@
 enum PP_OP patch_op = PP_NONE;
 char *my_tmp = NULL;
 int flag_bsdiff = 0;
+char *pkg_repo_url = NULL;
 
 
 static void usage_short(void);
@@ -53,9 +54,11 @@
 static void
 usage_short() {
 	printf("usage:\n");
-	printf("\t%s -c [-b] package_file_1 package_file_2 patch_file\n", argv[0]);
+	printf("\t%s -c [-b] package_file_1 package_file_2 patch_file\n",
+	    argv[0]);
 	printf("\t%s -a patch_file\n", argv[0]);
-	printf("\t%s -m [-b] package_dir_1 package_dir_2 patch_dir\n", argv[0]);
+	printf("\t%s -m [-b] [-r url_repo] package_dir_1 package_dir_2 "
+	    "patch_dir\n", argv[0]);
 	printf("\t%s -u [url]\n", argv[0]);
 }
 
@@ -64,7 +67,7 @@
 proc_args() {
 	int ch;
 	
-	while ((ch = getopt(argc, argv, "abcfhmuv")) != -1) {
+	while ((ch = getopt(argc, argv, "abcfhmp:uv")) != -1) {
 		switch (ch) {
 		case 'a':
 			patch_op = PP_APPLY;
@@ -85,6 +88,9 @@
 		case 'm':
 			patch_op = PP_MKPATCHDIR;
 			break;
+		case 'r':
+			pkg_repo_url = strdup(optarg);
+			break;
 		case 'v':
 			Verbose++;
 			break;

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


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


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

@@ -64,6 +64,10 @@
 	if (access(dpatch, W_OK) != 0)
 		err(1, "Access error writing directory: %s", dpatch);
 	
+	if (pkg_repo_url == NULL)
+		warnx("Package repository URL not specified for this "
+		    "patchset. Read the manual for details.");
+	
 	snprintf(flog, PATH_MAX, "%s/%s", dpatch, PKGPATCHINDEX_FNAME);
 	fpl = fopen(flog, "a+");
 	if (fpl == NULL)
@@ -83,6 +87,8 @@
 	fprintf(fpl, "# Created by mkpatchdir at %s\n", time_ctime(-1));
 	fprintf(fpl, "@version %d.%d\n", PKGPATCH_VERSION_MAJOR,
 	    PKGPATCH_VERSION_MINOR);
+	if (pkg_repo_url != NULL)
+		fprintf(fpl, "@pkgrepo %s\n", pkg_repo_url);
 	
 	SLIST_FOREACH(pl, &pkglist, linkage) {
 		char pname[PATH_MAX];

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


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

@@ -15,7 +15,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 9, 2010
+.Dd August 9, 2010
 .Dt PKG_PATCH 1
 .Os
 .Sh NAME
@@ -71,27 +71,27 @@
 .It Fl u
 Compare the current system state with the package patch repository and
 update any packages found to need updating.
+.It Fl h
+Show usage help message.
 .Sh TECHNICAL DETAILS
 The
 .Nm
 utility operates on binary package files and on the live system, including
 the package database in
 .Pa /var/db/pkg .
-All modes of operation require
+All documented modes of operation require
 .Nm
 to be run as the superuser.
 Currently,
 .Nm
-does not invoke any scripts specified in the package files.
+does not invoke any scripts or commands specified in the package files.
 .Sh SEE ALSO
 .Xr pkg_add 1 ,
 .Xr pkg_create 1 ,
 .Xr pkg_delete 1 ,
 .Xr pkg_info 1 ,
 .Xr pkg_version 1 ,
-.Xr mktemp 3 ,
-.Xr sysconf 3 ,
-.Xr mtree 8
+.Xr bsdiff 1
 .Sh AUTHORS
 .An Ivan Voras Aq ivoras at freebsd.org
 .Sh BUGS

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

@@ -130,6 +130,7 @@
 extern enum PP_OP patch_op;
 extern char *my_tmp;
 extern int flag_bsdiff;
+extern char *pkg_repo_url;
 
 #endif
 

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


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

@@ -48,21 +48,29 @@
 	TAILQ_ENTRY(patchrec)	linkage;
 };
 
+struct patch_index {
+	int	ver_major;
+	int	ver_minor;
+	char	*pkg_repo_url;
+	struct patchrec_list prlist;
+};
+
 static int
-read_pkgpatchindex_file(struct patchrec_list *prlist, char *fname)
+read_pkgpatchindex_file(struct patch_index *pindex, char *fname)
 {
 	char line[4*PKGNAME_MAX];
 	char *cmd, *param;
 	FILE *f;
 	char *p;
+	struct patchrec_list *prlist;
 	
+	prlist = &pindex->prlist;
+	
 	f = fopen(fname, "r");
 	if (f == NULL)
 		return (-1);
 	
 	while (fgets(line, sizeof(line), f) != NULL) {
-		int vmajor, vminor;
-		
 		p = strchr(line, '#');
 		if (p != NULL)
 			*p = '\0';
@@ -79,20 +87,16 @@
 		*p = '\0';
 		param = p + 1;
 		if (strcmp(cmd, "version") == 0) {
+			int vmajor, vminor;
+			
 			if (sscanf(param, "%d.%d", &vmajor, &vminor) != 2) {
 				warnx("Cannot parse version: %s", param);
 				break;
 			}
-			if (vmajor != PKGPATCH_VERSION_MAJOR) {
-				warnx("Major version mismatch: got %d expected %d",
-				    vmajor, PKGPATCH_VERSION_MAJOR);
-				break;
-			}
-			if (vminor > PKGPATCH_VERSION_MINOR) {
-				warnx("Minor version cannot be handled: %d",
-				    vminor);
-				break;
-			}
+			pindex->ver_major = vmajor;
+			pindex->ver_minor = vminor;
+		} else if (strcmp(cmd, "pkgrepo") == 0) {
+			pindex->pkg_repo_url = strdup(param);
 		} else if (strcmp(cmd, "havepatch") == 0) {
 			char src[PKGNAME_MAX], tgt[PKGNAME_MAX],
 			    patch[PATH_MAX], tstamp[PKGNAME_MAX];
@@ -157,16 +161,30 @@
 }
 
 
+static int
+pkg_add(struct patch_index *pindex, char *pkg_name)
+{
+	char url[PATH_MAX];
+	
+	snprintf(url, sizeof(url), "%s/%s.%s", pindex->pkg_repo_url,
+	    pkg_name, PKG_FORMAT_EXT);
+	if (Verbose > 1)
+		printf("Trying to install %s.\n", url);
+	return vsystem("%s %s", _PATH_PKG_ADD, url);
+}
+
+
 void
 perform_updateweb(const char *in_url)
 {
 	char url_base[PATH_MAX], url_index[PATH_MAX], index_fname[PATH_MAX];
 	char local_index[PATH_MAX];
-	struct patchrec_list prlist;
+	struct patch_index pindex;
 	struct patchrec *pr;
 	char **instpkg;
 	int er, i, pcount = 0, scount;
 	
+	memset(&pindex, 0, sizeof(pindex));
 	if (in_url == NULL)
 		in_url = PKGPATCH_SITE_URL;
 	
@@ -207,11 +225,20 @@
 		if (Verbose > 2)
 			printf("Decompressed index to: %s\n", local_index);
 	}
-	TAILQ_INIT(&prlist);
-	if (read_pkgpatchindex_file(&prlist, local_index) != 0)
+	TAILQ_INIT(&pindex.prlist);
+	if (read_pkgpatchindex_file(&pindex, local_index) != 0)
 		err(1, "Cannot read pkgpatchindex: %s", local_index);
+	if (pindex.ver_major != PKGPATCH_VERSION_MAJOR)
+		errx(1, "Major version mismatch: got %d expected %d",
+		    pindex.ver_major, PKGPATCH_VERSION_MAJOR);
+	if (pindex.ver_minor > PKGPATCH_VERSION_MINOR)
+		errx(1, "Minor version cannot be handled: %d",
+		    pindex.ver_minor);
+	if (pindex.pkg_repo_url == NULL)
+		warnx("Target package repo URL is not present in patch repo "
+		    "metadata.");
 	if (Verbose > 2)
-		TAILQ_FOREACH(pr, &prlist, linkage)
+		TAILQ_FOREACH(pr, &pindex.prlist, linkage)
 			printf("Available: %s to %s via %s\n", pr->source,
 			    pr->target, pr->patch_name);
 	
@@ -221,7 +248,7 @@
 	for (i = 0; instpkg[i] != NULL; i++) {
 		if (Verbose > 2)
 			printf("Installed: %s\n", instpkg[i]);
-		TAILQ_FOREACH(pr, &prlist, linkage)
+		TAILQ_FOREACH(pr, &pindex.prlist, linkage)
 			if (strncmp(instpkg[i], pr->source, PKGNAME_MAX) == 0) {
 				pr->match = TRUE;
 				pcount++;
@@ -236,7 +263,7 @@
 	/* Show this information even if we're in non-verbose mode, it's
 	 * important! */
 	printf("Patch candidates:\n");
-	TAILQ_FOREACH(pr, &prlist, linkage) {
+	TAILQ_FOREACH(pr, &pindex.prlist, linkage) {
 		if (pr->match)
 			printf("%s\t", pr->source);
 	}
@@ -249,7 +276,7 @@
 	/* Ok now, fetch the patches */
 	if (Verbose)
 		printf("Downloading: ");
-	TAILQ_FOREACH(pr, &prlist, linkage) {
+	TAILQ_FOREACH(pr, &pindex.prlist, linkage) {
 		char local_file[PATH_MAX], remote_file[PATH_MAX];
 		
 		if (pr->match) {
@@ -271,7 +298,7 @@
 		printf(".\n");
 	
 	/* Read the package patches' plists */
-	TAILQ_FOREACH(pr, &prlist, linkage) {
+	TAILQ_FOREACH(pr, &pindex.prlist, linkage) {
 		char local_file[PATH_MAX];
 		
 		if (!pr->match)
@@ -299,7 +326,7 @@
 		
 		scount = 0;
 		/* Sort the package patches by dependancies */
-		TAILQ_FOREACH(pr, &prlist, linkage) {
+		TAILQ_FOREACH(pr, &pindex.prlist, linkage) {
 			struct patchrec *pr2 = NULL;
 			int foundit = FALSE;
 			
@@ -322,7 +349,7 @@
 					pl = pl->next;
 					continue;
 				}
-				TAILQ_FOREACH(pr2, &prlist, linkage) {
+				TAILQ_FOREACH(pr2, &pindex.prlist, linkage) {
 					if (strncmp(pl->name, pr2->target,
 					    PKGNAME_MAX) == 0) {
 						ndeps_found++;
@@ -331,16 +358,19 @@
 					}
 				}
 				if (!foundit) {
-					printf("Cannot resolve dependancy "
+					printf("Dependancy cannot be satisfied "
 					    "%s -> %s\n", pr->target, pl->name);
+					if (pkg_add(&pindex, pl->name) != 0)
+						err(1, "Cannot install %s\n",
+						    pl->name);
 					pl = pl->next;
 					continue;
 				}
 				/* Reshuffle the found (depended-on) package to
 				 * the front. */
 				assert(pr2 != NULL);
-				TAILQ_REMOVE(&prlist, pr2, linkage);
-				TAILQ_INSERT_HEAD(&prlist, pr2, linkage);
+				TAILQ_REMOVE(&pindex.prlist, pr2, linkage);
+				TAILQ_INSERT_HEAD(&pindex.prlist, pr2, linkage);
 				scount++;
 				pl = pl->next;
 			}
@@ -351,7 +381,7 @@
 	}
 	
 	/* Ok, apply the gathered patches now */
-	TAILQ_FOREACH(pr, &prlist, linkage) {
+	TAILQ_FOREACH(pr, &pindex.prlist, linkage) {
 		char local_file[PATH_MAX];
 		
 		if (!pr->match)

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



More information about the p4-projects mailing list