[geary] Ensure Db.Database corruption check doesn't fail on missing DB file.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary] Ensure Db.Database corruption check doesn't fail on missing DB file.
- Date: Mon, 21 May 2018 13:11:28 +0000 (UTC)
commit 1b49fc110464a815927df3accb52f3babd6d5dbd
Author: Michael James Gratton <mike vee net>
Date: Mon May 21 21:01:34 2018 +1000
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.
src/engine/db/db-database.vala | 4 ++-
test/engine/db/db-database-test.vala | 51 ++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 1 deletions(-)
---
diff --git a/src/engine/db/db-database.vala b/src/engine/db/db-database.vala
index a558ef1..3d3aeb2 100644
--- a/src/engine/db/db-database.vala
+++ b/src/engine/db/db-database.vala
@@ -136,7 +136,9 @@ public class Geary.Db.Database : Geary.Db.Context {
warning("SQLite not thread-safe: asynchronous queries will not be available");
}
- if ((flags & DatabaseFlags.CHECK_CORRUPTION) != 0) {
+ if ((flags & DatabaseFlags.CHECK_CORRUPTION) != 0 &&
+ this.file != null &&
+ yield Geary.Files.query_exists_async(this.file, cancellable)) {
yield Nonblocking.Concurrent.global.schedule_async(() => {
check_for_corruption(flags, cancellable);
}, cancellable);
diff --git a/test/engine/db/db-database-test.vala b/test/engine/db/db-database-test.vala
index e79e8d4..25b5dda 100644
--- a/test/engine/db/db-database-test.vala
+++ b/test/engine/db/db-database-test.vala
@@ -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();
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]