summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@gmail.com>2012-12-17 12:28:19 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2013-01-09 13:56:07 +0100
commit377666075f7eb5ee07e0c76ed18ce417f7491150 (patch)
tree159f5852bcb06c99dcf2bd859d7eb945b8359300
parent6106dcb112c0ff995744281c5a343a7918491884 (diff)
downloadmsitools-377666075f7eb5ee07e0c76ed18ce417f7491150.tar.gz
msitools-377666075f7eb5ee07e0c76ed18ce417f7491150.tar.xz
msitools-377666075f7eb5ee07e0c76ed18ce417f7491150.zip
database: make export() GObject-like
-rw-r--r--include/libmsi-database.h5
-rw-r--r--libmsi/libmsi-database.c15
-rw-r--r--tests/testdatabase.c12
-rw-r--r--tools/msiinfo.c22
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)