[Midnightbsd-cvs] src [7752] trunk/lib/libmport: code cleanup and locking fixes

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Aug 20 20:07:06 EDT 2016


Revision: 7752
          http://svnweb.midnightbsd.org/src/?rev=7752
Author:   laffer1
Date:     2016-08-20 20:07:05 -0400 (Sat, 20 Aug 2016)
Log Message:
-----------
code cleanup and locking fixes

Modified Paths:
--------------
    trunk/lib/libmport/bundle_read_install_pkg.c
    trunk/lib/libmport/clean.c
    trunk/lib/libmport/info.c
    trunk/lib/libmport/install_primative.c

Modified: trunk/lib/libmport/bundle_read_install_pkg.c
===================================================================
--- trunk/lib/libmport/bundle_read_install_pkg.c	2016-08-20 23:08:10 UTC (rev 7751)
+++ trunk/lib/libmport/bundle_read_install_pkg.c	2016-08-21 00:07:05 UTC (rev 7752)
@@ -65,21 +65,21 @@
 int
 mport_bundle_read_install_pkg(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta *pkg)
 {
-    if (do_pre_install(mport, bundle, pkg) != MPORT_OK) {
-        RETURN_CURRENT_ERROR;
-    }
+	if (do_pre_install(mport, bundle, pkg) != MPORT_OK) {
+		RETURN_CURRENT_ERROR;
+	}
 
-    if (do_actual_install(mport, bundle, pkg) != MPORT_OK) {
-        RETURN_CURRENT_ERROR;
-    }
+	if (do_actual_install(mport, bundle, pkg) != MPORT_OK) {
+		RETURN_CURRENT_ERROR;
+	}
 
-    if (do_post_install(mport, bundle, pkg) != MPORT_OK) {
-        RETURN_CURRENT_ERROR;
-    }
+	if (do_post_install(mport, bundle, pkg) != MPORT_OK) {
+		RETURN_CURRENT_ERROR;
+	}
 
-    syslog(LOG_NOTICE, "%s-%s installed", pkg->name, pkg->version);
+	syslog(LOG_NOTICE, "%s-%s installed", pkg->name, pkg->version);
 
-    return MPORT_OK;
+	return MPORT_OK;
 }  
 
 
@@ -135,7 +135,7 @@
 	return MPORT_OK;
 
 	ERROR:
-		// TODO: asset list free
+	// TODO: asset list free
 	RETURN_CURRENT_ERROR;
 }
 
@@ -148,23 +148,23 @@
 	__block char *err;
 
 	if (mport_db_prepare(mport->db, &count,
-						 "SELECT COUNT(*) FROM stub.assets WHERE (type=%i or type=%i or type=%i or type=%i) AND pkg=%Q",
-						 ASSET_FILE, ASSET_SAMPLE, ASSET_SHELL, ASSET_FILE_OWNER_MODE, pkg_name) != MPORT_OK) {
+	                     "SELECT COUNT(*) FROM stub.assets WHERE (type=%i or type=%i or type=%i or type=%i) AND pkg=%Q",
+	                     ASSET_FILE, ASSET_SAMPLE, ASSET_SHELL, ASSET_FILE_OWNER_MODE, pkg_name) != MPORT_OK) {
 		sqlite3_finalize(count);
 		RETURN_CURRENT_ERROR;
 	}
 
 	dispatch_sync(mportSQLSerial, ^{
-		switch (sqlite3_step(count)) {
-			case SQLITE_ROW:
-				*file_total = sqlite3_column_int(count, 0);
-				sqlite3_finalize(count);
-				break;
-			default:
-				err = (char *) sqlite3_errmsg(mport->db);
-				result = MPORT_ERR_FATAL;
-				sqlite3_finalize(count);
-		}
+	    switch (sqlite3_step(count)) {
+		    case SQLITE_ROW:
+			    *file_total = sqlite3_column_int(count, 0);
+			    sqlite3_finalize(count);
+			    break;
+		    default:
+			    err = (char *) sqlite3_errmsg(mport->db);
+			    result = MPORT_ERR_FATAL;
+			    sqlite3_finalize(count);
+	    }
 	});
 
 	if (result == MPORT_ERR_FATAL)
@@ -178,9 +178,9 @@
 	/* Insert the package meta row into the packages table (We use pack here because things might have been twiddled) */
 	/* Note that this will be marked as dirty by default */
 	if (mport_db_do(mport->db,
-					"INSERT INTO packages (pkg, version, origin, prefix, lang, options, comment, os_release, cpe, locked) VALUES (%Q,%Q,%Q,%Q,%Q,%Q,%Q,%Q,%Q,0)",
-					pkg->name, pkg->version, pkg->origin, pkg->prefix, pkg->lang, pkg->options, pkg->comment,
-					pkg->os_release, pkg->cpe) != MPORT_OK)
+	                "INSERT INTO packages (pkg, version, origin, prefix, lang, options, comment, os_release, cpe, locked) VALUES (%Q,%Q,%Q,%Q,%Q,%Q,%Q,%Q,%Q,0)",
+	                pkg->name, pkg->version, pkg->origin, pkg->prefix, pkg->lang, pkg->options, pkg->comment,
+	                pkg->os_release, pkg->cpe) != MPORT_OK)
 		RETURN_CURRENT_ERROR;
 
 	return MPORT_OK;
@@ -191,8 +191,8 @@
 {
 	/* Insert the depends into the master table */
 	if (mport_db_do(mport->db,
-					"INSERT INTO depends (pkg, depend_pkgname, depend_pkgversion, depend_port) SELECT pkg,depend_pkgname,depend_pkgversion,depend_port FROM stub.depends WHERE pkg=%Q",
-					pkg->name) != MPORT_OK)
+	                "INSERT INTO depends (pkg, depend_pkgname, depend_pkgversion, depend_port) SELECT pkg,depend_pkgname,depend_pkgversion,depend_port FROM stub.depends WHERE pkg=%Q",
+	                pkg->name) != MPORT_OK)
 		RETURN_CURRENT_ERROR;
 
 	return MPORT_OK;
