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
This commit is contained in:
abraunegg 2022-08-01 07:35:19 +10:00 committed by GitHub
parent b2991fded9
commit aaf8505205
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);