Ensure the directory exists before creating the SQLite database (#19980)

Ensure the directory exists before creating the SQLite database.
This commit is contained in:
Andy Butland
2025-08-26 19:54:19 +02:00
committed by GitHub
parent b23906a6b6
commit da7454e987

View File

@@ -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);
}
}
}