[Midnightbsd-cvs] src [7509] trunk/lib/libmport/bundle_read_install_pkg.c: improve error handling for modes.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Apr 9 16:26:22 EDT 2016
Revision: 7509
http://svnweb.midnightbsd.org/src/?rev=7509
Author: laffer1
Date: 2016-04-09 16:26:21 -0400 (Sat, 09 Apr 2016)
Log Message:
-----------
improve error handling for modes. fix the file install count for the progress bar to include @() syntax.
Modified Paths:
--------------
trunk/lib/libmport/bundle_read_install_pkg.c
Modified: trunk/lib/libmport/bundle_read_install_pkg.c
===================================================================
--- trunk/lib/libmport/bundle_read_install_pkg.c 2016-04-09 20:25:07 UTC (rev 7508)
+++ trunk/lib/libmport/bundle_read_install_pkg.c 2016-04-09 20:26:21 UTC (rev 7509)
@@ -169,8 +169,8 @@
/* get the file count for the progress meter */
if (mport_db_prepare(db, &count,
- "SELECT COUNT(*) FROM stub.assets WHERE (type=%i or type=%i or type=%i) AND pkg=%Q",
- ASSET_FILE, ASSET_SAMPLE, ASSET_SHELL, 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)
RETURN_CURRENT_ERROR;
switch (sqlite3_step(count)) {
@@ -233,7 +233,7 @@
checksum = (char *) sqlite3_column_text(assets, 2);
fm_owner = (char *) sqlite3_column_text(assets, 3);
fm_group = (char *) sqlite3_column_text(assets, 4);
- fm_mode = (char *) sqlite3_column_text(assets, 5);
+ fm_mode = (char *) sqlite3_column_text(assets, 5);
switch (type) {
case ASSET_CWD:
@@ -243,7 +243,6 @@
break;
case ASSET_CHMOD:
- printf("asset_chmod %s, %s\n", mode, data);
if (mode != NULL)
free(mode);
/* TODO: should we reset the mode rather than NULL here */
@@ -279,7 +278,12 @@
if (mport_bundle_read_next_entry(bundle, &entry) != MPORT_OK)
goto ERROR;
- (void) snprintf(file, FILENAME_MAX, "%s%s/%s", mport->root, cwd, data);
+ (void) snprintf(file, FILENAME_MAX, "%s%s/%s", mport->root, cwd, data);
+ if (entry == NULL) {
+ SET_ERROR(MPORT_ERR_FATAL, "Unexpected EOF with archive file");
+ goto ERROR;
+ }
+
archive_entry_set_pathname(entry, file);
if (mport_bundle_read_extract_next_file(bundle, entry) != MPORT_OK)
@@ -291,15 +295,22 @@
if (S_ISREG(sb.st_mode)) {
if (type == ASSET_FILE_OWNER_MODE) {
/* Test for owner and group settings, otherwise roll with our default. */
- if (fm_owner != NULL && fm_group != NULL) {
+ if (fm_owner != NULL && fm_group != NULL && fm_owner[0] != '\0' && fm_group[0] != '\0') {
+ fprintf(stderr, "owner %s and group %s\n", fm_owner, fm_group);
if (chown(file, mport_get_uid(fm_owner), mport_get_gid(fm_group)) == -1)
goto ERROR;
- } else if (fm_owner != NULL) {
+ } else if (fm_owner != NULL && fm_owner[0] != '\0') {
+ fprintf(stderr, "owner %s\n", fm_owner);
if (chown(file, mport_get_uid(fm_owner), group) == -1)
goto ERROR;
- } else if (fm_group != NULL) {
+ } else if (fm_group != NULL && fm_group[0] != '\0') {
+ fprintf(stderr, "group %s\n", fm_group);
if (chown(file, owner, mport_get_gid(fm_group)) == -1)
goto ERROR;
+ } else {
+ // use default.
+ if (chown(file, owner, group) == -1)
+ goto ERROR;
}
} else {
/* Set the owner and group */
@@ -368,8 +379,21 @@
SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
goto ERROR;
}
+ if (sqlite3_bind_text(insert, 4, fm_owner, -1, SQLITE_STATIC) != SQLITE_OK) {
+ SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+ goto ERROR;
+ }
+ if (sqlite3_bind_text(insert, 5, fm_group, -1, SQLITE_STATIC) != SQLITE_OK) {
+ SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+ goto ERROR;
+ }
+ if (sqlite3_bind_text(insert, 6, fm_mode, -1, SQLITE_STATIC) != SQLITE_OK) {
+ SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+ goto ERROR;
+ }
} else if (type == ASSET_DIR || type == ASSET_DIRRM || type == ASSET_DIRRMTRY) {
(void) snprintf(dir, FILENAME_MAX, "%s/%s", cwd, data);
+
if (sqlite3_bind_text(insert, 2, dir, -1, SQLITE_STATIC) != SQLITE_OK) {
SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
goto ERROR;
@@ -379,6 +403,21 @@
SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
goto ERROR;
}
+
+ if (sqlite3_bind_null(insert, 4) != SQLITE_OK) {
+ SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+ goto ERROR;
+ }
+
+ if (sqlite3_bind_null(insert, 5) != SQLITE_OK) {
+ SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+ goto ERROR;
+ }
+
+ if (sqlite3_bind_null(insert, 6) != SQLITE_OK) {
+ SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+ goto ERROR;
+ }
} else {
if (sqlite3_bind_text(insert, 2, data, -1, SQLITE_STATIC) != SQLITE_OK) {
SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
@@ -389,6 +428,21 @@
SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
goto ERROR;
}
+
+ if (sqlite3_bind_null(insert, 4) != SQLITE_OK) {
+ SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+ goto ERROR;
+ }
+
+ if (sqlite3_bind_null(insert, 5) != SQLITE_OK) {
+ SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+ goto ERROR;
+ }
+
+ if (sqlite3_bind_null(insert, 6) != SQLITE_OK) {
+ SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+ goto ERROR;
+ }
}
if (sqlite3_step(insert) != SQLITE_DONE) {
More information about the Midnightbsd-cvs
mailing list