summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@gmail.com>2012-12-17 14:28:02 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2013-01-09 13:56:07 +0100
commit6f89276d0065a3476f9072ae5ec116633f56bdc1 (patch)
tree19365dabe7ced913873aa4d14b70472972ca4fce
parent694a948ae7e29b6bd1000c293727ad3651fb270f (diff)
downloadmsitools-6f89276d0065a3476f9072ae5ec116633f56bdc1.tar.gz
msitools-6f89276d0065a3476f9072ae5ec116633f56bdc1.tar.xz
msitools-6f89276d0065a3476f9072ae5ec116633f56bdc1.zip
database: make commit() GObject-like
-rw-r--r--include/libmsi-database.h4
-rw-r--r--libmsi/libmsi-database.c42
-rw-r--r--tests/testdatabase.c96
-rw-r--r--tools/msibuild.c18
4 files changed, 77 insertions, 83 deletions
diff --git a/include/libmsi-database.h b/include/libmsi-database.h
index 84666e0..2ea23bb 100644
--- a/include/libmsi-database.h
+++ b/include/libmsi-database.h
@@ -67,8 +67,8 @@ gboolean libmsi_database_merge (LibmsiDatabase *db,
LibmsiDatabase *merge,
const char *table,
GError **error);
-LibmsiResult libmsi_database_commit (LibmsiDatabase *);
-
+gboolean libmsi_database_commit (LibmsiDatabase *db,
+ GError **error);
G_END_DECLS
diff --git a/libmsi/libmsi-database.c b/libmsi/libmsi-database.c
index 470dacc..0720cc3 100644
--- a/libmsi/libmsi-database.c
+++ b/libmsi/libmsi-database.c
@@ -2291,15 +2291,15 @@ end:
return ret;
}
-LibmsiResult libmsi_database_commit( LibmsiDatabase *db )
+gboolean
+libmsi_database_commit (LibmsiDatabase *db, GError **error)
{
unsigned r = LIBMSI_RESULT_SUCCESS;
unsigned bytes_per_strref;
- TRACE("%d\n", db);
+ TRACE ("%p\n", db);
- if( !db )
- return LIBMSI_RESULT_INVALID_HANDLE;
+ g_return_val_if_fail (LIBMSI_IS_DATABASE (db), FALSE);
g_object_ref(db);
if (db->mode == LIBMSI_DB_OPEN_READONLY)
@@ -2307,31 +2307,31 @@ LibmsiResult libmsi_database_commit( LibmsiDatabase *db )
/* FIXME: lock the database */
- r = msi_save_string_table( db->strings, db, &bytes_per_strref );
- if( r != LIBMSI_RESULT_SUCCESS )
- {
- WARN("failed to save string table r=%08x\n",r);
+ r = msi_save_string_table (db->strings, db, &bytes_per_strref);
+ if (r != LIBMSI_RESULT_SUCCESS) {
+ g_set_error (error, LIBMSI_RESULT_ERROR, r,
+ "failed to save string table r=%08x\n", r);
goto end;
}
- r = msi_enum_db_storages( db, commit_storage, db );
- if (r != LIBMSI_RESULT_SUCCESS)
- {
- WARN("failed to save storages r=%08x\n",r);
+ r = msi_enum_db_storages (db, commit_storage, db);
+ if (r != LIBMSI_RESULT_SUCCESS) {
+ g_set_error (error, LIBMSI_RESULT_ERROR, r,
+ "failed to save storages r=%08x\n", r);
goto end;
}
- r = msi_enum_db_streams( db, commit_stream, db );
- if (r != LIBMSI_RESULT_SUCCESS)
- {
- WARN("failed to save streams r=%08x\n",r);
+ r = msi_enum_db_streams (db, commit_stream, db);
+ if (r != LIBMSI_RESULT_SUCCESS) {
+ g_set_error (error, LIBMSI_RESULT_ERROR, r,
+ "failed to save streams r=%08x\n", r);
goto end;
}
- r = _libmsi_database_commit_tables( db, bytes_per_strref );
- if (r != LIBMSI_RESULT_SUCCESS)
- {
- WARN("failed to save tables r=%08x\n",r);
+ r = _libmsi_database_commit_tables (db, bytes_per_strref);
+ if (r != LIBMSI_RESULT_SUCCESS) {
+ g_set_error (error, LIBMSI_RESULT_ERROR, r,
+ "failed to save tables r=%08x\n", r);
goto end;
}
@@ -2347,7 +2347,7 @@ LibmsiResult libmsi_database_commit( LibmsiDatabase *db )
end:
g_object_unref(db);
- return r;
+ return r == LIBMSI_RESULT_SUCCESS;
}
struct msi_primary_key_record_info
diff --git a/tests/testdatabase.c b/tests/testdatabase.c
index 6aebd5e..3e95f49 100644
--- a/tests/testdatabase.c
+++ b/tests/testdatabase.c
@@ -67,8 +67,8 @@ static void test_msidatabase(void)
hdb = libmsi_database_new(msifile, LIBMSI_DB_OPEN_CREATE, NULL );
ok(hdb , "Failed to create database\n" );
- res = libmsi_database_commit( hdb );
- ok( res == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n" );
+ res = libmsi_database_commit(hdb, NULL);
+ ok(res, "Failed to commit database\n");
ok( -1 != access( msifile, F_OK ), "database should exist\n");
@@ -77,8 +77,8 @@ static void test_msidatabase(void)
hdb2 = libmsi_database_new( msifile, msifile2, NULL );
ok(hdb2 , "Failed to open database\n" );
- res = libmsi_database_commit( hdb2 );
- ok( res == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n" );
+ res = libmsi_database_commit(hdb2, NULL);
+ ok(res , "Failed to commit database\n");
ok( -1 != access( msifile2, F_OK ), "database should exist\n");
@@ -94,8 +94,8 @@ static void test_msidatabase(void)
hdb2 = libmsi_database_new( msifile, msifile2, NULL );
ok( hdb2 , "Failed to close database\n" );
- res = libmsi_database_commit( hdb2 );
- ok( res == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n" );
+ res = libmsi_database_commit(hdb2, NULL);
+ ok(res, "Failed to commit database\n");
g_object_unref( hdb2 );
@@ -104,8 +104,8 @@ static void test_msidatabase(void)
hdb = libmsi_database_new( msifile, LIBMSI_DB_OPEN_READONLY, NULL );
ok(hdb , "Failed to open database\n" );
- res = libmsi_database_commit( hdb );
- ok( res == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n" );
+ res = libmsi_database_commit(hdb, NULL);
+ ok(res, "Failed to commit database\n");
g_object_unref( hdb );
@@ -128,8 +128,8 @@ static void test_msidatabase(void)
hdb = libmsi_database_new( msifile, LIBMSI_DB_OPEN_CREATE, NULL );
ok(hdb , "Failed to open database\n" );
- res = libmsi_database_commit( hdb );
- ok( res == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n" );
+ res = libmsi_database_commit(hdb, NULL);
+ ok(res, "Failed to commit database\n", res);
ok( -1 != access( msifile, F_OK ), "database should exist\n");
@@ -431,8 +431,8 @@ static void test_msiinsert(void)
hrec = libmsi_query_fetch(0, NULL);
ok(!hrec, "libmsi_query_fetch must fail\n");
- r = libmsi_database_commit(hdb);
- ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_database_commit failed\n");
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "libmsi_database_commit failed\n");
g_object_unref(hdb);
@@ -495,8 +495,8 @@ static void test_msibadqueries(void)
hdb = libmsi_database_new(msifile, LIBMSI_DB_OPEN_CREATE, NULL);
ok(hdb, "libmsi_database_open failed\n");
- r = libmsi_database_commit( hdb );
- ok(r == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n");
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "Failed to commit database\n");
g_object_unref( hdb );
@@ -577,8 +577,8 @@ static void test_msibadqueries(void)
"CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
ok(r == LIBMSI_RESULT_SUCCESS , "query 4 failed\n");
- r = libmsi_database_commit( hdb );
- ok(r == LIBMSI_RESULT_SUCCESS , "Failed to commit database after write\n");
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "Failed to commit database after write\n");
r = try_query( hdb, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
"PRIMARY KEY `foo`)");
@@ -587,8 +587,8 @@ static void test_msibadqueries(void)
r = try_insert_query( hdb, "insert into a ( `b` ) VALUES ( ? )");
ok(r == LIBMSI_RESULT_SUCCESS , "failed to insert record in db\n");
- r = libmsi_database_commit( hdb );
- ok(r == LIBMSI_RESULT_SUCCESS , "Failed to commit database after write\n");
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "Failed to commit database after write\n");
r = try_query( hdb, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
"PRIMARY KEY `ba`)");
@@ -711,8 +711,8 @@ static LibmsiDatabase *create_db(void)
hdb = libmsi_database_new(msifile, LIBMSI_DB_OPEN_CREATE, NULL );
ok(hdb , "Failed to create database\n" );
- res = libmsi_database_commit( hdb );
- ok( res == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n" );
+ res = libmsi_database_commit(hdb, NULL);
+ ok(res, "Failed to commit database\n");
return hdb;
}
@@ -1040,8 +1040,8 @@ static void test_longstrings(void)
r = try_query( hdb, str );
ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_database_open_query failed\n");
- r = libmsi_database_commit(hdb);
- ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_database_commit failed\n");
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "libmsi_database_commit failed\n");
g_object_unref(hdb);
hdb = libmsi_database_new(msifile, LIBMSI_DB_OPEN_READONLY, NULL);
@@ -1111,8 +1111,8 @@ static void test_streamtable(void)
"( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
ok( r == LIBMSI_RESULT_SUCCESS, "Failed to add to table\n" );
- r = libmsi_database_commit( hdb );
- ok( r == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n" );
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "Failed to commit database\n");
g_object_unref( hdb );
@@ -1354,8 +1354,8 @@ static void test_binary(void)
g_object_unref( rec );
- r = libmsi_database_commit( hdb );
- ok( r == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n" );
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "Failed to commit database\n" );
g_object_unref( hdb );
@@ -2452,8 +2452,8 @@ static LibmsiDatabase *create_package_db(const char *filename)
hdb = libmsi_database_new(filename, LIBMSI_DB_OPEN_CREATE, NULL );
ok(hdb , "Failed to create database\n" );
- res = libmsi_database_commit( hdb );
- ok( res == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n" );
+ res = libmsi_database_commit(hdb, NULL);
+ ok(res, "Failed to commit database\n");
res = set_summary_info(hdb);
ok( res == LIBMSI_RESULT_SUCCESS , "Failed to set summary info\n" );
@@ -2516,8 +2516,8 @@ static void test_try_transform(void)
g_object_unref(hrec);
- r = libmsi_database_commit( hdb );
- ok( r == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n" );
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "Failed to commit database\n");
g_object_unref( hdb );
unlink("testdata.bin");
@@ -2530,7 +2530,7 @@ static void test_try_transform(void)
r = libmsi_database_apply_transform(hdb, mstfile, NULL);
ok(r, "libmsi_database_apply_transform() failed\n");
- libmsi_database_commit( hdb );
+ libmsi_database_commit(hdb, NULL);
/* check new values */
hrec = 0;
@@ -3739,8 +3739,8 @@ static void test_integers(void)
libmsi_query_close(query, NULL);
g_object_unref(query);
- r = libmsi_database_commit(hdb);
- ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_database_commit failed\n");
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "libmsi_database_commit failed\n");
g_object_unref(hdb);
@@ -4023,8 +4023,8 @@ static void test_update(void)
libmsi_query_close(query, NULL);
g_object_unref(query);
- r = libmsi_database_commit(hdb);
- ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_database_commit failed\n");
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "libmsi_database_commit failed\n");
g_object_unref(hdb);
unlink(msifile);
@@ -4617,8 +4617,8 @@ static void test_stringtable(void)
r = run_query(hdb, 0, sql);
ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
- r = libmsi_database_commit(hdb);
- ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "Expected LIBMSI_RESULT_SUCCESS\n");
g_object_unref(hdb);
@@ -5152,8 +5152,8 @@ static void test_deleterow(void)
r = run_query(hdb, 0, sql);
ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
- r = libmsi_database_commit(hdb);
- ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "Expected LIBMSI_RESULT_SUCCESS\n");
g_object_unref(hdb);
@@ -5654,8 +5654,8 @@ static void test_forcecodepage(void)
r = run_query(hdb, 0, sql);
ok(r == LIBMSI_RESULT_BAD_QUERY_SYNTAX, "Expected LIBMSI_RESULT_BAD_QUERY_SYNTAX, got %d\n", r);
- r = libmsi_database_commit(hdb);
- ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "Expected LIBMSI_RESULT_SUCCESS\n");
sql = "SELECT * FROM `_ForceCodepage`";
r = run_query(hdb, 0, sql);
@@ -5759,8 +5759,8 @@ static void test_storages_table(void)
hdb = create_db();
ok(hdb, "failed to create db\n");
- r = libmsi_database_commit(hdb);
- ok(r == LIBMSI_RESULT_SUCCESS , "Failed to commit database\n");
+ r = libmsi_database_commit(hdb, NULL);
+ ok(r, "Failed to commit database\n");
g_object_unref(hdb);
@@ -5830,7 +5830,7 @@ static void test_storages_table(void)
libmsi_query_close(hquery, NULL);
g_object_unref(hquery);
- libmsi_database_commit(hdb);
+ libmsi_database_commit(hdb, NULL);
g_object_unref(hdb);
MultiByteToWideChar(CP_ACP, 0, msifile, -1, name, MAX_PATH);
@@ -7202,8 +7202,8 @@ static void test_createtable(void)
g_object_unref( htab );
- res = libmsi_database_commit(hdb);
- ok(res == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", res);
+ res = libmsi_database_commit(hdb, NULL);
+ ok(res, "Expected LIBMSI_RESULT_SUCCESS\n");
g_object_unref(hdb);
@@ -7226,8 +7226,8 @@ static void test_createtable(void)
g_object_unref( htab );
}
- res = libmsi_database_commit(hdb);
- ok(res == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", res);
+ res = libmsi_database_commit(hdb, NULL);
+ ok(res, "Expected LIBMSI_RESULT_SUCCESS\n");
g_object_unref(hdb);
diff --git a/tools/msibuild.c b/tools/msibuild.c
index ff69cc4..cf52820 100644
--- a/tools/msibuild.c
+++ b/tools/msibuild.c
@@ -101,12 +101,11 @@ static LibmsiResult open_database(const char *msifile, LibmsiDatabase **db,
if (!init_suminfo(*si, error))
return LIBMSI_RESULT_FUNCTION_FAILED;
- r = libmsi_database_commit(*db);
- if (r != LIBMSI_RESULT_SUCCESS)
+ if (!libmsi_database_commit(*db, error))
{
- fprintf(stderr, "failed to commit database (%u)\n", r);
+ fprintf(stderr, "failed to commit database\n");
g_object_unref(*db);
- return r;
+ return LIBMSI_RESULT_FUNCTION_FAILED;
}
}
else
@@ -330,16 +329,11 @@ int main(int argc, char *argv[])
}
if (r == LIBMSI_RESULT_SUCCESS) {
- libmsi_summary_info_persist(si, &error);
- if (error)
+ if (!libmsi_summary_info_persist(si, &error))
goto end;
- r = libmsi_database_commit(db);
- if (r != LIBMSI_RESULT_SUCCESS)
- {
- fprintf(stderr, "failed to commit database (%u)\n", r);
- exit(1);
- }
+ if (!libmsi_database_commit(db, &error))
+ goto end;
}
end: