Resolve segfault when running 'onedrive --display-sync-status' when run as 2nd process (#2105)

* Rather than force exit if unable to lock the database, add a function and boolean to control if the database access has been init was successful. If not, use the exit scopes to exit the application
This commit is contained in:
abraunegg 2022-08-30 19:09:35 +10:00 committed by GitHub
parent 3b7a06cdcd
commit 5288f94ac4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -42,6 +42,7 @@ final class ItemDatabase
string selectItemByIdStmt; string selectItemByIdStmt;
string selectItemByParentIdStmt; string selectItemByParentIdStmt;
string deleteItemByIdStmt; string deleteItemByIdStmt;
bool databaseInitialised = false;
this(const(char)[] filename) this(const(char)[] filename)
{ {
@ -61,7 +62,7 @@ final class ItemDatabase
log.error("ERROR: An internal database error occurred: " ~ e.msg); log.error("ERROR: An internal database error occurred: " ~ e.msg);
writeln(); writeln();
} }
exit(-1); return;
} }
if (dbVersion == 0) { if (dbVersion == 0) {
@ -114,6 +115,14 @@ final class ItemDatabase
"; ";
selectItemByParentIdStmt = "SELECT * FROM item WHERE driveId = ? AND parentId = ?"; selectItemByParentIdStmt = "SELECT * FROM item WHERE driveId = ? AND parentId = ?";
deleteItemByIdStmt = "DELETE FROM item WHERE driveId = ? AND id = ?"; 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() void createTable()

View file

@ -936,6 +936,14 @@ int main(string[] args)
log.vdebug("Using database file: ", asNormalizedPath(cfg.databaseFilePath)); log.vdebug("Using database file: ", asNormalizedPath(cfg.databaseFilePath));
itemDb = new ItemDatabase(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? // What are the permission that have been set for the application?
// These are relevant for: // These are relevant for:
@ -1901,7 +1909,7 @@ extern(C) nothrow @nogc @system void exitHandler(int value) {
oneDrive.shutdown(); oneDrive.shutdown();
} }
// was itemDb initialised? // was itemDb initialised?
if (itemDb !is null) { if (itemDb.isDatabaseInitialised()) {
// Make sure the .wal file is incorporated into the main db before we exit // Make sure the .wal file is incorporated into the main db before we exit
log.log("Shutting down db connection and merging temporary data"); log.log("Shutting down db connection and merging temporary data");
itemDb.performVacuum(); itemDb.performVacuum();