Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions backend/FwLite/FwLiteWeb/FwLiteWebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static WebApplication SetupAppServer(WebApplicationOptions options, Actio
configure?.Invoke(builder);
var app = builder.Build();
app.Logger.LogInformation("FwLite FwLiteWeb startup");
EnsureDataDirectoriesExist(app);
// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI(o =>
Expand Down Expand Up @@ -134,4 +135,23 @@ public static WebApplication SetupAppServer(WebApplicationOptions options, Actio
.AddAdditionalAssemblies(typeof(FwLiteShared._Imports).Assembly);
return app;
}

/// <summary>
/// Creates the project and auth-cache directories up front, the way the MAUI host already does
/// (see <c>FwLiteMauiKernel</c>). FwLiteWeb never did, which was harmless while the paths defaulted
/// to the working directory (always present), but a host can point <c>LcmCrdt:ProjectPath</c> /
/// <c>Auth:CacheFileName</c> at a per-user location that doesn't exist yet — the Platform.Bible
/// extension does, and it can't create the directory itself. Without this, a missing directory makes
/// project listing (<see cref="Directory.EnumerateFiles(string, string)"/>), project creation
/// (SQLite can't open a file under a missing directory), and MSAL cache init all fail.
/// </summary>
private static void EnsureDataDirectoriesExist(WebApplication app)
{
var projectPath = app.Services.GetRequiredService<IOptions<LcmCrdtConfig>>().Value.ProjectPath;
Directory.CreateDirectory(projectPath);

var cacheFileName = app.Services.GetRequiredService<IOptions<AuthConfig>>().Value.CacheFileName;
var cacheDir = Path.GetDirectoryName(cacheFileName);
if (!string.IsNullOrEmpty(cacheDir)) Directory.CreateDirectory(cacheDir);
}
}
Loading