aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Server/Program.cs')
-rw-r--r--Jellyfin.Server/Program.cs27
1 files changed, 17 insertions, 10 deletions
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs
index f40526e22..ce11c63f9 100644
--- a/Jellyfin.Server/Program.cs
+++ b/Jellyfin.Server/Program.cs
@@ -224,12 +224,16 @@ namespace Jellyfin.Server
}
finally
{
- _logger.LogInformation("Running query planner optimizations in the database... This might take a while");
- // Run before disposing the application
- using var context = appHost.Resolve<JellyfinDbProvider>().CreateContext();
- if (context.Database.IsSqlite())
+ // Don't throw additional exception if startup failed.
+ if (appHost.ServiceProvider != null)
{
- context.Database.ExecuteSqlRaw("PRAGMA optimize");
+ _logger.LogInformation("Running query planner optimizations in the database... This might take a while");
+ // Run before disposing the application
+ using var context = appHost.Resolve<JellyfinDbProvider>().CreateContext();
+ if (context.Database.IsSqlite())
+ {
+ context.Database.ExecuteSqlRaw("PRAGMA optimize");
+ }
}
appHost.Dispose();
@@ -545,12 +549,15 @@ namespace Jellyfin.Server
// Get a stream of the resource contents
// NOTE: The .csproj name is used instead of the assembly name in the resource path
const string ResourcePath = "Jellyfin.Server.Resources.Configuration.logging.json";
- await using Stream resource = typeof(Program).Assembly.GetManifestResourceStream(ResourcePath)
+ Stream resource = typeof(Program).Assembly.GetManifestResourceStream(ResourcePath)
?? throw new InvalidOperationException($"Invalid resource path: '{ResourcePath}'");
-
- // Copy the resource contents to the expected file path for the config file
- await using Stream dst = new FileStream(configPath, FileMode.CreateNew, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous);
- await resource.CopyToAsync(dst).ConfigureAwait(false);
+ Stream dst = new FileStream(configPath, FileMode.CreateNew, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous);
+ await using (resource.ConfigureAwait(false))
+ await using (dst.ConfigureAwait(false))
+ {
+ // Copy the resource contents to the expected file path for the config file
+ await resource.CopyToAsync(dst).ConfigureAwait(false);
+ }
}
/// <summary>