Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Aug 2007 06:22:41 GMT
From:      Garrett Cooper <gcooper@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 125288 for review
Message-ID:  <200708180622.l7I6Mfxp076812@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=125288

Change 125288 by gcooper@optimus-revised_pkgtools on 2007/08/18 06:22:15

	Whitespace and minor comment update.

Affected files ...

.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg.c#3 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg.h#4 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_db.c#3 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_db.h#3 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_db_match.c#3 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_db_private.h#4 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_manifest.c#3 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_private.h#3 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_repo.c#3 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_repo.h#3 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_repo_files.c#4 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_repo_ftp.c#4 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_repo_private.h#4 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_util.c#4 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkgfile.c#4 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/lib/db/api.c#4 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/lib/db/api.h#4 edit

Differences ...

==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg.c#3 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg.h#4 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_db.c#3 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_db.h#3 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_db_match.c#3 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_db_private.h#4 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_manifest.c#3 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_private.h#3 (text+ko) ====

@@ -224,7 +224,6 @@
 	pkg_run_script_callback		*pkg_run_script;
 };
 
-int pkg_dir_build(const char *, mode_t);
 int pkg_dir_clean(const char *);
 int pkg_exec(const char *, ...);
 FILE *pkg_cached_file(FILE *, const char *);

==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_repo.c#3 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_repo.h#3 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_repo_files.c#4 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_repo_ftp.c#4 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_repo_private.h#4 (text+ko) ====


==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkg_util.c#4 (text+ko) ====

@@ -58,60 +58,6 @@
  */
 
 /**
- * @brief A simplified version of `mkdir -p path'
- * @return 0 on success, -1 on error
- */
-/* Based off src/bin/mkdir/mkdir.c 1.32 */
-int
-pkg_dir_build(const char *path, mode_t mode)
-{
-	struct stat sb;
-	int last, retval;
-	char *str, *p;
-
-	str = strdup(path);
-	if (!str) {
-		return -1;
-	}
-	p = str;
-	retval = 0;
-    if (p[0] == '/')	/* Skip leading '/'. */
-	++p;
-    for (last = 0; !last ; ++p) {
-	if (p[0] == '\0')
-	    last = 1;
-	else if (p[0] != '/')
-	    continue;
-	*p = '\0';
-	if (!last && p[1] == '\0')
-	    last = 1;
-	if (mkdir(str,
-	    (mode == 0) ? (S_IRWXU | S_IRWXG | S_IRWXO) : mode) < 0) {
-	    if (errno == EEXIST || errno == EISDIR) {
-		if (stat(str, &sb) < 0) {
-		    retval = -1;
-		    break;
-		} else if (!S_ISDIR(sb.st_mode)) {
-		    if (last)
-			errno = EEXIST;
-		    else
-			errno = ENOTDIR;
-		    retval = -1;
-		    break;
-		}
-	    } else {
-		retval = -1;
-		break;
-	    }
-	}
-	if (!last)
-	    *p = '/';
-    }
-    free(str);
-    return (retval);
-}
-
-/**
  * @brief Walks from the a child directory to the root removing all empty directories
  * @param child The directory to start from
  * @return  0 on success

==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/contrib/libpkg/pkgfile.c#4 (text+ko) ====

@@ -67,7 +67,7 @@
 {
     struct pkgfile *file;
 
-    file = malloc(sizeof(struct pkgfile));
+    file = calloc(sizeof(struct pkgfile));
     if (file == NULL)
 	return NULL;
 
@@ -77,18 +77,6 @@
 	return NULL;
     }
 
-    file->cwd = NULL;
-    file->real_name = NULL;
-    file->type = type;
-    file->loc = location;
-    file->follow_link = 0;
-    file->fd = NULL;
-    file->data = NULL;
-    file->length = 0;
-    file->offset = 0;
-    file->mode = 0;
-    file->md5[0] = '\0';
-
     return file;
 }
 
@@ -133,7 +121,7 @@
  * @brief Gets a file's type from disk
  *
  * This is to be used when the file's type in needed but
- * the file dosn't need to be opened
+ * the file doesn't need to be opened
  * @return  0 on success
  * @return -1 on error
  */
