From aaf8505205eba73a3ffa1dfa04e34a4b1a8f65b2 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Mon, 1 Aug 2022 07:35:19 +1000 Subject: [PATCH] Update --resync handling of database file removal (#2067) * Only safe remove the files from the local file system if these are exclusively available for this running instance to perform a delete - otherwise this allows multiple clients to perform a --resync on the same data, which, could lead to a data loss scenario --- src/main.d | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.d b/src/main.d index f766c888..4b95e811 100644 --- a/src/main.d +++ b/src/main.d @@ -743,9 +743,14 @@ int main(string[] args) return EXIT_FAILURE; } - // Handle --resync to remove local files + // Handle the actual --resync to remove local files if (cfg.getValueBool("resync")) { log.vdebug("--resync requested"); + log.vdebug("Testing if we have exclusive access to local database file"); + // Are we the only running instance? Test that we can open the database file path + itemDb = new ItemDatabase(cfg.databaseFilePath); + destroy(itemDb); + // If we have exclusive access we will not have exited log.log("Deleting the saved application sync status ..."); if (!cfg.getValueBool("dry_run")) { safeRemove(cfg.databaseFilePath);