Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Jul 2010 00:30:48 GMT
From:      Ivan Voras <ivoras@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 180789 for review
Message-ID:  <201007120030.o6C0UmON027573@repoman.freebsd.org>

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

Change 180789 by ivoras@betelgeuse on 2010/07/12 00:29:55

	Read plist from patch archives

Affected files ...

.. //depot/projects/soc2010/pkg_patch/src/patch/Makefile#27 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.c#17 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.h#17 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#26 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#26 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/main.c#27 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#25 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#25 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatchdir.c#10 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatchdir.h#9 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#25 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/support.c#24 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/updateweb.c#5 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/updateweb.h#5 edit

Differences ...

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

@@ -8,7 +8,7 @@
 WARNS?=	4
 WFORMAT?=	1
 
-LDADD=	-lmd -lfetch -pthread
+LDADD=	-lmd -lfetch -larchive -pthread
 
 #CFLAGS+=-g
 #LDADD+=-g

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


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


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


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


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

@@ -143,7 +143,7 @@
 	
 	proc_args();
 	if (patch_op == PP_NONE)
-		errx(1, "No operation switch given");
+		errx(1, "No operation switch given, try '-h' for help");
 	atexit(atexit_handler);
 	proc_setup();
 	

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


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


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


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


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

@@ -154,5 +154,6 @@
 time_t iso8601_to_time(char *t);
 char *time_ctime(time_t t);
 void baton_twirl(void);
+Package *pkg_read_plist(char *pfilename);
 
 #endif

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

@@ -32,6 +32,8 @@
 #include <errno.h>
 #include <err.h>
 #include <fts.h>
+#include <archive.h>
+#include <archive_entry.h>
 
 #include <pkg.h>
 #include "pkg_patch.h"
@@ -640,3 +642,46 @@
 	fprintf(stdout, "%c\b", bpos[counter++ % 4]);
 	fflush(stdout);
 }
+
+
+/* Read the +CONTENTS file from the given package file */
+Package *
+pkg_read_plist(char *filename)
+{
+	struct archive *arc;
+	struct archive_entry *entry;
+	Package *pkg = NULL;
+	int er;
+	
+	arc = archive_read_new();
+	archive_read_support_compression_all(arc);
+	archive_read_support_format_tar(arc);
+	
+	er = archive_read_open_filename(arc, filename, 65536);
+	if (er != ARCHIVE_OK)
+		return NULL;
+	while (archive_read_next_header(arc, &entry) == ARCHIVE_OK) {
+		FILE *fplist;
+		size_t bs = 16*1024;
+		char *buf;
+		
+		if (strncmp(archive_entry_pathname(entry), CONTENTS_FNAME,
+		    PATH_MAX) != 0)
+			continue;
+		fplist = tmpfile();
+		buf = malloc(bs);
+		while (bs > 0) {
+			bs = archive_read_data(arc, buf, bs);
+			if (bs > 0)
+				if (fwrite(buf, 1, bs, fplist) != bs)
+					err(1, "Cannot extract plist");
+		}
+		fseek(fplist, 0, 0);
+		pkg = calloc(1, sizeof(*pkg));
+		read_plist(pkg, fplist);
+		fclose(fplist);
+		break;
+	}
+	archive_read_finish(arc);
+	return (pkg);
+}

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

@@ -42,6 +42,7 @@
 	char 	patch_name[PATH_MAX];
 	time_t 	patch_timestamp;
 	Boolean	match;
+	Package *plist;
 	STAILQ_ENTRY(patchrec)	linkage;
 };
 
@@ -230,6 +231,8 @@
 			printf("No package update candidates.\n");
 		return;
 	}
+	/* Show this information even if we're in non-verbose mode, it's
+	 * important! */
 	printf("Patch candidates:\n");
 	STAILQ_FOREACH(pr, &prlist, linkage) {
 		if (pr->match)
@@ -237,7 +240,7 @@
 	}
 	printf("\n");
 	if (!Force) {
-		if (!y_or_n(FALSE, "Continue with patching %d packages", pcount))
+		if (!y_or_n(FALSE, "Patch %d packages", pcount))
 			return;
 	}
 	
@@ -254,8 +257,8 @@
 			}
 			snprintf(local_file, PATH_MAX, "%s/%s", my_tmp,
 			    pr->patch_name);
-			snprintf(remote_file, PATH_MAX, "%s/%s",
-			    url_base, pr->patch_name);
+			snprintf(remote_file, PATH_MAX, "%s/%s", url_base,
+			    pr->patch_name);
 			if (Verbose > 3)
 				printf("%s to %s", remote_file, local_file);
 			if (download_file(remote_file, local_file) != 0)
@@ -264,4 +267,18 @@
 	}
 	if (Verbose)
 		printf(".\n");
+	
+	/* Sort the package patches by dependancies */
+	STAILQ_FOREACH(pr, &prlist, linkage) {
+		char local_file[PATH_MAX];
+		
+		if (!pr->match)
+			continue;
+		
+		snprintf(local_file, PATH_MAX, "%s/%s", my_tmp,
+		    pr->patch_name);
+		pr->plist = pkg_read_plist(local_file);
+		if (pr->plist == NULL)
+			err(1, "Cannot read %s file", CONTENTS_FNAME);
+	}
 }

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




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