@@ -202,8 +202,9 @@
 create_categories(mportInstance *mport, mportPackageMeta *pkg)
 {
 	/* Insert the categories into the master table */
-	if (mport_db_do(mport->db, "INSERT INTO categories (pkg, category) SELECT pkg, category FROM stub.categories WHERE pkg=%Q",
-					pkg->name) != MPORT_OK)
+	if (mport_db_do(mport->db,
+	                "INSERT INTO categories (pkg, category) SELECT pkg, category FROM stub.categories WHERE pkg=%Q",
+	                pkg->name) != MPORT_OK)
 		RETURN_CURRENT_ERROR;
 
 	return MPORT_OK;
@@ -244,19 +245,23 @@
 	*alist_p = alist;
 
 	if (state == PREINSTALL) {
-		if (mport_db_prepare(mport->db, &stmt, "SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type in (%d, %d)", pkg->name, ASSET_CWD, ASSET_PREEXEC) != MPORT_OK) {
+		if (mport_db_prepare(mport->db, &stmt,
+		                     "SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type in (%d, %d)",
+		                     pkg->name, ASSET_CWD, ASSET_PREEXEC) != MPORT_OK) {
 			sqlite3_finalize(stmt);
 			RETURN_CURRENT_ERROR;
 		}
 	} else if (state == ACTUALINSTALL) {
 		if (mport_db_prepare(mport->db, &stmt,
-							 "SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type not in (%d, %d)",
-							 pkg->name, ASSET_PREEXEC, ASSET_POSTEXEC) != MPORT_OK) {
+		                     "SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type not in (%d, %d)",
+		                     pkg->name, ASSET_PREEXEC, ASSET_POSTEXEC) != MPORT_OK) {
 			sqlite3_finalize(stmt);
 			RETURN_CURRENT_ERROR;
 		}
 	} else if (state == POSTINSTALL) {
-		if (mport_db_prepare(mport->db, &stmt, "SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type in (%d, %d)", pkg->name, ASSET_CWD, ASSET_POSTEXEC) != MPORT_OK) {
+		if (mport_db_prepare(mport->db, &stmt,
+		                     "SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type in (%d, %d)",
+		                     pkg->name, ASSET_CWD, ASSET_POSTEXEC) != MPORT_OK) {
 			sqlite3_finalize(stmt);
 			RETURN_CURRENT_ERROR;
 		}
@@ -267,60 +272,54 @@
 	}
 
 	dispatch_sync(mportSQLSerial, ^{
-		while (1) {
-			mportAssetListEntry *e;
+	    while (1) {
+		    mportAssetListEntry *e;
 
-			int ret = sqlite3_step(stmt);
+		    int ret = sqlite3_step(stmt);
 
-			if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
-				sleep(1);
-				ret = sqlite3_step(stmt);
-			}
+		    if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
+			    sleep(1);
+			    ret = sqlite3_step(stmt);
+		    }
 
-			if (ret == SQLITE_DONE)
-				break;
+		    if (ret == SQLITE_DONE)
+			    break;
 
-			if (ret != SQLITE_ROW) {
-				err = (char *) sqlite3_errmsg(mport->db);
-				result = MPORT_ERR_FATAL;
-				break; // we finalize below
-			}
+		    if (ret != SQLITE_ROW) {
+			    err = (char *) sqlite3_errmsg(mport->db);
+			    result = MPORT_ERR_FATAL;
+			    break; // we finalize below
+		    }
 
-			e = (mportAssetListEntry *) calloc(1, sizeof(mportAssetListEntry));
+		    e = (mportAssetListEntry *) calloc(1, sizeof(mportAssetListEntry));
 
-			if (e == NULL) {
-				err = "Out of memory";
-				result = MPORT_ERR_FATAL;
-				break; // we finalize below
-			}
+		    if (e == NULL) {
+			    err = "Out of memory";
+			    result = MPORT_ERR_FATAL;
+			    break; // we finalize below
+		    }
 
-			e->type = (mportAssetListEntryType) sqlite3_column_int(stmt, 0);
-			const unsigned char *data = sqlite3_column_text(stmt, 1);
-			const unsigned char *checksum = sqlite3_column_text(stmt, 2);
-			const unsigned char *owner = sqlite3_column_text(stmt, 3);
-			const unsigned char *group = sqlite3_column_text(stmt, 4);
-			const unsigned char *mode = sqlite3_column_text(stmt, 5);
+		    e->type = (mportAssetListEntryType) sqlite3_column_int(stmt, 0);
+		    const unsigned char *data = sqlite3_column_text(stmt, 1);
+		    const unsigned char *checksum = sqlite3_column_text(stmt, 2);
+		    const unsigned char *owner = sqlite3_column_text(stmt, 3);
+		    const unsigned char *group = sqlite3_column_text(stmt, 4);
+		    const unsigned char *mode = sqlite3_column_text(stmt, 5);
 
-			e->data = data == NULL ? NULL : strdup((char *) data);
-			if (checksum != NULL)
-				e->checksum = strdup((char *) checksum);
-			if (owner != NULL)
-				e->owner = strdup((char *) owner);
-			if (group != NULL)
-				e->group = strdup((char *) group);
-			if (mode != NULL)
-				e->mode = strdup((char *) mode);
+		    e->data = data == NULL ? NULL : strdup((char *) data);
+		    if (checksum != NULL)
+			    e->checksum = strdup((char *) checksum);
+		    if (owner != NULL)
+			    e->owner = strdup((char *) owner);
+		    if (group != NULL)
+			    e->group = strdup((char *) group);
+		    if (mode != NULL)
+			    e->mode = strdup((char *) mode);
 
-			if (e->data == NULL) {
-				err = "Out of memory";
-				result = MPORT_ERR_FATAL;
-				break;
-			}
+		    STAILQ_INSERT_TAIL(alist, e, next);
+	    }
 
-			STAILQ_INSERT_TAIL(alist, e, next);
-		}
-
-		sqlite3_finalize(stmt);
+	    sqlite3_finalize(stmt);
 	});
 
 	if (result == MPORT_ERR_FATAL)