@@ -376,34 +364,34 @@
     assert(file->type != pkgfile_none);
 
     switch (file->type) {
-	case pkgfile_none:
-	    break;
-	case pkgfile_dir:
-	    if (file->length == 0)
-		file->length = strlen(file->name);
+    case pkgfile_none:
+	break;
+    case pkgfile_dir:
+	if (file->length == 0)
+	    file->length = strlen(file->name);
+	return file->length;
+	break;
+    case pkgfile_hardlink:
+	assert(file->loc == pkgfile_loc_mem);
+	if (file->loc == pkgfile_loc_mem) {
 	    return file->length;
-	    break;
-	case pkgfile_hardlink:
-	    assert(file->loc == pkgfile_loc_mem);
-	    if (file->loc == pkgfile_loc_mem) {
-		return file->length;
-	    }
-	    break;
-	case pkgfile_regular:
-	    if (file->loc == pkgfile_loc_disk) {
-		struct stat sb;
+	}
+	break;
+    case pkgfile_regular:
+	if (file->loc == pkgfile_loc_disk) {
+	    struct stat sb;
 
-		fstat(fileno(file->fd), &sb);
-		return sb.st_size;
-	    } else if (file->data != NULL) {
-		return file->length;
-	    }
-	    break;
-	case pkgfile_symlink:
-	    if (file->data != NULL) {
-		return strlen(file->data);
-	    }
-	    break;
+	    fstat(fileno(file->fd), &sb);
+	    return sb.st_size;
+	} else if (file->data != NULL) {
+	    return file->length;
+	}
+	break;
+    case pkgfile_symlink:
+	if (file->data != NULL) {
+	    return strlen(file->data);
+	}
+	break;
     }
 
     return 0;
@@ -437,7 +425,9 @@
 	}
 	break;
     case pkgfile_regular:
+
 	if (file->loc == pkgfile_loc_disk) {
+
 	    /* Load the file to the data pointer */
 	    if (file->data == NULL && file->length > 0) {
 		file->data = malloc(file->length);
@@ -450,7 +440,9 @@
 		/** @todo check length < size left in file */
 		fread(file->data, 1, file->length, file->fd);
 	    }
+
 	}
+
     case pkgfile_symlink:
 	return file->data;
     }
@@ -762,6 +754,7 @@
     file->length -= strlen(line) + 1;
 
     if (file->loc == pkgfile_loc_disk) {
+
 	fseek(file->fd, 0, SEEK_SET);
 	if (fwrite(file->data, 1, file->length, file->fd) !=
 	    file->length) {
@@ -769,6 +762,7 @@
 	    return -1;
 	}
 	ftruncate(fileno(file->fd), file->length);
+
     }
 
     return 0;
@@ -885,7 +879,7 @@
 		 * on the dir and opening again
 		 */
 		dir_name = dirname(pkgfile_real_name(file));
-		pkg_dir_build(dir_name, 0);
+		mkdir_p(dir_name, 0);
 		fd = fopen(pkgfile_real_name(file), "a");
 		if (fd == NULL) {
 		    return -1;
@@ -938,7 +932,7 @@
 		return -1;
 
 	    dir_name = dirname(pkgfile_real_name(file));
-	    pkg_dir_build(dir_name, 0);
+	    mkdir_p(dir_name, 0);
 	    if (link(file->data, file->name) != 0)
 		return -1;
 	}
@@ -950,13 +944,13 @@
 		return -1;
 
 	    dir_name = dirname(pkgfile_real_name(file));
-	    pkg_dir_build(dir_name, 0);
+	    mkdir_p(dir_name, "");
 	    if (symlink(file->data, file->name) != 0)
 		return -1;
 	}
 	break;
     case pkgfile_dir:
-	if (pkg_dir_build(pkgfile_real_name(file), file->mode) != 0)
+	if (mkdir_p(pkgfile_real_name(file), file->mode) != 0)
 	    return -1;
 	break;
     }

==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/lib/db/api.c#4 (text+ko) ====

