Added check to ensure backup exists when restoring (#2779)

A check to ensure that the backup database exists before deleting the
current database.

Fixes #2778

Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com>
This commit is contained in:
Matthew Nickson 2023-02-14 16:43:40 +00:00 committed by GitHub
parent c19dcdba44
commit cd18b96f69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -496,6 +496,16 @@ class Database {
const shmPath = Database.path + "-shm"; const shmPath = Database.path + "-shm";
const walPath = Database.path + "-wal"; const walPath = Database.path + "-wal";
// Make sure we have a backup to restore before deleting old db
if (
!fs.existsSync(this.backupPath)
&& !fs.existsSync(shmPath)
&& !fs.existsSync(walPath)
) {
log.error("db", "Backup file not found! Leaving database in failed state.");
process.exit(1);
}
// Delete patch failed db // Delete patch failed db
try { try {
if (fs.existsSync(Database.path)) { if (fs.existsSync(Database.path)) {