Skip to content

Commit da7454e

Browse files
authored
Ensure the directory exists before creating the SQLite database (#19980)
Ensure the directory exists before creating the SQLite database.
1 parent b23906a commit da7454e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Umbraco.Cms.Persistence.Sqlite/Services/SqliteDatabaseCreator.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public void Create(string connectionString)
8686
// Copy our blank(ish) wal mode sqlite database to its final location.
8787
try
8888
{
89+
EnsureDatabaseDirectory(original.DataSource);
8990
File.Copy(tempFile, original.DataSource, true);
9091
}
9192
catch (Exception ex)
@@ -104,4 +105,13 @@ public void Create(string connectionString)
104105
_logger.LogWarning(ex, "Unable to cleanup temporary sqlite database file {path}", tempFile);
105106
}
106107
}
108+
109+
private static void EnsureDatabaseDirectory(string dataSource)
110+
{
111+
var directoryPath = Path.GetDirectoryName(dataSource);
112+
if (string.IsNullOrEmpty(directoryPath) is false && Directory.Exists(directoryPath) is false)
113+
{
114+
Directory.CreateDirectory(directoryPath);
115+
}
116+
}
107117
}

0 commit comments

Comments
 (0)