@@ -333,29 +332,29 @@
 {
 	mportAssetList *alist = NULL;
 	__block mportAssetListEntry *e = NULL;
-    int file_total;
-    int file_count = 0;
-    struct archive_entry *entry;
-    char *orig_cwd = NULL;
-    uid_t owner = 0; /* root */
-    gid_t group = 0; /* wheel */
-    mode_t *set = NULL;
-    mode_t newmode;
-    mode_t *dirset = NULL;
-    mode_t dirnewmode;
-    char *mode = NULL;
-    char *mkdirp = NULL;
-    struct stat sb;
-    __block char file[FILENAME_MAX], cwd[FILENAME_MAX];
-    __block sqlite3_stmt *insert = NULL;
+	int file_total;
+	int file_count = 0;
+	struct archive_entry *entry;
+	char *orig_cwd = NULL;
+	uid_t owner = 0; /* root */
+	gid_t group = 0; /* wheel */
+	mode_t *set = NULL;
+	mode_t newmode;
+	mode_t *dirset = NULL;
+	mode_t dirnewmode;
+	char *mode = NULL;
+	char *mkdirp = NULL;
+	struct stat sb;
+	__block char file[FILENAME_MAX], cwd[FILENAME_MAX];
+	__block sqlite3_stmt *insert = NULL;
 
-    /* sadly, we can't just use abs pathnames, because it will break hardlinks */
-    orig_cwd = getcwd(NULL, 0);
+	/* sadly, we can't just use abs pathnames, because it will break hardlinks */
+	orig_cwd = getcwd(NULL, 0);
 
 	if (get_file_count(mport, pkg->name, &file_total) != MPORT_OK)
 		goto ERROR;
 
-    mport_call_progress_init_cb(mport, "Installing %s-%s", pkg->name, pkg->version);
+	mport_call_progress_init_cb(mport, "Installing %s-%s", pkg->name, pkg->version);
 
 	if (mport_bundle_read_get_assetlist(mport, pkg, &alist, ACTUALINSTALL) != MPORT_OK)
 		goto ERROR;
@@ -369,46 +368,47 @@
 	if (create_categories(mport, pkg) != MPORT_OK)
 		goto ERROR;
 
-    /* Insert the assets into the master table (We do this one by one because we want to insert file
-     * assets as absolute paths. */
-    if (mport_db_prepare(mport->db, &insert, "INSERT INTO assets (pkg, type, data, checksum, owner, grp, mode) values (%Q,?,?,?,?,?,?)", pkg->name) !=
-        MPORT_OK)
-        goto ERROR;
+	/* Insert the assets into the master table (We do this one by one because we want to insert file
+	* assets as absolute paths. */
+	if (mport_db_prepare(mport->db, &insert,
+	                     "INSERT INTO assets (pkg, type, data, checksum, owner, grp, mode) values (%Q,?,?,?,?,?,?)",
+	                     pkg->name) != MPORT_OK)
+		goto ERROR;
 
-    (void) strlcpy(cwd, pkg->prefix, sizeof(cwd));
+	(void) strlcpy(cwd, pkg->prefix, sizeof(cwd));
 
-    if (mport_chdir(mport, cwd) != MPORT_OK)
-        goto ERROR;
+	if (mport_chdir(mport, cwd) != MPORT_OK)
+		goto ERROR;
 
 	mport_db_do(mport->db, "BEGIN TRANSACTION");
 
 	STAILQ_FOREACH(e, alist, next) {
-        switch (e->type) {
-            case ASSET_CWD:
-                (void) strlcpy(cwd, e->data == NULL ? pkg->prefix : e->data, sizeof(cwd));
-                if (mport_chdir(mport, cwd) != MPORT_OK)
-                    goto ERROR;
-                break;
-            case ASSET_CHMOD:
-                if (mode != NULL)
-                    free(mode);
-                /* TODO: should we reset the mode rather than NULL here */
-                if (e->data == NULL)
-                    mode = NULL;
-                else
-                    mode = strdup(e->data);
-                break;
-            case ASSET_CHOWN:
-                owner = mport_get_uid(e->data);
-                break;
-            case ASSET_CHGRP:
-                group = mport_get_gid(e->data);
-                break;
-            case ASSET_DIR:
-            case ASSET_DIRRM:
-            case ASSET_DIRRMTRY:
-	    	case ASSET_DIR_OWNER_MODE:
-				mkdirp = strdup(e->data); /* need a char * here */
+		switch (e->type) {
+			case ASSET_CWD:
+				(void) strlcpy(cwd, e->data == NULL ? pkg->prefix : e->data, sizeof(cwd));
+				if (mport_chdir(mport, cwd) != MPORT_OK)
+					goto ERROR;
+				break;
+			case ASSET_CHMOD:
+				if (mode != NULL)
+					free(mode);
+				/* TODO: should we reset the mode rather than NULL here */
+				if (e->data == NULL)
+					mode = NULL;
+				else
+					mode = strdup(e->data);
+				break;
+			case ASSET_CHOWN:
+				owner = mport_get_uid(e->data);
+				break;
+			case ASSET_CHGRP:
+				group = mport_get_gid(e->data);
+				break;
+			case ASSET_DIR:
+			case ASSET_DIRRM:
+			case ASSET_DIRRMTRY:
+			case ASSET_DIR_OWNER_MODE:
+				mkdirp = strdup( e->data == NULL ? "" : e->data); /* need a char * here */
 				if (mkdirp == NULL || mport_mkdirp(mkdirp, S_IRWXU | S_IRWXG | S_IRWXO) == 0) {
 					free(mkdirp);
 					SET_ERRORX(MPORT_ERR_FATAL, "Unable to create directory %s", e->data);
@@ -416,45 +416,46 @@
 				}
 				free(mkdirp);
 
-                if (e->mode != NULL && e->mode[0] != '\0') {
-                       if ((dirset = setmode(e->mode)) == NULL)
-                             goto ERROR;
-                       dirnewmode = getmode(dirset, sb.st_mode);
-                       free(dirset);
-                       if (chmod(e->data, dirnewmode))
-                           goto ERROR;
+				if (e->mode != NULL && e->mode[0] != '\0') {
+					if ((dirset = setmode(e->mode)) == NULL)
+						goto ERROR;
+					dirnewmode = getmode(dirset, sb.st_mode);
+					free(dirset);
+					if (chmod(e->data, dirnewmode))
+						goto ERROR;
 				}
-	        	if (e->owner != NULL && e->group != NULL && e->owner[0] != '\0' && e->group[0] != '\0') {
+				if (e->owner != NULL && e->group != NULL && e->owner[0] != '\0' &&
+				    e->group[0] != '\0') {
 					if (chown(e->data, mport_get_uid(e->owner), mport_get_gid(e->group)) == -1) {
 						SET_ERROR(MPORT_ERR_FATAL, "Unable to change owner");
 						goto ERROR;
 					}
-                } else if (e->owner != NULL && e->owner[0] != '\0') {
+				} else if (e->owner != NULL && e->owner[0] != '\0') {
 					if (chown(e->data, mport_get_uid(e->owner), group) == -1) {
 						SET_ERROR(MPORT_ERR_FATAL, "Unable to change owner");
 						goto ERROR;
 					}
-                } else if (e->group != NULL && e->group[0] != '\0') {
+				} else if (e->group != NULL && e->group[0] != '\0') {
 					if (chown(e->data, owner, mport_get_gid(e->group)) == -1) {
 						SET_ERROR(MPORT_ERR_FATAL, "Unable to change owner");
 						goto ERROR;
 					}
-                }
-	
+				}
+
 				break;
-            case ASSET_EXEC:
-                if (mport_run_asset_exec(mport, e->data, cwd, file) != MPORT_OK)
-                    goto ERROR;
-                break;
-            case ASSET_FILE_OWNER_MODE:
+			case ASSET_EXEC:
+				if (mport_run_asset_exec(mport, e->data, cwd, file) != MPORT_OK)
+					goto ERROR;
+				break;
+			case ASSET_FILE_OWNER_MODE:
 				/* FALLS THROUGH */
-            case ASSET_FILE:
-                /* FALLS THROUGH */
-            case ASSET_SHELL:
-                /* FALLS THROUGH */
-            case ASSET_SAMPLE:
-                if (mport_bundle_read_next_entry(bundle, &entry) != MPORT_OK)
-                    goto ERROR;
+			case ASSET_FILE:
+				/* FALLS THROUGH */
+			case ASSET_SHELL:
+				/* FALLS THROUGH */
+			case ASSET_SAMPLE:
+				if (mport_bundle_read_next_entry(bundle, &entry) != MPORT_OK)
+					goto ERROR;
 
 				(void) snprintf(file, FILENAME_MAX, "%s%s/%s", mport->root, cwd, e->data);
 				if (entry == NULL) {
@@ -462,24 +463,26 @@
 					goto ERROR;
 				}
 
-                archive_entry_set_pathname(entry, file);
+				archive_entry_set_pathname(entry, file);
 
-                if (mport_bundle_read_extract_next_file(bundle, entry) != MPORT_OK)
-                    goto ERROR;
+				if (mport_bundle_read_extract_next_file(bundle, entry) != MPORT_OK)
+					goto ERROR;
 
-                if (lstat(file, &sb)) {
-		    		SET_ERRORX(MPORT_ERR_FATAL, "Unable to stat file %s", file);
-                    goto ERROR;
+				if (lstat(file, &sb)) {
+					SET_ERRORX(MPORT_ERR_FATAL, "Unable to stat file %s", file);
+					goto ERROR;
 				}
 
-                if (S_ISREG(sb.st_mode)) {
-		    		if (e->type == ASSET_FILE_OWNER_MODE) {
+				if (S_ISREG(sb.st_mode)) {
+					if (e->type == ASSET_FILE_OWNER_MODE) {
 						/* Test for owner and group settings, otherwise roll with our default. */
-						if (e->owner != NULL && e->group != NULL && e->owner[0] != '\0' && e->group[0] != '\0') {
+						if (e->owner != NULL && e->group != NULL && e->owner[0] != '\0' &&
+						    e->group[0] != '\0') {
 #ifdef DEBUG
 							fprintf(stderr, "owner %s and group %s\n", fm_owner, fm_group);
 #endif
-							if (chown(file, mport_get_uid(e->owner), mport_get_gid(e->group)) == -1) {
+							if (chown(file, mport_get_uid(e->owner),
+							          mport_get_gid(e->group)) == -1) {
 								SET_ERROR(MPORT_ERR_FATAL, "Unable to change owner");
 								goto ERROR;
 							}
@@ -506,58 +509,60 @@
 								goto ERROR;
 							}
 						}
-		    		} else {
+					} else {
 						/* Set the owner and group */
 						if (chown(file, owner, group) == -1) {
-							SET_ERRORX(MPORT_ERR_FATAL, "Unable to set permissions on file %s", file);
+							SET_ERRORX(MPORT_ERR_FATAL,
+							           "Unable to set permissions on file %s", file);
 							goto ERROR;
 						}
-		    		}
+					}
 
-                    /* Set the file permissions, assumes non NFSv4 */
-                    if (mode != NULL) {
-                        if (stat(file, &sb)) {
-			    			SET_ERRORX(MPORT_ERR_FATAL, "Unable to stat file %s", file);
-                            goto ERROR;
+					/* Set the file permissions, assumes non NFSv4 */
+					if (mode != NULL) {
+						if (stat(file, &sb)) {
+							SET_ERRORX(MPORT_ERR_FATAL, "Unable to stat file %s", file);
+							goto ERROR;
 						}
 						if (e->type == ASSET_FILE_OWNER_MODE && e->mode != NULL) {
-                        	if ((set = setmode(e->mode)) == NULL) {
+							if ((set = setmode(e->mode)) == NULL) {
 								SET_ERROR(MPORT_ERR_FATAL, "Unable to set mode");
 								goto ERROR;
 							}
 						} else {
-                        	if ((set = setmode(mode)) == NULL) {
+							if ((set = setmode(mode)) == NULL) {
 								SET_ERROR(MPORT_ERR_FATAL, "Unable to set mode");
 								goto ERROR;
 							}
 						}
 						newmode = getmode(set, sb.st_mode);
-                    	free(set);
+						free(set);
 						if (chmod(file, newmode)) {
-			    			SET_ERROR(MPORT_ERR_FATAL, "Unable to set file permissions");
+							SET_ERROR(MPORT_ERR_FATAL, "Unable to set file permissions");
 							goto ERROR;
 						}
-                    }
+					}
 
-                    /* shell registration */
-                    if (e->type == ASSET_SHELL && mport_shell_register(file) != MPORT_OK) {
+					/* shell registration */
+					if (e->type == ASSET_SHELL && mport_shell_register(file) != MPORT_OK) {
 						goto ERROR;
-                    }
+					}
 
-                    /* for sample files, if we don't have an existing file, make a new one */
+					/* for sample files, if we don't have an existing file, make a new one */
 					if (e->type == ASSET_SAMPLE && create_sample_file(file) != MPORT_OK) {
-						SET_ERRORX(MPORT_ERR_FATAL, "Unable to create sample file from %s", file);
+						SET_ERRORX(MPORT_ERR_FATAL, "Unable to create sample file from %s",
+						           file);
 						goto ERROR;
 					}
-                }
+				}
 
-                (mport->progress_step_cb)(++file_count, file_total, file);
+				(mport->progress_step_cb)(++file_count, file_total, file);
 
-                break;
-            default:
-                /* do nothing */
-                break;
-        }
+				break;
+			default:
+				/* do nothing */
+				break;
+		}
 
 		/* insert this asset into the master database */
 		__block int code = MPORT_OK;
@@ -565,143 +570,144 @@
 		__block char *filePtr = strdup(file);
 		__block char *cwdPtr = strdup(cwd);
 		dispatch_sync(mportSQLSerial, ^{
-			char dir[FILENAME_MAX];
-			if (sqlite3_bind_int(insert, 1, (int) e->type) != SQLITE_OK) {
-				code = MPORT_ERR_FATAL;
-				err = sqlite3_errmsg(mport->db);
-				return;
-			}
-			if (e->type == ASSET_FILE || e->type == ASSET_SAMPLE || e->type == ASSET_SHELL ||
-				e->type == ASSET_FILE_OWNER_MODE) {
-				/* don't put the root in the database! */
-				if (sqlite3_bind_text(insert, 2, filePtr + strlen(mport->root), -1, SQLITE_STATIC) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
+		    char dir[FILENAME_MAX];
+		    if (sqlite3_bind_int(insert, 1, (int) e->type) != SQLITE_OK) {
+			    code = MPORT_ERR_FATAL;
+			    err = sqlite3_errmsg(mport->db);
+			    return;
+		    }
+		    if (e->type == ASSET_FILE || e->type == ASSET_SAMPLE || e->type == ASSET_SHELL ||
+		        e->type == ASSET_FILE_OWNER_MODE) {
+			    /* don't put the root in the database! */
+			    if (sqlite3_bind_text(insert, 2, filePtr + strlen(mport->root), -1, SQLITE_STATIC) !=
+			        SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
 
-				if (sqlite3_bind_text(insert, 3, e->checksum, -1, SQLITE_STATIC) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
+			    if (sqlite3_bind_text(insert, 3, e->checksum, -1, SQLITE_STATIC) != SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
 
-				if (e->owner != NULL) {
-					if (sqlite3_bind_text(insert, 4, e->owner, -1, SQLITE_STATIC) != SQLITE_OK) {
-						code = MPORT_ERR_FATAL;
-						err = sqlite3_errmsg(mport->db);
-						return;
-					}
-				} else {
-					if (sqlite3_bind_null(insert, 4) != SQLITE_OK) {
-						code = MPORT_ERR_FATAL;
-						err = sqlite3_errmsg(mport->db);
-						return;
-					}
-				}
+			    if (e->owner != NULL) {
+				    if (sqlite3_bind_text(insert, 4, e->owner, -1, SQLITE_STATIC) != SQLITE_OK) {
+					    code = MPORT_ERR_FATAL;
+					    err = sqlite3_errmsg(mport->db);
+					    return;
+				    }
+			    } else {
+				    if (sqlite3_bind_null(insert, 4) != SQLITE_OK) {
+					    code = MPORT_ERR_FATAL;
+					    err = sqlite3_errmsg(mport->db);
+					    return;
+				    }
+			    }
 
-				if (e->group != NULL) {
-					if (sqlite3_bind_text(insert, 5, e->group, -1, SQLITE_STATIC) != SQLITE_OK) {
-						code = MPORT_ERR_FATAL;
-						err = sqlite3_errmsg(mport->db);
-						return;
-					}
-				} else {
-					if (sqlite3_bind_null(insert, 5) != SQLITE_OK) {
-						code = MPORT_ERR_FATAL;
-						err = sqlite3_errmsg(mport->db);
-						return;
-					}
-				}
+			    if (e->group != NULL) {
+				    if (sqlite3_bind_text(insert, 5, e->group, -1, SQLITE_STATIC) != SQLITE_OK) {
+					    code = MPORT_ERR_FATAL;
+					    err = sqlite3_errmsg(mport->db);
+					    return;
+				    }
+			    } else {
+				    if (sqlite3_bind_null(insert, 5) != SQLITE_OK) {
+					    code = MPORT_ERR_FATAL;
+					    err = sqlite3_errmsg(mport->db);
+					    return;
+				    }
+			    }
 
-				if (e->mode != NULL) {
-					if (sqlite3_bind_text(insert, 6, e->mode, -1, SQLITE_STATIC) != SQLITE_OK) {
-						code = MPORT_ERR_FATAL;
-						err = sqlite3_errmsg(mport->db);
-						return;
-					}
-				} else {
-					if (sqlite3_bind_null(insert, 6) != SQLITE_OK) {
-						code = MPORT_ERR_FATAL;
-						err = sqlite3_errmsg(mport->db);
-						return;
-					}
-				}
-			} else if (e->type == ASSET_DIR || e->type == ASSET_DIRRM || e->type == ASSET_DIRRMTRY) {
-				/* if data starts with /, it's most likely an absolute path. Don't prepend cwd */
-				if (e->data != NULL && e->data[0] == '/')
-					(void) snprintf(dir, FILENAME_MAX, "%s", e->data);
-				else
-					(void) snprintf(dir, FILENAME_MAX, "%s/%s", cwdPtr, e->data);
+			    if (e->mode != NULL) {
+				    if (sqlite3_bind_text(insert, 6, e->mode, -1, SQLITE_STATIC) != SQLITE_OK) {
+					    code = MPORT_ERR_FATAL;
+					    err = sqlite3_errmsg(mport->db);
+					    return;
+				    }
+			    } else {
+				    if (sqlite3_bind_null(insert, 6) != SQLITE_OK) {
+					    code = MPORT_ERR_FATAL;
+					    err = sqlite3_errmsg(mport->db);
+					    return;
+				    }
+			    }
+		    } else if (e->type == ASSET_DIR || e->type == ASSET_DIRRM || e->type == ASSET_DIRRMTRY) {
+			    /* if data starts with /, it's most likely an absolute path. Don't prepend cwd */
+			    if (e->data != NULL && e->data[0] == '/')
+				    (void) snprintf(dir, FILENAME_MAX, "%s", e->data);
+			    else
+				    (void) snprintf(dir, FILENAME_MAX, "%s/%s", cwdPtr, e->data);
 
-				if (sqlite3_bind_text(insert, 2, dir, -1, SQLITE_STATIC) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
+			    if (sqlite3_bind_text(insert, 2, dir, -1, SQLITE_STATIC) != SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
 
-				if (sqlite3_bind_null(insert, 3) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
+			    if (sqlite3_bind_null(insert, 3) != SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
 
-				if (sqlite3_bind_null(insert, 4) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
+			    if (sqlite3_bind_null(insert, 4) != SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
 
-				if (sqlite3_bind_null(insert, 5) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
+			    if (sqlite3_bind_null(insert, 5) != SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
 
-				if (sqlite3_bind_null(insert, 6) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
-			} else {
-				if (sqlite3_bind_text(insert, 2, e->data, -1, SQLITE_STATIC) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
+			    if (sqlite3_bind_null(insert, 6) != SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
+		    } else {
+			    if (sqlite3_bind_text(insert, 2, e->data, -1, SQLITE_STATIC) != SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
 
-				if (sqlite3_bind_null(insert, 3) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
+			    if (sqlite3_bind_null(insert, 3) != SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
 
-				if (sqlite3_bind_null(insert, 4) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
+			    if (sqlite3_bind_null(insert, 4) != SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
 
-				if (sqlite3_bind_null(insert, 5) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
+			    if (sqlite3_bind_null(insert, 5) != SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
 
-				if (sqlite3_bind_null(insert, 6) != SQLITE_OK) {
-					code = MPORT_ERR_FATAL;
-					err = sqlite3_errmsg(mport->db);
-					return;
-				}
-			}
+			    if (sqlite3_bind_null(insert, 6) != SQLITE_OK) {
+				    code = MPORT_ERR_FATAL;
+				    err = sqlite3_errmsg(mport->db);
+				    return;
+			    }
+		    }
 
-			if (sqlite3_step(insert) != SQLITE_DONE) {
-				code = MPORT_ERR_FATAL;
-				err = sqlite3_errmsg(mport->db);
-				return;
-			}
+		    if (sqlite3_step(insert) != SQLITE_DONE) {
+			    code = MPORT_ERR_FATAL;
+			    err = sqlite3_errmsg(mport->db);
+			    return;
+		    }
 
-			sqlite3_reset(insert);
+		    sqlite3_reset(insert);
 		});
 
 		free(filePtr);
@@ -726,7 +732,7 @@
 	mport_assetlist_free(alist);
 	return (MPORT_OK);
 
-ERROR:
+	ERROR:
 	sqlite3_finalize(insert);
 	(mport->progress_free_cb)();
 	free(orig_cwd);
@@ -743,7 +749,7 @@
                                   if (mport_copy_file(from, to) != MPORT_OK) \
                                     RETURN_CURRENT_ERROR; \
                                 }
-                                
+
 static int
 mark_complete(mportInstance *mport, mportPackageMeta *pkg)
 {
@@ -759,20 +765,20 @@
 static int
 do_post_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta *pkg)
 {
-    char to[FILENAME_MAX], from[FILENAME_MAX];
+	char to[FILENAME_MAX], from[FILENAME_MAX]; /* keep these for COPY_METAFILE */
 
-    COPY_METAFILE(MPORT_MTREE_FILE);
-    COPY_METAFILE(MPORT_INSTALL_FILE);
-    COPY_METAFILE(MPORT_DEINSTALL_FILE);
-    COPY_METAFILE(MPORT_MESSAGE_FILE);
+	COPY_METAFILE(MPORT_MTREE_FILE);
+	COPY_METAFILE(MPORT_INSTALL_FILE);
+	COPY_METAFILE(MPORT_DEINSTALL_FILE);
+	COPY_METAFILE(MPORT_MESSAGE_FILE);
 
-    if (run_postexec(mport, pkg) != MPORT_OK)
-        RETURN_CURRENT_ERROR;
+	if (run_postexec(mport, pkg) != MPORT_OK)
+		RETURN_CURRENT_ERROR;
 
-    if (display_pkg_msg(mport, bundle, pkg) != MPORT_OK)
-        RETURN_CURRENT_ERROR;
+	if (display_pkg_msg(mport, bundle, pkg) != MPORT_OK)
+		RETURN_CURRENT_ERROR;
 
-    if (run_pkg_install(mport, bundle, pkg, "POST-INSTALL") != MPORT_OK)
+	if (run_pkg_install(mport, bundle, pkg, "POST-INSTALL") != MPORT_OK)
 		RETURN_CURRENT_ERROR;
 
 	return mark_complete(mport, pkg);
@@ -786,49 +792,49 @@
 	mportAssetListEntry *e = NULL;
 	char cwd[FILENAME_MAX];
 
-    /* Process @postexec steps */
+	/* Process @postexec steps */
 	if (mport_bundle_read_get_assetlist(mport, pkg, &alist, POSTINSTALL) != MPORT_OK)
 		goto ERROR;
 
-    (void) strlcpy(cwd, pkg->prefix, sizeof(cwd));
+	(void) strlcpy(cwd, pkg->prefix, sizeof(cwd));
 
-    if (mport_chdir(mport, cwd) != MPORT_OK)
-        goto ERROR;
+	if (mport_chdir(mport, cwd) != MPORT_OK)
+		goto ERROR;
 
 	STAILQ_FOREACH(e, alist, next) {
-        char file[FILENAME_MAX];
-        if (e->data == NULL) {
-            snprintf(file, sizeof(file), "%s", mport->root);
-        } else if (e->data[0] == '/') {
-            snprintf(file, sizeof(file), "%s%s", mport->root, e->data);
-        } else {
-            snprintf(file, sizeof(file), "%s%s/%s", mport->root, pkg->prefix, e->data);
-        }
+		char file[FILENAME_MAX];
+		if (e->data == NULL) {
+			snprintf(file, sizeof(file), "%s", mport->root);
+		} else if (e->data[0] == '/') {
+			snprintf(file, sizeof(file), "%s%s", mport->root, e->data);
+		} else {
+			snprintf(file, sizeof(file), "%s%s/%s", mport->root, pkg->prefix, e->data);
+		}
 
-        switch (e->type) {
-            case ASSET_CWD:
-                (void) strlcpy(cwd, e->data == NULL ? pkg->prefix : e->data, sizeof(cwd));
-                if (mport_chdir(mport, cwd) != MPORT_OK)
-                    goto ERROR;
-                break;
-            case ASSET_POSTEXEC:
-                if (mport_run_asset_exec(mport, e->data, cwd, file) != MPORT_OK)
-                    goto ERROR;
-                break;
-            default:
-                /* do nothing */
-                break;
-        }
-    }
+		switch (e->type) {
+			case ASSET_CWD:
+				(void) strlcpy(cwd, e->data == NULL ? pkg->prefix : e->data, sizeof(cwd));
+				if (mport_chdir(mport, cwd) != MPORT_OK)
+					goto ERROR;
+				break;
+			case ASSET_POSTEXEC:
+				if (mport_run_asset_exec(mport, e->data, cwd, file) != MPORT_OK)
+					goto ERROR;
+				break;
+			default:
+				/* do nothing */
+				break;
+		}
+	}
 
 	mport_assetlist_free(alist);
-    mport_pkgmeta_logevent(mport, pkg, "postexec");
+	mport_pkgmeta_logevent(mport, pkg, "postexec");
 
-    return MPORT_OK;
+	return MPORT_OK;
 
-    ERROR:
+	ERROR:
 	// TODO: asset list free
-    RETURN_CURRENT_ERROR;
+	RETURN_CURRENT_ERROR;
 }
 
 
@@ -835,18 +841,20 @@
 static int
 run_mtree(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta *pkg)
 {
-    char file[FILENAME_MAX];
-    int ret;
+	char file[FILENAME_MAX];
+	int ret;
 
-    (void) snprintf(file, FILENAME_MAX, "%s/%s/%s-%s/%s", bundle->tmpdir, MPORT_STUB_INFRA_DIR, pkg->name, pkg->version,
-                    MPORT_MTREE_FILE);
+	(void) snprintf(file, FILENAME_MAX, "%s/%s/%s-%s/%s", bundle->tmpdir, MPORT_STUB_INFRA_DIR, pkg->name,
+	                pkg->version,
+	                MPORT_MTREE_FILE);
 
-    if (mport_file_exists(file)) {
-        if ((ret = mport_xsystem(mport, "%s -U -f %s -d -e -p %s >/dev/null", MPORT_MTREE_BIN, file, pkg->prefix)) != 0)
-            RETURN_ERRORX(MPORT_ERR_FATAL, "%s returned non-zero: %i", MPORT_MTREE_BIN, ret);
-    }
+	if (mport_file_exists(file)) {
+		if ((ret = mport_xsystem(mport, "%s -U -f %s -d -e -p %s >/dev/null", MPORT_MTREE_BIN, file,
+		                         pkg->prefix)) != 0)
+			RETURN_ERRORX(MPORT_ERR_FATAL, "%s returned non-zero: %i", MPORT_MTREE_BIN, ret);
+	}
 
-    return MPORT_OK;
+	return MPORT_OK;
 }
 
 
@@ -853,56 +861,56 @@
 static int
 run_pkg_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta *pkg, const char *mode)
 {
-    char file[FILENAME_MAX];
-    int ret;
+	char file[FILENAME_MAX];
+	int ret;
 
-    (void) snprintf(file, FILENAME_MAX, "%s/%s/%s-%s/%s", bundle->tmpdir, MPORT_STUB_INFRA_DIR, pkg->name, pkg->version,
-                    MPORT_INSTALL_FILE);
+	(void) snprintf(file, FILENAME_MAX, "%s/%s/%s-%s/%s", bundle->tmpdir, MPORT_STUB_INFRA_DIR, pkg->name,
+	                pkg->version,
+	                MPORT_INSTALL_FILE);
 
-    if (mport_file_exists(file)) {
-        if (chmod(file, 755) != 0)
-            RETURN_ERRORX(MPORT_ERR_FATAL, "chmod(%s, 755): %s", file, strerror(errno));
+	if (mport_file_exists(file)) {
+		if (chmod(file, 755) != 0)
+			RETURN_ERRORX(MPORT_ERR_FATAL, "chmod(%s, 755): %s", file, strerror(errno));
 
-        if ((ret = mport_xsystem(mport, "PKG_PREFIX=%s %s %s %s", pkg->prefix, file, pkg->name, mode)) != 0)
-            RETURN_ERRORX(MPORT_ERR_FATAL, "%s %s returned non-zero: %i", MPORT_INSTALL_FILE, mode, ret);
-    }
+		if ((ret = mport_xsystem(mport, "PKG_PREFIX=%s %s %s %s", pkg->prefix, file, pkg->name, mode)) != 0)
+			RETURN_ERRORX(MPORT_ERR_FATAL, "%s %s returned non-zero: %i", MPORT_INSTALL_FILE, mode, ret);
+	}
 
-    return MPORT_OK;
+	return MPORT_OK;
 }
- 
 
 
 static int
 display_pkg_msg(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta *pkg)
 {
-    char filename[FILENAME_MAX];
-    char *buf;
-    struct stat st;
-    FILE *file;
+	char filename[FILENAME_MAX];
+	char *buf;
+	struct stat st;
+	FILE *file;
 
-    (void) snprintf(filename, FILENAME_MAX, "%s/%s/%s-%s/%s", bundle->tmpdir, MPORT_STUB_INFRA_DIR, pkg->name,
-                    pkg->version, MPORT_MESSAGE_FILE);
+	(void) snprintf(filename, FILENAME_MAX, "%s/%s/%s-%s/%s", bundle->tmpdir, MPORT_STUB_INFRA_DIR, pkg->name,
+	                pkg->version, MPORT_MESSAGE_FILE);
 
-    if (stat(filename, &st) == -1)
-        /* if we couldn't stat the file, we assume there isn't a pkg-msg */
-        return MPORT_OK;
+	if (stat(filename, &st) == -1)
+		/* if we couldn't stat the file, we assume there isn't a pkg-msg */
+		return MPORT_OK;
 
-    if ((file = fopen(filename, "r")) == NULL)
-        RETURN_ERRORX(MPORT_ERR_FATAL, "Couldn't open %s: %s", filename, strerror(errno));
+	if ((file = fopen(filename, "r")) == NULL)
+		RETURN_ERRORX(MPORT_ERR_FATAL, "Couldn't open %s: %s", filename, strerror(errno));
 
-    if ((buf = (char *) calloc((size_t)(st.st_size + 1), sizeof(char))) == NULL)
-        RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
+	if ((buf = (char *) calloc((size_t) (st.st_size + 1), sizeof(char))) == NULL)
+		RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
 
-    if (fread(buf, 1, (size_t)st.st_size, file) != (size_t) st.st_size) {
-        free(buf);
-        RETURN_ERRORX(MPORT_ERR_FATAL, "Read error: %s", strerror(errno));
-    }
+	if (fread(buf, 1, (size_t) st.st_size, file) != (size_t) st.st_size) {
+		free(buf);
+		RETURN_ERRORX(MPORT_ERR_FATAL, "Read error: %s", strerror(errno));
+	}
 
-    buf[st.st_size] = 0;
+	buf[st.st_size] = 0;
 
-    mport_call_msg_cb(mport, buf);
+	mport_call_msg_cb(mport, buf);
 
-    free(buf);
+	free(buf);
 
-    return MPORT_OK;
+	return MPORT_OK;
 }

Modified: trunk/lib/libmport/clean.c
===================================================================
--- trunk/lib/libmport/clean.c	2016-08-20 23:08:10 UTC (rev 7751)
+++ trunk/lib/libmport/clean.c	2016-08-21 00:07:05 UTC (rev 7752)
@@ -37,66 +37,70 @@
 #include <errno.h>
 #include <dirent.h>
 
-MPORT_PUBLIC_API int 
-mport_clean_database(mportInstance *mport) {
-    __block int error_code = MPORT_OK;
+MPORT_PUBLIC_API int
+mport_clean_database(mportInstance *mport)
+{
+	__block int error_code = MPORT_OK;
 
-    dispatch_sync(mportTaskSerial, ^{
-        if (mport_db_do(mport->db, "vacuum") != MPORT_OK) {
-            error_code = mport_err_code();
-            mport_call_msg_cb(mport, "Database maintenance failed: %s\n", mport_err_string());
-	} else {
-            mport_call_msg_cb(mport, "Database maintenance complete.\n");
-	}
-    });
+	dispatch_sync(mportTaskSerial, ^{
+	    if (mport_db_do(mport->db, "vacuum") != MPORT_OK) {
+		    error_code = mport_err_code();
+		    mport_call_msg_cb(mport, "Database maintenance failed: %s\n", mport_err_string());
+	    } else {
+		    mport_call_msg_cb(mport, "Database maintenance complete.\n");
+	    }
+	});
 
-    return error_code;
+	return error_code;
 }
 
 MPORT_PUBLIC_API int
-mport_clean_oldpackages(mportInstance *mport) {
-    __block int error_code = MPORT_OK;
+mport_clean_oldpackages(mportInstance *mport)
+{
+	__block int error_code = MPORT_OK;
 
-    dispatch_sync(mportTaskSerial, ^{
-	int deleted = 0;
-        struct dirent *de;
-        DIR *d = opendir(MPORT_FETCH_STAGING_DIR);
+	dispatch_sync(mportTaskSerial, ^{
+	    int deleted = 0;
+	    struct dirent *de;
+	    DIR *d = opendir(MPORT_FETCH_STAGING_DIR);
 
-        if (d == NULL) {
-		error_code = SET_ERRORX(MPORT_ERR_FATAL, "Couldn't open directory %s: %s", MPORT_FETCH_STAGING_DIR, strerror(errno));
-		return;
-	}
+	    if (d == NULL) {
+		    error_code = SET_ERRORX(MPORT_ERR_FATAL, "Couldn't open directory %s: %s", MPORT_FETCH_STAGING_DIR,
+		                            strerror(errno));
+		    return;
+	    }
 
-            while ((de = readdir(d)) != NULL) {
-                mportIndexEntry **indexEntry;
-                char *path;
-                if (strcmp(".", de->d_name) == 0 || strcmp("..", de->d_name) == 0)
-                    continue;
+	    while ((de = readdir(d)) != NULL) {
+		    mportIndexEntry **indexEntry;
+		    char *path;
+		    if (strcmp(".", de->d_name) == 0 || strcmp("..", de->d_name) == 0)
+			    continue;
 
-                if (mport_index_search(mport, &indexEntry, "bundlefile=%Q", de->d_name) != MPORT_OK) {
-			continue;
-                }
+		    if (mport_index_search(mport, &indexEntry, "bundlefile=%Q", de->d_name) != MPORT_OK) {
+			    continue;
+		    }
 
-                if (indexEntry == NULL || *indexEntry == NULL) {
-                    asprintf(&path, "%s/%s", MPORT_FETCH_STAGING_DIR, de->d_name);
-                    if (path != NULL)  {
-			if (unlink(path) < 0) {
-                       		error_code = SET_ERRORX(MPORT_ERR_FATAL, "Could not delete file %s: %s", path, strerror(errno));
-				mport_call_msg_cb(mport, "%s\n", mport_err_string());
-                    	} else {
-				deleted++;
-			}
-                    	free(path);
+		    if (indexEntry == NULL || *indexEntry == NULL) {
+			    asprintf(&path, "%s/%s", MPORT_FETCH_STAGING_DIR, de->d_name);
+			    if (path != NULL) {
+				    if (unlink(path) < 0) {
+					    error_code = SET_ERRORX(MPORT_ERR_FATAL, "Could not delete file %s: %s",
+					                            path, strerror(errno));
+					    mport_call_msg_cb(mport, "%s\n", mport_err_string());
+				    } else {
+					    deleted++;
+				    }
+				    free(path);
+			    }
+		    } else {
+			    mport_index_entry_free_vec(indexEntry);
 		    }
-                } else {
-                    mport_index_entry_free_vec(indexEntry);
-                }
-            }
+	    }
 
-            closedir(d);
+	    closedir(d);
 
-		mport_call_msg_cb(mport, "Cleaned up %d packages.\n", deleted);
-        });
+	    mport_call_msg_cb(mport, "Cleaned up %d packages.\n", deleted);
+	});
 
 	return error_code;
 }

Modified: trunk/lib/libmport/info.c
===================================================================
--- trunk/lib/libmport/info.c	2016-08-20 23:08:10 UTC (rev 7751)
+++ trunk/lib/libmport/info.c	2016-08-21 00:07:05 UTC (rev 7752)
@@ -36,66 +36,68 @@
 
 
 MPORT_PUBLIC_API char *
-mport_info(mportInstance *mport, const char *packageName) {
-    mportIndexEntry **indexEntry;
-    mportPackageMeta **packs;
-    char *status, *origin;
-    char *os_release;
-    char *cpe;
-    int locked = 0;
-    char *info_text = NULL;
+mport_info(mportInstance *mport, const char *packageName)
+{
+	mportIndexEntry **indexEntry;
+	mportPackageMeta **packs;
+	char *status, *origin;
+	char *os_release;
+	char *cpe;
+	int locked = 0;
+	char *info_text = NULL;
 
-    if (packageName == NULL) {
-        SET_ERROR(MPORT_ERR_FATAL, "Package name not found.");
-        return (NULL);
-    }
+	if (packageName == NULL) {
+		SET_ERROR(MPORT_ERR_FATAL, "Package name not found.");
+		return (NULL);
+	}
 
 
-    if (mport_index_lookup_pkgname(mport, packageName, &indexEntry) != MPORT_OK) {
-       return (NULL);
-    }
+	if (mport_index_lookup_pkgname(mport, packageName, &indexEntry) != MPORT_OK) {
+		return (NULL);
+	}
 
-    if (indexEntry == NULL || *indexEntry == NULL) {
-        SET_ERROR(MPORT_ERR_FATAL, "Could not resolve package.");
-        return (NULL);
-    }
+	if (indexEntry == NULL || *indexEntry == NULL) {
+		SET_ERROR(MPORT_ERR_FATAL, "Could not resolve package.");
+		return (NULL);
+	}
 
-    if (mport_pkgmeta_search_master(mport, &packs, "pkg=%Q", packageName) != MPORT_OK) {
-        return (NULL);
-    }
+	if (mport_pkgmeta_search_master(mport, &packs, "pkg=%Q", packageName) != MPORT_OK) {
+		return (NULL);
+	}
 
-    if (packs == NULL) {
-        status = strdup("N/A");
-        origin = strdup("");
-        os_release = strdup("");
-        cpe = strdup("");
-    } else {
-        status = (*packs)->version;
-        origin = (*packs)->origin;
-        os_release = (*packs)->os_release;
-        cpe = (*packs)->cpe;
-        locked = (*packs)->locked;
-    }
+	if (packs == NULL) {
+		status = strdup("N/A");
+		origin = strdup("");
+		os_release = strdup("");
+		cpe = strdup("");
+	} else {
+		status = (*packs)->version;
+		origin = (*packs)->origin;
+		os_release = (*packs)->os_release;
+		cpe = (*packs)->cpe;
+		locked = (*packs)->locked;
+	}
 
-    asprintf(&info_text, "%s\nlatest: %s\ninstalled: %s\nlicense: %s\norigin: %s\nos: %s\n\n%s\ncpe: %s\nlocked: %s\n",
-           (*indexEntry)->pkgname,
-           (*indexEntry)->version,
-           status,
-           (*indexEntry)->license,
-           origin,
-           os_release,
-           (*indexEntry)->comment,
-           cpe,
-           locked ? "yes" : "no");
+	asprintf(&info_text,
+	         "%s\nlatest: %s\ninstalled: %s\nlicense: %s\norigin: %s\nos: %s\n\n%s\ncpe: %s\nlocked: %s\n",
+	         (*indexEntry)->pkgname,
+	         (*indexEntry)->version,
+	         status,
+	         (*indexEntry)->license,
+	         origin,
+	         os_release,
+	         (*indexEntry)->comment,
+	         cpe,
+	         locked ? "yes" : "no");
 
-    if (packs == NULL) {
-        free(status);
-        free(origin);
-        free(os_release);
-        free(cpe);
-    } else
-        mport_pkgmeta_vec_free(packs);
+	if (packs == NULL) {
+		free(status);
+		free(origin);
+		free(os_release);
+		free(cpe);
+	} else
+		mport_pkgmeta_vec_free(packs);
 
-    mport_index_entry_free_vec(indexEntry);
-    return info_text;
+	mport_index_entry_free_vec(indexEntry);
+	return info_text;
 }
\ No newline at end of file

Modified: trunk/lib/libmport/install_primative.c
===================================================================
--- trunk/lib/libmport/install_primative.c	2016-08-20 23:08:10 UTC (rev 7751)
+++ trunk/lib/libmport/install_primative.c	2016-08-21 00:07:05 UTC (rev 7752)
@@ -34,51 +34,52 @@
 #include <string.h>
 
 MPORT_PUBLIC_API int
-mport_install_primative(mportInstance *mport, const char *filename, const char *prefix) 
+mport_install_primative(mportInstance *mport, const char *filename, const char *prefix)
 {
-  mportBundleRead *bundle;
-  mportPackageMeta **pkgs, *pkg;
-  int i;
-  bool error = false;
-  
-  if ((bundle = mport_bundle_read_new()) == NULL)
-    RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
-  
-  if (mport_bundle_read_init(bundle, filename) != MPORT_OK)
-    RETURN_CURRENT_ERROR;
+	mportBundleRead *bundle;
+	mportPackageMeta **pkgs, *pkg;
+	int i;
+	bool error = false;
 
-  if (mport_bundle_read_prep_for_install(mport, bundle) != MPORT_OK)
-    RETURN_CURRENT_ERROR;
-  
-  if (mport_pkgmeta_read_stub(mport, &pkgs) != MPORT_OK)
-    RETURN_CURRENT_ERROR;
-  
-  for (i=0; *(pkgs + i) != NULL; i++) {
-    pkg = pkgs[i];
-    
-    if (prefix != NULL) {
-      /* override the default prefix with the given prefix */
-      free(pkg->prefix);
-      if ((pkg->prefix = strdup(prefix)) == NULL) /* all hope is lost! bail */
-        RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
-    }
+	if ((bundle = mport_bundle_read_new()) == NULL)
+		RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
 
-    if ((mport_check_preconditions(mport, pkg, MPORT_PRECHECK_INSTALLED|MPORT_PRECHECK_DEPENDS|MPORT_PRECHECK_CONFLICTS) != MPORT_OK) 
-                      || 
-        (mport_bundle_read_install_pkg(mport, bundle, pkg) != MPORT_OK)) 
-    {
-      mport_call_msg_cb(mport, "Unable to install %s-%s: %s", pkg->name, pkg->version, mport_err_string());
-      /* TODO: WHY WAS THIS HERE mport_set_err(MPORT_OK, NULL); */
-		error = true;
-		break; /* do not keep going if we have a package failure! */
-    }
-  }
+	if (mport_bundle_read_init(bundle, filename) != MPORT_OK)
+		RETURN_CURRENT_ERROR;
 
-  if (mport_bundle_read_finish(mport, bundle) != MPORT_OK)
-    RETURN_CURRENT_ERROR;
+	if (mport_bundle_read_prep_for_install(mport, bundle) != MPORT_OK)
+		RETURN_CURRENT_ERROR;
 
-  if (error)
-     return MPORT_ERR_FATAL;
-    
-  return MPORT_OK;  
+	if (mport_pkgmeta_read_stub(mport, &pkgs) != MPORT_OK)
+		RETURN_CURRENT_ERROR;
+
+	for (i = 0; *(pkgs + i) != NULL; i++) {
+		pkg = pkgs[i];
+
+		if (prefix != NULL) {
+			/* override the default prefix with the given prefix */
+			free(pkg->prefix);
+			if ((pkg->prefix = strdup(prefix)) == NULL) /* all hope is lost! bail */
+				RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
+		}
+
+		if ((mport_check_preconditions(mport, pkg, MPORT_PRECHECK_INSTALLED | MPORT_PRECHECK_DEPENDS |
+		                                           MPORT_PRECHECK_CONFLICTS) != MPORT_OK)
+		    ||
+		    (mport_bundle_read_install_pkg(mport, bundle, pkg) != MPORT_OK)) {
+			mport_call_msg_cb(mport, "Unable to install %s-%s: %s", pkg->name, pkg->version,
+			                  mport_err_string());
+			/* TODO: WHY WAS THIS HERE mport_set_err(MPORT_OK, NULL); */
+			error = true;
+			break; /* do not keep going if we have a package failure! */
+		}
+	}
+
+	if (mport_bundle_read_finish(mport, bundle) != MPORT_OK)
+		RETURN_CURRENT_ERROR;
+
+	if (error)
+		return MPORT_ERR_FATAL;
+
+	return MPORT_OK;
 }



More information about the Midnightbsd-cvs mailing list