Improve application runtime check (#1955)

* Improve application runtime check fixing false positive when CTRL-C is used to terminate application
This commit is contained in:
abraunegg 2022-05-08 05:57:25 +10:00 committed by GitHub
parent 04c65f9b48
commit 7139578af1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 12 deletions

View file

@ -51,7 +51,13 @@ final class ItemDatabase
dbVersion = db.getVersion();
} catch (SqliteException e) {
// An error was generated - what was the error?
log.error("\nAn internal database error occurred: " ~ e.msg ~ "\n");
if (e.msg == "database is locked") {
log.error("\nERROR: onedrive application is already running - check system process list for active application instances");
log.vlog(" - Use 'sudo ps aufxw | grep onedrive' to potentially determine acive running process");
write("\n");
} else {
log.error("\nERROR: An internal database error occurred: " ~ e.msg ~ "\n");
}
exit(-1);
}
@ -84,6 +90,10 @@ final class ItemDatabase
// https://www.sqlite.org/pragma.html#pragma_auto_vacuum
// PRAGMA schema.auto_vacuum = 0 | NONE | 1 | FULL | 2 | INCREMENTAL;
db.exec("PRAGMA auto_vacuum = FULL");
// This pragma sets or queries the database connection locking-mode. The locking-mode is either NORMAL or EXCLUSIVE.
// https://www.sqlite.org/pragma.html#pragma_locking_mode
// PRAGMA schema.locking_mode = NORMAL | EXCLUSIVE
db.exec("PRAGMA locking_mode = EXCLUSIVE");
insertItemStmt = "
INSERT OR REPLACE INTO item (driveId, id, name, type, eTag, cTag, mtime, parentId, crc32Hash, sha1Hash, quickXorHash, remoteDriveId, remoteId, syncStatus)

View file

@ -163,17 +163,6 @@ int main(string[] args)
// update configuration from command line args
cfg.update_from_args(args);
// In some cases, a user may have a systemd service running, and, also attempt a manual sync
// This causes issues with DB items / DB entries if there are significant changes in the database
// Check to see if 'items.sqlite3-shm' and 'items.sqlite3-wal' are present - if they are present, we need to exit early
string activeShmFile = cfg.databaseFilePath ~ "-shm";
string activeWalFile = cfg.databaseFilePath ~ "-wal";
if (exists(asNormalizedPath(activeShmFile)) || exists(asNormalizedPath(activeWalFile))) {
log.error("ERROR: onedrive application is already running - check system process list for active application instances");
log.vlog(" - Use 'sudo ps aufxw | grep onedrive' to potentially determine acive running process");
return EXIT_FAILURE;
}
// --resync should be a 'last resort item' .. the user needs to 'accept' to proceed
if ((cfg.getValueBool("resync")) && (!cfg.getValueBool("display_config"))) {
// what is the risk acceptance?