Browse Source

Corrected ADatabase::restoreBackup

George 4 years ago
parent
commit
fac3b6f8e4
2 changed files with 10 additions and 9 deletions
  1. 8 8
      src/database/adatabase.cpp
  2. 2 1
      src/gui/widgets/backupwidget.cpp

+ 8 - 8
src/database/adatabase.cpp

@@ -751,21 +751,21 @@ bool ADatabase::restoreBackup(const QString& backup_file)
     QFile backup(backup_file);
     QFile current_db(databaseFile.absoluteFilePath());
 
-    if(!backup.isWritable()) {
+    // [G]: Wrong permissions would end up making a inf loop
+    // So i go defensively by checking first
+    if(backup.isWritable() == false || current_db.isWritable() == false) {
         WARN << backup << "is not writtable check PERMISSIONS";
         return false;
     }
 
-    // [G]: Wrong permissions would end up making a inf loop
-    // So i go defensively by checking first
-    if (!backup.copy(databaseFile.absoluteFilePath()))
-    {
-        WARN << "Could not copy" << backup << "to" << databaseFile;
+    if (!current_db.remove(databaseFile.absoluteFilePath())) {
+        WARN << current_db.errorString() << "Unable to delete current db file";
         return false;
     }
 
-    if (!current_db.remove(databaseFile.absoluteFilePath())) {
-        WARN << "Unable to restore backup. The following error has ocurred:" << current_db.errorString();
+    if (!backup.copy(databaseFile.absoluteFilePath()))
+    {
+        WARN << backup.errorString() << "Could not copy" << backup << "to" << databaseFile;
         return false;
     }
 

+ 2 - 1
src/gui/widgets/backupwidget.cpp

@@ -54,7 +54,6 @@ void BackupWidget::on_tableView_clicked(const QModelIndex &index)
 
 void BackupWidget::on_createLocalPushButton_clicked()
 {
-    NOT_IMPLEMENTED
     QString filename = QFileDialog::getSaveFileName(
                 this,
                 "Choose destination file",
@@ -84,6 +83,7 @@ void BackupWidget::on_createLocalPushButton_clicked()
 
 void BackupWidget::on_restoreLocalPushButton_clicked()
 {
+    NOT_IMPLEMENTED
     if(selectedBackupName == nullptr) {
         INFO << "No backup selected";
         return;
@@ -96,6 +96,7 @@ void BackupWidget::on_restoreLocalPushButton_clicked()
 
 void BackupWidget::on_deleteSelectedPushButton_clicked()
 {
+    NOT_IMPLEMENTED
     if(selectedBackupName == nullptr) {
         INFO << "No backup was selected";
         return;