Ensure Db.Database corruption check doesn't fail on missing DB file.
* src/engine/db/db-database.vala (Context): Only run the corruption check if there is a DB file and the file exists. Add unit tests.
This commit is contained in:
parent
8d3b16ca68
commit
1b49fc1104
2 changed files with 54 additions and 1 deletions
|
|
@ -15,6 +15,8 @@ class Geary.Db.DatabaseTest : TestCase {
|
|||
add_test("open_create_file", open_create_file);
|
||||
add_test("open_create_dir", open_create_dir);
|
||||
add_test("open_create_dir_existing", open_create_dir_existing);
|
||||
add_test("open_check_corruption", open_check_corruption);
|
||||
add_test("open_create_check", open_create_check);
|
||||
}
|
||||
|
||||
public void transient_open() throws Error {
|
||||
|
|
@ -121,5 +123,54 @@ class Geary.Db.DatabaseTest : TestCase {
|
|||
tmp_dir.delete();
|
||||
}
|
||||
|
||||
public void open_check_corruption() throws Error {
|
||||
GLib.File tmp_dir = GLib.File.new_for_path(
|
||||
GLib.DirUtils.make_tmp("geary-db-database-test-XXXXXX")
|
||||
);
|
||||
|
||||
Database db = new Geary.Db.Database.persistent(
|
||||
tmp_dir.get_child("test.db")
|
||||
);
|
||||
db.open.begin(
|
||||
Geary.Db.DatabaseFlags.CREATE_FILE |
|
||||
Geary.Db.DatabaseFlags.CHECK_CORRUPTION,
|
||||
null, null,
|
||||
(obj, ret) => { async_complete(ret); }
|
||||
);
|
||||
db.open.end(async_result());
|
||||
|
||||
// Need to get a connection since the database doesn't
|
||||
// actually get created until then
|
||||
db.get_master_connection();
|
||||
|
||||
db.file.delete();
|
||||
tmp_dir.delete();
|
||||
}
|
||||
|
||||
public void open_create_check() throws Error {
|
||||
GLib.File tmp_dir = GLib.File.new_for_path(
|
||||
GLib.DirUtils.make_tmp("geary-db-database-test-XXXXXX")
|
||||
);
|
||||
|
||||
Database db = new Geary.Db.Database.persistent(
|
||||
tmp_dir.get_child("nonexistent").get_child("test.db")
|
||||
);
|
||||
db.open.begin(
|
||||
Geary.Db.DatabaseFlags.CREATE_DIRECTORY |
|
||||
Geary.Db.DatabaseFlags.CREATE_FILE |
|
||||
Geary.Db.DatabaseFlags.CHECK_CORRUPTION,
|
||||
null, null,
|
||||
(obj, ret) => { async_complete(ret); }
|
||||
);
|
||||
db.open.end(async_result());
|
||||
|
||||
// Need to get a connection since the database doesn't
|
||||
// actually get created until then
|
||||
db.get_master_connection();
|
||||
|
||||
db.file.delete();
|
||||
db.file.get_parent().delete();
|
||||
tmp_dir.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue