diff options
-rw-r--r-- | include/libmsi-database.h | 5 | ||||
-rw-r--r-- | libmsi/libmsi-database.c | 15 | ||||
-rw-r--r-- | tests/testdatabase.c | 12 | ||||
-rw-r--r-- | tools/msiinfo.c | 22 |
4 files changed, 34 insertions, 20 deletions
diff --git a/include/libmsi-database.h b/include/libmsi-database.h index c59bdcd..c3f4a99 100644 --- a/include/libmsi-database.h +++ b/include/libmsi-database.h @@ -53,7 +53,10 @@ LibmsiRecord * libmsi_database_get_primary_keys (LibmsiDatabase *db, gboolean libmsi_database_apply_transform (LibmsiDatabase *db, const char *file, GError **error); -LibmsiResult libmsi_database_export (LibmsiDatabase *, const char *, int fd); +gboolean libmsi_database_export (LibmsiDatabase *db, + const char *table, + int fd, + GError **error); LibmsiResult libmsi_database_import (LibmsiDatabase *, const char *, const char *); LibmsiCondition libmsi_database_is_table_persistent (LibmsiDatabase *, const char *); LibmsiResult libmsi_database_merge (LibmsiDatabase *, LibmsiDatabase *, const char *); diff --git a/libmsi/libmsi-database.c b/libmsi/libmsi-database.c index de1456a..33e0702 100644 --- a/libmsi/libmsi-database.c +++ b/libmsi/libmsi-database.c @@ -1333,8 +1333,11 @@ done: * * row4 : data <tab> data <tab> data <tab> ... data <cr> <lf> */ -LibmsiResult libmsi_database_export( LibmsiDatabase *db, const char *szTable, - int fd ) +gboolean +libmsi_database_export (LibmsiDatabase *db, + const char *table, + int fd, + GError **error) { unsigned r = LIBMSI_RESULT_OUTOFMEMORY; @@ -1344,9 +1347,13 @@ LibmsiResult libmsi_database_export( LibmsiDatabase *db, const char *szTable, return LIBMSI_RESULT_INVALID_HANDLE; g_object_ref(db); - r = _libmsi_database_export( db, szTable, fd ); + r = _libmsi_database_export(db, table, fd); g_object_unref(db); - return r; + + if (r != LIBMSI_RESULT_SUCCESS) + g_set_error (error, LIBMSI_RESULT_ERROR, r, G_STRFUNC); + + return r == LIBMSI_RESULT_SUCCESS; } typedef struct _tagMERGETABLE diff --git a/tests/testdatabase.c b/tests/testdatabase.c index c08101c..abc2d30 100644 --- a/tests/testdatabase.c +++ b/tests/testdatabase.c @@ -984,8 +984,8 @@ static void test_msiexport(void) fd = open(file, O_WRONLY | O_BINARY | O_CREAT, 0644); ok(fd != -1, "open failed\n"); - r = libmsi_database_export(hdb, "phone", fd); - ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_database_export failed\n"); + r = libmsi_database_export(hdb, "phone", fd, NULL); + ok(r, "libmsi_database_export failed\n"); close(fd); @@ -5669,8 +5669,8 @@ static void test_forcecodepage(void) fd = open("forcecodepage.idt", O_WRONLY | O_BINARY | O_CREAT, 0644); ok(fd != -1, "cannot open file\n"); - r = libmsi_database_export(hdb, "_ForceCodepage", fd); - ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r); + r = libmsi_database_export(hdb, "_ForceCodepage", fd, NULL); + ok(r, "Expected success\n"); close(fd); read_file_data("forcecodepage.idt", buffer); @@ -5685,8 +5685,8 @@ static void test_forcecodepage(void) fd = open("forcecodepage.idt", O_WRONLY | O_BINARY | O_CREAT, 0644); ok(fd != -1, "cannot open file\n"); - r = libmsi_database_export(hdb, "_ForceCodepage", fd); - ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r); + r = libmsi_database_export(hdb, "_ForceCodepage", fd, NULL); + ok(r, "Expected success\n"); close(fd); read_file_data("forcecodepage.idt", buffer); diff --git a/tools/msiinfo.c b/tools/msiinfo.c index ea41713..a9786d8 100644 --- a/tools/msiinfo.c +++ b/tools/msiinfo.c @@ -434,7 +434,7 @@ static unsigned export_create_table(const char *table, guint num_columns = libmsi_record_get_field_count(names); guint num_keys = libmsi_record_get_field_count(keys); guint i, len; - unsigned r; + unsigned r = LIBMSI_RESULT_SUCCESS; char size[20], extra[30]; gchar *name, *type; unsigned sz; @@ -660,7 +660,7 @@ done: static int cmd_export(struct Command *cmd, int argc, char **argv, GError **error) { LibmsiDatabase *db = NULL; - LibmsiResult r; + LibmsiResult r = LIBMSI_RESULT_SUCCESS; gboolean sql = FALSE; if (argc > 1 && !strcmp(argv[1], "-s")) { @@ -679,20 +679,24 @@ static int cmd_export(struct Command *cmd, int argc, char **argv, GError **error if (sql) { r = export_sql(db, argv[2], error); + if (r) { + print_libmsi_error(r); + } + + } else { #if O_BINARY _setmode(STDOUT_FILENO, O_BINARY); #endif - r = libmsi_database_export(db, argv[2], STDOUT_FILENO); - } - - if (r) { - print_libmsi_error(r); + if (!libmsi_database_export(db, argv[2], STDOUT_FILENO, error)) + goto end; } - g_object_unref(db); +end: + if (db) + g_object_unref(db); - return 0; + return *error ? 1 : 0; } static int cmd_version(struct Command *cmd, int argc, char **argv, GError **error) |