@@ -9,7 +9,7 @@
 build_filedb(db *database, const char *filedb_filename, const char **file_manifest_filenames)
 {
 
-    int build_db_exit_status;
+    int build_db_ret_code;
 
     /**
      * Create temporary store for output conversion,
@@ -20,9 +20,9 @@
     /**
      * Convert all entries to strings.
      */
-    build_db_exit_status = build_db(database, filedb_filename, file_data);
+    build_db_ret_code = build_db(database, filedb_filename, file_data);
 
-    return build_db_exit_status;
+    return build_db_ret_code;
 
 }
 
@@ -35,7 +35,7 @@
 build_pkgdb(db *database, const char *pkgdb_filename, const char **index_filenames)
 {
 
-    int build_db_exit_status;
+    int build_db_ret_code;
 
     /**
      * Create temporary store for output conversion,
@@ -46,9 +46,9 @@
     /**
      * Convert all entries to strings.
      */
-    build_db_exit_status = build_db(database, pkgdb_filename, pkg_data);
+    build_db_ret_code = build_db(database, pkgdb_filename, pkg_data);
 
-    return build_db_exit_status;
+    return build_db_ret_code;
 
 }
 
@@ -62,7 +62,7 @@
 build_db(db *database, const char *db_filename, const char *data)
 {
 
-    int build_db_exit_status;
+    int build_db_ret_code;
 	
     database->bdb_obj =
 	dbopen(db_filename, O_CREAT | O_EXLOCK | O_EXCL | O_WRLOCK, 0644, DB_HASH, NULL);
@@ -70,36 +70,36 @@
     /**
      * dbopen was successful.
      */
-    if(NULL != build_db_exit_status) {
+    if(NULL != build_db_ret_code) {
 
 	/**
 	 * Try initializing the database header.
 	 */
-	build_db_exit_status = initialize_database_header(database);
+	build_db_ret_code = initialize_database_header(database);
 
 	/**
 	 * Database header creation was good. Continue by trying to
 	 * create the cache.
 	 */
-	if(0 == build_db_exit_status) {
+	if(0 == build_db_ret_code) {
 
-	    build_db_exit_status = initialize_entry_cache(database);
+	    build_db_ret_code = initialize_entry_cache(database);
 
 	    /**
-	     * Database is fully built if build_db_exit_status == 0.
+	     * Database is fully built if build_db_ret_code == 0.
 	     */
 
 	}
 
     } else {
-	build_db_exit_status = 1;
+	build_db_ret_code = 1;
     }
 
     /**
      * Else dbopen was bunk -- return exit status.
      */
 
-    return build_db_exit_status;
+    return build_db_ret_code;
 
 }
 
@@ -124,7 +124,9 @@
 }
 
 /**
- * @brief Cache recent entry into pkg database, substituting
+ * @brief Cache entry into pkg database.
+ *
+ * Cache pkg entry into pkg database, substituting
  * the current entry for the least recently cached one.
  * @return 0 on success
  * @return 1 on failure
@@ -154,6 +156,8 @@
 remove_lru_cache_entry(db *database, const size_t entry_size)
 {
 
+    int db_ret_code = -1;
+
     DBT
 	/**
 	 * Cache updating related items.
@@ -176,24 +180,37 @@
 	header_query = { __HEADER_TITLE, sizeof(__HEADER_TITLE) },
 	header_retrieved;
 
-//    int db_exit_status = database->bdb_obj->get(, 0);
+    /**
+     * Get the header -- search to see if there's a cache.
+     */
+    db_ret_code = database->bdb_obj->get(database->bdb_obj, &header_query, &header_retrieved, 0);
 
     /**
      * Ok, there is a cache. Let's proceed.
      */
-    if(0 == db_exit_status) {
+    if(0 == db_ret_code) {
 	
 	
 
     }
 
-    return db_exit_status;
+    return db_ret_code;
 
 }
 
 /**
- * @brief Setup the database header; this should only be
- * executed after building the database.
+ * @brief Setup the database header
+ *
+ * This initializes a header with the following format:
+ *
+ *  _______________________________________________________________
+ * |                   |              |                            |
+ * | has_cache (uchar) | type (uchar) | cache_entry_prefix (char*) |
+ * |                   |              |                            |
+ *  ---------------------------------------------------------------
+ *
+ * This should only be executed after building the database,
+ * and should consist of
  * @return 0 on success
  * @return 1 on failure
  */
@@ -206,8 +223,11 @@
 }
 
 /**
- * @brief Setup the entry cache; this should only be executed
- * after building the database.
+ * @brief Setup the entry cache.
+ *
+ * 
+ *
+ * This should only be executed after building the database.
  * @return 0 on success
  * @return 1 on failure
  */
