From 0ced152fc96c59f09d9b3d106886b425743ee720 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sat, 7 Sep 2024 04:19:05 +0300 Subject: [PATCH] fix: remove database when check connect to sqlite --- .../Configuration/SetupController.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Endpoint/Controllers/Configuration/SetupController.cs b/Endpoint/Controllers/Configuration/SetupController.cs index 5b7b149..db69a18 100644 --- a/Endpoint/Controllers/Configuration/SetupController.cs +++ b/Endpoint/Controllers/Configuration/SetupController.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Data; using System.IO; +using System.Linq; using System.Net.Mail; using System.Runtime.InteropServices; using System.Security.Cryptography; @@ -93,6 +94,10 @@ public class SetupController( connection.Open(); connection.Close(); + if (connection is SqliteConnection) + SqliteConnection.ClearAllPools(); + } + var general = GeneralConfig; general.DbSettings = new DbSettings { @@ -152,12 +157,21 @@ public class SetupController( else Directory.CreateDirectory(path, UnixFileMode.UserRead | UnixFileMode.UserWrite); } - else + else if (Directory.GetDirectories(path).Length != 0 || + !Directory.GetFiles(path).Select(x => string.Equals(Path.GetFileName(x), "database.db3")).All(x => x)) throw new ControllerArgumentException("Such a folder exists. Enter a different name"); - string connectionString = $"Data Source={PathBuilder.Combine(path, "database.db3")}"; + var filePath = Path.Combine(path, "database.db3"); + var connectionString = $"Data Source={filePath}"; - return SetDatabase(connectionString, DbSettings.DatabaseEnum.Sqlite); + //System.IO.File.Create(filePath); + + var result = SetDatabase(connectionString, DbSettings.DatabaseEnum.Sqlite); + + foreach (var file in Directory.GetFiles(path)) + System.IO.File.Delete(file); + + return result; } [HttpPost("SetRedis")]