diff --git a/src/itemdb.d b/src/itemdb.d index 72a097e1..d3210609 100644 --- a/src/itemdb.d +++ b/src/itemdb.d @@ -42,6 +42,7 @@ final class ItemDatabase string selectItemByIdStmt; string selectItemByParentIdStmt; string deleteItemByIdStmt; + bool databaseInitialised = false; this(const(char)[] filename) { @@ -61,7 +62,7 @@ final class ItemDatabase log.error("ERROR: An internal database error occurred: " ~ e.msg); writeln(); } - exit(-1); + return; } if (dbVersion == 0) { @@ -114,6 +115,14 @@ final class ItemDatabase "; selectItemByParentIdStmt = "SELECT * FROM item WHERE driveId = ? AND parentId = ?"; deleteItemByIdStmt = "DELETE FROM item WHERE driveId = ? AND id = ?"; + + // flag that the database is accessible and we have control + databaseInitialised = true; + } + + bool isDatabaseInitialised() + { + return databaseInitialised; } void createTable() diff --git a/src/main.d b/src/main.d index ebc35e8b..d155a62b 100644 --- a/src/main.d +++ b/src/main.d @@ -936,6 +936,14 @@ int main(string[] args) log.vdebug("Using database file: ", asNormalizedPath(cfg.databaseFilePath)); itemDb = new ItemDatabase(cfg.databaseFilePath); } + + // did we successfully initialise the database class? + if (!itemDb.isDatabaseInitialised()) { + // no .. destroy class + itemDb = null; + // exit application + return EXIT_FAILURE; + } // What are the permission that have been set for the application? // These are relevant for: @@ -1901,7 +1909,7 @@ extern(C) nothrow @nogc @system void exitHandler(int value) { oneDrive.shutdown(); } // was itemDb initialised? - if (itemDb !is null) { + if (itemDb.isDatabaseInitialised()) { // Make sure the .wal file is incorporated into the main db before we exit log.log("Shutting down db connection and merging temporary data"); itemDb.performVacuum();