Skip to content

Commit cf8dc43

Browse files
authored
fix(db): clean directory before import (#370)
1 parent 57b080f commit cf8dc43

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/BSH.Main/Dialogs/frmMainTabs/ucDoConfigure.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Threading.Tasks;
2020
using System.Windows.Forms;
2121
using Brightbits.BSH.Engine;
22+
using Brightbits.BSH.Engine.Database;
2223
using Brightbits.BSH.Engine.Security;
2324
using Brightbits.BSH.Engine.Storage;
2425
using BSH.Main.Properties;
@@ -480,17 +481,16 @@ private async Task ShowWizardStepAsync(int iStep)
480481
}
481482

482483
// copy database from backup device
484+
DeleteCurrentDatabaseFile();
483485
File.Copy(lvBackups.SelectedItems[0].Tag.ToString() + @"\backup.bshdb", BackupLogic.DatabaseFile, true);
484486
}
485487
else if (tcStep5.SelectedIndex == 1)
486488
{
487489
// ftp server
488490
try
489491
{
490-
// delete old database file
491-
File.Delete(BackupLogic.DatabaseFile);
492-
493492
// download backup database
493+
DeleteCurrentDatabaseFile();
494494
using IStorage storage = new FtpStorage(
495495
txtFTPServer2.Text,
496496
int.Parse(txtFTPPort2.Text),
@@ -524,6 +524,7 @@ private async Task ShowWizardStepAsync(int iStep)
524524
}
525525

526526
// copy database from backup device
527+
DeleteCurrentDatabaseFile();
527528
File.Copy(txtPath.Text + @"\backup.bshdb", BackupLogic.DatabaseFile, true);
528529
}
529530

@@ -633,6 +634,30 @@ private async Task ShowWizardStepAsync(int iStep)
633634
}
634635
}
635636

637+
private static void DeleteCurrentDatabaseFile()
638+
{
639+
DbClientFactory.ClosePool();
640+
641+
// delete old database file
642+
File.Delete(BackupLogic.DatabaseFile);
643+
try
644+
{
645+
File.Delete(BackupLogic.DatabaseFile + "-wal");
646+
}
647+
catch
648+
{
649+
// ignore error
650+
}
651+
try
652+
{
653+
File.Delete(BackupLogic.DatabaseFile + "-shm");
654+
}
655+
catch (Exception)
656+
{
657+
// ignore error
658+
}
659+
}
660+
636661
private sealed class VersionEntry
637662
{
638663
public VersionEntry(string path, bool changed)

0 commit comments

Comments
 (0)