From 5506efb31303438579e426a3c9bdd22e1a779823 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Tue, 3 May 2022 15:09:08 +1000 Subject: [PATCH] Detect if application is already operational (#1944) * In some scenarios users may have a running background service syncing data (systemd or otherwise). In these events, running the application in standalone mode can create a conflict when attempting to perform database queries when there are significant changes to data structures occurring. This PR specifically checks if the database operation files are present, and, if these are present (meaning the application is most likely currently operational) fail fast and not execute the application as a second instance against the same active configuration. Potentially also resolves RBZ2061430 and RBZ2075468 --- src/main.d | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.d b/src/main.d index 510f7330..db3f00d6 100644 --- a/src/main.d +++ b/src/main.d @@ -162,6 +162,17 @@ 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")) {