mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Prevents the theme detection job from crashing the host on file system errors
This commit is contained in:
1 parent
a7e722321c
commit
a09876525b
1 file changed
+40
-26
@@ -72,35 +72,49 @@ internal sealed class ThemeDetectionSyncJob : BackgroundService
|
|||||||
if (knownThemeIds.Contains(manifestResult.Value.Id))
|
if (knownThemeIds.Contains(manifestResult.Value.Id))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
await using FileStream archive = File.OpenRead(archivePath);
|
// installing a bundled theme at startup is best effort: a file system failure here must never crash the host,
|
||||||
Result<ThemeManifestDto> installResult = await _themeService.InstallAsync(archive, stoppingToken);
|
// because the default BackgroundServiceExceptionBehavior (StopHost) shuts down the whole application and
|
||||||
if (installResult.IsFailure)
|
// disposes its service provider, making every later request fail
|
||||||
|
try
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Failed to install bundled theme '{ThemeId}': {Error}", manifestResult.Value.Id, installResult.FirstError.Description);
|
await using FileStream archive = File.OpenRead(archivePath);
|
||||||
continue;
|
Result<ThemeManifestDto> installResult = await _themeService.InstallAsync(archive, stoppingToken);
|
||||||
|
if (installResult.IsFailure)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Failed to install bundled theme '{ThemeId}': {Error}", manifestResult.Value.Id, installResult.FirstError.Description);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ThemeEntity themeEntity = new()
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
ThemeId = manifestResult.Value.Id,
|
||||||
|
Name = manifestResult.Value.Name,
|
||||||
|
Description = manifestResult.Value.Description,
|
||||||
|
Author = manifestResult.Value.Author,
|
||||||
|
Version = manifestResult.Value.Version,
|
||||||
|
PreviewPath = manifestResult.Value.Preview,
|
||||||
|
InstallSource = ThemeInstallSource.Bundled,
|
||||||
|
InstalledAtUtc = DateTime.UtcNow,
|
||||||
|
CreatedOnUtc = DateTime.UtcNow,
|
||||||
|
CreatedBy = default,
|
||||||
|
UpdatedBy = default
|
||||||
|
};
|
||||||
|
|
||||||
|
Result<Created> insertResult = await unitOfWork.ThemeRepository.InsertAsync(themeEntity, stoppingToken);
|
||||||
|
if (insertResult.IsFailure)
|
||||||
|
_logger.LogWarning("Failed to persist the detection of theme '{ThemeId}': {Error}", manifestResult.Value.Id, insertResult.FirstError.Description);
|
||||||
|
else
|
||||||
|
themes.Add(themeEntity);
|
||||||
}
|
}
|
||||||
|
catch (IOException exception)
|
||||||
ThemeEntity themeEntity = new()
|
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
_logger.LogWarning(exception, "Failed to install bundled theme '{ThemeId}': the theme files could not be written.", manifestResult.Value.Id);
|
||||||
ThemeId = manifestResult.Value.Id,
|
}
|
||||||
Name = manifestResult.Value.Name,
|
catch (UnauthorizedAccessException exception)
|
||||||
Description = manifestResult.Value.Description,
|
{
|
||||||
Author = manifestResult.Value.Author,
|
_logger.LogWarning(exception, "Failed to install bundled theme '{ThemeId}': access to the theme files was denied.", manifestResult.Value.Id);
|
||||||
Version = manifestResult.Value.Version,
|
}
|
||||||
PreviewPath = manifestResult.Value.Preview,
|
|
||||||
InstallSource = ThemeInstallSource.Bundled,
|
|
||||||
InstalledAtUtc = DateTime.UtcNow,
|
|
||||||
CreatedOnUtc = DateTime.UtcNow,
|
|
||||||
CreatedBy = default,
|
|
||||||
UpdatedBy = default
|
|
||||||
};
|
|
||||||
|
|
||||||
Result<Created> insertResult = await unitOfWork.ThemeRepository.InsertAsync(themeEntity, stoppingToken);
|
|
||||||
if (insertResult.IsFailure)
|
|
||||||
_logger.LogWarning("Failed to persist the detection of theme '{ThemeId}': {Error}", manifestResult.Value.Id, insertResult.FirstError.Description);
|
|
||||||
else
|
|
||||||
themes.Add(themeEntity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await CleanUpMissingThemePacksAsync(unitOfWork, themes, stoppingToken);
|
await CleanUpMissingThemePacksAsync(unitOfWork, themes, stoppingToken);
|
||||||
|
|||||||
Reference in new issue
Block a user