in src/Covi/Services/Storage/LiteDbStorage/StorageService.cs [45:74]
private async Task<LiteDatabase> CreateAsync()
{
var options = await _optionsProvider.GetAsync();
var filePath = GetFilePath();
var connectionString = $"Filename={filePath}";
if (!string.IsNullOrWhiteSpace(options.EncryptionKey))
{
var encryptionKey = options.EncryptionKey;
connectionString += $";Password={encryptionKey}";
}
LiteDatabase database = null;
try
{
database = new LiteDatabase(connectionString);
Interlocked.CompareExchange(ref _database, database, null);
}
catch (Exception ex)
{
// In case of database opening errors, try to remove it and try again
_logger.LogError(ex, "Failed to initialize the databse, trying to replace the file. Reason: " + ex.ToString());
System.IO.File.Delete(filePath);
database = new LiteDatabase(connectionString);
Interlocked.CompareExchange(ref _database, database, null);
}
return database;
}