Update application output when using --dry-run and --resync and database is corrupt (Issue#844) (#845)

* Update application output when database is corrupt and how to resolve by using --resync
* Handle --dry-run and --resync correctly - do not copy the database, it may be corrupt
* Always check if items-dryrun.sqlite3 still exists, remove it as it maybe corrupt when --dry-run is used
This commit is contained in:
abraunegg 2020-03-30 06:55:27 +11:00 committed by GitHub
parent 3708828806
commit 50fb2d8bfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View file

@ -277,11 +277,24 @@ int main(string[] args)
// dry-run database setup
if (cfg.getValueBool("dry_run")) {
// If the dry run database exists, clean this up
if (exists(cfg.databaseFilePathDryRun)) {
// remove the existing file
log.vdebug("Removing items-dryrun.sqlite3 as it still exists for some reason");
safeRemove(cfg.databaseFilePathDryRun);
}
// Make a copy of the original items.sqlite3 for use as the dry run copy if it exists
if (exists(cfg.databaseFilePath)) {
// copy the file
log.vdebug("Copying items.sqlite3 to items-dryrun.sqlite3 to use for dry run operations");
copy(cfg.databaseFilePath,cfg.databaseFilePathDryRun);
// in a --dry-run --resync scenario, we should not copy the existing database file
if (!cfg.getValueBool("resync")) {
// copy the existing DB file to the dry-run copy
log.vdebug("Copying items.sqlite3 to items-dryrun.sqlite3 to use for dry run operations");
copy(cfg.databaseFilePath,cfg.databaseFilePathDryRun);
} else {
// no database copy due to --resync
log.vdebug("No database copy created for --dry-run due to --resync also being used");
}
}
}

View file

@ -87,6 +87,7 @@ struct Database
int rc = sqlite3_exec(pDb, toStringz(sql), null, null, null);
if (rc != SQLITE_OK) {
log.error("\nA database execution error occurred: "~ getErrorMessage() ~ "\n");
log.error("Please retry your command with --resync to fix any local database corruption issues.\n");
close();
exit(-1);
}
@ -184,6 +185,7 @@ struct Statement
} else {
string errorMessage = ifromStringz(sqlite3_errmsg(sqlite3_db_handle(pStmt)));
log.error("\nA database statement execution error occurred: "~ errorMessage ~ "\n");
log.error("Please retry your command with --resync to fix any local database corruption issues.\n");
exit(-1);
}
}