PERFORCE change 123255 for review

Garrett Cooper gcooper at FreeBSD.org
Tue Jul 10 08:24:39 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=123255

Change 123255 by gcooper at optimus-revised_pkgtools on 2007/07/10 08:23:57

	A new try at buffering the +CONTENTS file, which hopes to increase the speed of the file read
	to 1.5+ times faster than the functions current speed at optimum speed.
	
	Still needs to be tested, then later run through the simple profiler scripts and compared to
	previous versions function versions.

Affected files ...

.. //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/plist.c#4 edit

Differences ...

==== //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/plist.c#4 (text+ko) ====

@@ -28,7 +28,8 @@
 #include <stdarg.h>
 #include <sys/time.h>
 
-#if SIMPLE_PROF_TRY
+#define BUFFER_TRY 1 
+
 int
 run_generic_plist_prof(char *fn_name, ...)
 {
@@ -113,21 +114,17 @@
     return ret_code;
 
 }
-#endif
 
 /* Add an item to a packing list */
 void
 add_plist(Package *p, plist_t type, const char *arg)
 {
-#if SIMPLE_PROF_TRY
     run_generic_plist_prof("add_plist", p, type, arg);
 }
 
 void
 add_plist_np(Package *p, plist_t type, const char *arg)
 {
-#endif
-
     PackingList tmp;
 
     tmp = new_plist_entry();
@@ -159,14 +156,12 @@
 void
 add_plist_top(Package *p, plist_t type, const char *arg)
 {
-#if SIMPLE_PROF_TRY
     run_generic_plist_prof("add_plist_top", p, type, arg);
 }
 
 void
 add_plist_top_np(Package *p, plist_t type, const char *arg)
 {
-#endif
     PackingList tmp;
 
     tmp = new_plist_entry();
@@ -287,7 +282,6 @@
 int
 plist_cmd(const char *s, char **arg)
 {
-#if SIMPLE_PROF_TRY
     return run_generic_plist_prof("plist_cmd", s, arg);
 }
 
@@ -298,8 +292,6 @@
 int
 plist_cmd_np(const char *s, char **arg)
 {
-#endif
-
     char cmd[FILENAME_MAX + 20];	/* 20 == fudge for max cmd len */
     char *cp;
     const char *sp;
@@ -371,15 +363,134 @@
 void
 read_plist(Package *pkg, FILE *fp)
 {
-#if SIMPLE_PROF_TRY
     run_generic_plist_prof("read_plist", pkg, fp);
 }
 
+void
+read_plist_np_revised(Package *pkg, FILE *fp)
+{
+
+    struct stat contents_stat;
+
+    char *plines;
+    char *pline;
+    char *cp;
+
+    int cmd;
+
+    int i = 0;
+
+    pkg->fmtver_maj = 1;
+    pkg->fmtver_mnr = 0;
+    pkg->origin = NULL;
+
+    if(fstat( fileno(fp), &contents_stat )) {
+	err(-1, "Could not fstat +CONTENTS file");
+    }
+
+    assert(contents_stat.st_size != 0);
+
+    plines = (char*) malloc(contents_stat.st_size);
+
+    for(i = 0; !feof(fp) && i <= contents_stat.st_size; i++)
+	*(plines+i) = fgetc(fp);
+
+    /* Avoid strangely crafted files with zero-length, but non-zero size */
+    assert(i != 0);
+
+    *(plines+i) = '\0';
+
+    pline = strtok(plines, "\n");
+
+    if(trim_end_whitespace(pline)) {
+
+	int major, minor;
+
+	cp = pline;
+
+	cmd = plist_cmd(pline, &cp);
+
+	if (cmd == FAIL) {
+	    warnx("%s: unknown command '%s' (package tools out of date?)",
+		__func__, cp);
+	}
+
+	else if (*cp == '\0') {
+	    cp = NULL;
+	}
+
+	else if (cmd == PLIST_COMMENT && sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n",
+					   &major, &minor) == 2) {
+	    pkg->fmtver_maj = major;
+	    pkg->fmtver_mnr = minor;
+
+	    /* 
+	     * If the version is greater than the version major.minor, we
+	     * have a compatibility problem..
+	     */
+	    if (0 < verscmp(pkg, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR)) {
+		warnx("plist format revision (%d.%d) is higher than supported"
+		    "(%d.%d)", pkg->fmtver_maj, pkg->fmtver_mnr,
+		    PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR);
+
+		if (pkg->fmtver_maj > PLIST_FMT_VER_MAJOR) {
+		    cleanup(0);
+		    exit(2);
+	        }
+
+	    }
+
+	}
+
+    }
+
+    /* Now let's iterate through the lines and parse the commands */
+    while( NULL != (pline = strtok(NULL, "\n")) ) {
+
+	if(trim_end_whitespace(pline)) {
+	    
+	    if (*pline != CMD_CHAR)
+		cmd = PLIST_FILE;
+
+	    else {
+
+	        cp = pline;
+
+	        cmd = plist_cmd(pline, &cp);
+
+		if (cmd == FAIL) {
+		    warnx("%s: unknown command '%s' (package tools out of date?)",
+			__func__, cp);
+	    	} else if (*cp == '\0') {
+	            cp = NULL;
+	        }
+
+		add_plist(pkg, cmd, cp);
+
+	    }
+
+	}
+
+    }
+
+
+}
+
+int
+trim_end_whitespace(char * str)
+{
+    int len;
+
+    for(len = strlen(str); len && isspace(*(str+len)); len--)
+	*(str+len) = '\0';
+
+    return len;
+}
+
 /* Read a packing list from a file */
 void
 read_plist_np(Package *pkg, FILE *fp)
 {
-#endif
 
 #if BUFFER_TRY
 
@@ -483,7 +594,6 @@
 void
 write_plist(Package *pkg, FILE *fp)
 {
-#if SIMPLE_PROF_TRY
     run_generic_plist_prof("write_plist", pkg, fp);
 }
 
@@ -491,8 +601,6 @@
 void
 write_plist_np(Package *pkg, FILE *fp)
 {
-#endif
-
     PackingList plist = pkg->head;
 
     while (plist) {
@@ -591,7 +699,6 @@
 int
 delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
 {
-#if SIMPLE_PROF_TRY
     return run_generic_plist_prof("delete_package", ign_err, nukedirs, pkg);
 }
 
@@ -604,8 +711,6 @@
 int
 delete_package_np(Boolean ign_err, Boolean nukedirs, Package *pkg)
 {
-#endif
-
     PackingList p;
     const char *Where = ".", *last_file = "";
     Boolean fail = SUCCESS;
@@ -734,7 +839,6 @@
 int
 delete_hierarchy(const char *dir, Boolean ign_err, Boolean nukedirs)
 {
-#if SIMPLE_PROF_TRY
     return run_generic_plist_prof("delete_hierarchy", dir, ign_err, nukedirs);
 }
 
@@ -742,8 +846,6 @@
 int
 delete_hierarchy_np(const char *dir, Boolean ign_err, Boolean nukedirs)
 {
-#endif
-
     char *cp1, *cp2;
 
     cp1 = cp2 = strdup(dir);


More information about the p4-projects mailing list