Skip to content

Commit

Permalink
Merge pull request #3621 from warwickmm/dispose_connection
Browse files Browse the repository at this point in the history
Dispose of Connection after use
  • Loading branch information
Rune Henriksen committed Jan 25, 2019
2 parents 26d36a5 + c79fbf5 commit c1b0611
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Duplicati/Server/WebServer/RESTMethods/Backups.cs
Expand Up @@ -127,21 +127,22 @@ public static Serializable.ImportExportStructure ImportBackup(string configurati
Serializable.ImportExportStructure importedStructure = Backups.LoadConfiguration(configurationFile, importMetadata, getPassword);

// This will create the Duplicati-server.sqlite database file if it doesn't exist.
Duplicati.Server.Database.Connection connection = Program.GetDatabaseConnection(advancedOptions);

if (connection.Backups.Any(x => x.Name.Equals(importedStructure.Backup.Name, StringComparison.OrdinalIgnoreCase)))
using (Duplicati.Server.Database.Connection connection = Program.GetDatabaseConnection(advancedOptions))
{
throw new InvalidOperationException($"A backup with the name {importedStructure.Backup.Name} already exists.");
}
if (connection.Backups.Any(x => x.Name.Equals(importedStructure.Backup.Name, StringComparison.OrdinalIgnoreCase)))
{
throw new InvalidOperationException($"A backup with the name {importedStructure.Backup.Name} already exists.");
}

string error = connection.ValidateBackup(importedStructure.Backup, importedStructure.Schedule);
if (!string.IsNullOrWhiteSpace(error))
{
throw new InvalidOperationException(error);
}
string error = connection.ValidateBackup(importedStructure.Backup, importedStructure.Schedule);
if (!string.IsNullOrWhiteSpace(error))
{
throw new InvalidOperationException(error);
}

// This creates a new ID and DBPath.
connection.AddOrUpdateBackupAndSchedule(importedStructure.Backup, importedStructure.Schedule);
// This creates a new ID and DBPath.
connection.AddOrUpdateBackupAndSchedule(importedStructure.Backup, importedStructure.Schedule);
}

return importedStructure;
}
Expand Down

0 comments on commit c1b0611

Please sign in to comment.