mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-02 05:52:16 +02:00
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:
parent
3b7a06cdcd
commit
5288f94ac4
11
src/itemdb.d
11
src/itemdb.d
|
@ -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()
|
||||||
|
|
10
src/main.d
10
src/main.d
|
@ -937,6 +937,14 @@ int main(string[] args)
|
||||||
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:
|
||||||
// - The ~/OneDrive parent folder or 'sync_dir' configured item
|
// - The ~/OneDrive parent folder or 'sync_dir' configured item
|
||||||
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue