PERFORCE change 163227 for review

David Forsythe dforsyth at FreeBSD.org
Mon Jun 1 04:32:33 UTC 2009


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

Change 163227 by dforsyth at squirrel on 2009/06/01 04:31:32

	Started to add things to read files.

Affected files ...

.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_info.c#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.h#3 edit

Differences ...

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#3 (text+ko) ====

@@ -32,16 +32,6 @@
 	return (p);
 }
 
-struct pkg *
-pkg_set_path(struct pkg *p, const char *path)
-{
-	if (p == NULL || path == NULL)
-		return (p);
-
-	p->path = strdup(path);
-	return (p);
-}
-
 /* Set the short comment for this package */
 struct pkg *
 pkg_set_comment(struct pkg *p, const char *comment)
@@ -65,6 +55,13 @@
 	return (p);
 }
 
+struct pkg *
+pkg_set_pkg_info(struct pkg *p, struct pkg_info *pi)
+{
+	return (p);
+}
+	
+
 char *
 pkg_ident(struct pkg *p)
 {
@@ -83,7 +80,6 @@
 	return (p->comment);
 }
 
-
 /* TODO: Make an explicit note in the manual for libpkg that pkg_free
  * should NOT be called called on pkgs that are not explicitly created by
  * the user. */

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#3 (text+ko) ====

@@ -33,12 +33,16 @@
 struct pkg *pkgdb_pkg_list_first(struct pkgdb *db);
 void pkgdb_pkg_list_append(struct pkgdb *db, struct pkg *p);
 
+char *pkgdb_read_file_to_text(struct pkgdb *db, struct pkg *p,
+	const char *filename);
+
 void pkgdb_free_hierdb(struct pkgdb *db);
 void pkgdb_free_pkg_list(struct pkgdb *db);
 
 /* pkg_info */
+
 struct pkg_info;
 
-struct pkg *pkg_info_read_comment_file(struct pkg *p, const char *filename);
+struct pkg_info *pkg_info_digest_info_from_text(const char *text);
 
 #endif

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_info.c#3 (text+ko) ====

@@ -28,8 +28,13 @@
 	struct pkg_file *files;
 };
 
-char *
-pkg_info_read_file_to_string(const char *path, const char *filename)
+struct pkg_info *
+pkg_info_digest_info_from_text(const char *text)
 {
+	struct pkg_info *pi;
+
+	/* This function will parse text and create a pkg_info */
+	if (text == NULL)
+		return (NULL);
 	return (NULL);
 }

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#3 (text+ko) ====

@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <limits.h>
 
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -109,25 +110,28 @@
 {
 	int s; 
 	char *path;
+	char *text;
 	struct stat sb;
 	struct pkg *p;
 
 	p = pkg_new(ident);
 	path = pkgdb_pkg_path(db, p);
-	pkg_set_path(p, path);
 	if (p == NULL || path == NULL) {
 		pkg_free(p);
 		free(path);
+		return (NULL);
 	}
-	
+
 	s = lstat(path, &sb);
 	if (s < 0 || S_ISLNK(sb.st_mode) || !S_ISDIR(sb.st_mode)) {
 		pkg_free(p);
-		free(path);
 		return (NULL);
 	}
+
+	text = pkgdb_read_read_pkg_file_to_text(db, p, COMMENT_FILE);
+	pkg_set_comment(p, text);
 	
-	free(path);
+	free(text);
 	return (p);
 }
 
@@ -188,6 +192,46 @@
 	return (p);
 }
 
+char *
+pkgdb_read_file_to_text(struct pkgdb *db, struct pkg *p, 
+	const char *filename)
+{
+	int s;
+	int fd;
+	char *dir;
+	char *path;
+	char *text;
+	struct stat sb;
+
+	if (p == NULL || filename == NULL)
+		return (NULL);
+
+	/* +2 because dir will not have a trailing '/' */
+	dir = pkgdb_pkg_path(db, p);
+	path = malloc(strlen(dir) + strlen(filename) + 2);
+	if (path == NULL)
+		return (NULL);
+	strcpy(path, dir);
+	strcat(path, '/');
+	strcat(path, filename);
+
+	s = stat(path, &sb);
+	if (s < 0 || !S_ISREG(st.st_mode)) {
+		free(path);
+		return (NULL);
+	}
+
+	fd = open(path, O_READONLY);
+	if (fd < 0) {
+		free(path);
+		return (NULL);
+	}
+
+	
+
+	return (text);
+}
+
 /* Giving myself a level of abstraction between queue and pkgdb incase I
  * decide to change how the package list is done. */
 

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.h#3 (text+ko) ====

@@ -8,7 +8,6 @@
 	TAILQ_ENTRY(pkg) next;
 
 	char *ident; /* User given name for this pkg. */
-	char *path;
 	
 	char *comment; /* Mmmmm, should be 70 or less, right? */
 	struct pkg_contents *contents;


More information about the p4-projects mailing list