@@ -221,6 +241,11 @@
 
 /**
  * @brief Cache recent entry into pkg database.
+ *
+ * This will consist of iterating through a package list, one by one,
+ * updating entries in the overall database, and then update the
+ * cache, as the database type requires.
+ *
  * @return 0 on success
  * @return 1 on failure
  */
@@ -235,6 +260,9 @@
 
 /**
  * @brief Search for file in file database.
+ *
+ * Search over the database for a file, and return its entry.
+ *
  * @return file_entry if found.
  * @return NULL if not found.
  */
@@ -252,6 +280,12 @@
 
 /**
  * @brief Search for package in pkg database.
+ *
+ * Search over the database for a file, and return its entry.
+ *
+ * The pkg database will contain a cache, so let's check the
+ * cache first.
+ *
  * @return the pkg_entry if found.
  * @return NULL if not found.
  */
@@ -270,10 +304,12 @@
 /**
  * @brief Generic search method through a database, common
  * to both searching the file and pkg databases.
- * @return 1 on successful find
- * @return 0 on successful find.
- * @return 1 on lack of resources (memset / malloc failed)
- * or unknown BDB failure (check errno?)
+ *
+ *
+ * @return -1 on unsuccessful find
+ * @return  0 on successful find
+ * @return  1 on lack of resources (memset / malloc failed)
+ * 		 or unknown BDB failure (check errno?)
  *
  */
 
@@ -333,35 +369,45 @@
 
 }
 
+/**
+ * @brief db constructor
+ *
+ * Create a new database, assign proper methods to
+ * the object for caching, building, flushing, etc,
+ * and return the built object.
+ *
+ * @return NULL on fail or a db object when successful.
+ */
 void*
 initialize_db(const char *filename, __DB_TYPE_e db_type) {
 
-    db *database;
+    db *database = malloc(sizeof(db));
 
     switch(db_type) {
 
-	case FILEDB:
+    case FILEDB:
 
-	    database->__build = build_filedb;
-	    database->__cache_entry = cache_file_entry;
-    	    database->__flush = flush_changes;
-    	    database->__free = free_db;
-    	    database->__search = file_search;
+	database->__build = build_filedb;
+	database->__cache_entry = cache_file_entry;
+    	database->__flush = flush_changes;
+    	database->__free = free_db;
+    	database->__search = file_search;
 
-	    break;
+	break;
 
-	case PKGDB:
+    case PKGDB:
 
-	    database->__build = build_pkgdb;
-	    database->__cache_entry = cache_pkg_entry; 
-    	    database->__flush = flush_changes;
-    	    database->__free = free_db;
-    	    database->__search = pkg_search;
+	database->__build = build_pkgdb;
+	database->__cache_entry = cache_pkg_entry; 
+    	database->__flush = flush_changes;
+    	database->__free = free_db;
+    	database->__search = pkg_search;
 
-	    break;
+	break;
 
-	default:
-	    errx(-1, "Unknown package database type\n");
+	
+    default:
+	errx(-1, "Unknown database type\n");
 
     }
 
@@ -369,9 +415,26 @@
 
 }
 
+/**
+ * @brief db destructor
+ *
+ * Close the BDB DB object and free up any allocated resources
+ *
+ * [currently all that means is that we need to call free()].
+ *
+ * @return -1 on fail, 0 on success.
+ *
+ */
 int
-free_db(db* db_obj)
+free_db(db* database)
 {
 
+    int db_ret_code = 0;
+
+    db_ret_code = database->bdb_obj->close();
+
+    free(database);
+
+    return 0;
 
 }

==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/lib/db/api.h#4 (text+ko) ====




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