Ensure the directory exists before creating the SQLite database (#19980)
Ensure the directory exists before creating the SQLite database.
This commit is contained in:
@@ -86,6 +86,7 @@ public class SqliteDatabaseCreator : IDatabaseCreator
|
||||
// Copy our blank(ish) wal mode sqlite database to its final location.
|
||||
try
|
||||
{
|
||||
EnsureDatabaseDirectory(original.DataSource);
|
||||
File.Copy(tempFile, original.DataSource, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -104,4 +105,13 @@ public class SqliteDatabaseCreator : IDatabaseCreator
|
||||
_logger.LogWarning(ex, "Unable to cleanup temporary sqlite database file {path}", tempFile);
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnsureDatabaseDirectory(string dataSource)
|
||||
{
|
||||
var directoryPath = Path.GetDirectoryName(dataSource);
|
||||
if (string.IsNullOrEmpty(directoryPath) is false && Directory.Exists(directoryPath) is false)
|
||||
{
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user