Browse Source

fix macos config folder regression (#1682)

* migrate macos config folder on startup, if needed

* add macos config folder health check

* update macos fix; update changelog
pull/1683/head
Jason Dove 1 year ago committed by GitHub
parent
commit
d78110f6f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      CHANGELOG.md
  2. 8
      ErsatzTV.Core/FileSystemLayout.cs
  3. 5
      ErsatzTV.Core/Health/Checks/IMacOsConfigFolderHealthCheck.cs
  4. 29
      ErsatzTV.Infrastructure/Health/Checks/MacOsConfigFolderHealthCheck.cs
  5. 8
      ErsatzTV.Infrastructure/Health/HealthCheckService.cs
  6. 15
      ErsatzTV/Pages/Index.razor
  7. 49
      ErsatzTV/Startup.cs

6
CHANGELOG.md

@ -22,6 +22,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -22,6 +22,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add `XMLTV Days To Build` setting, which is distinct from the existing `Playout Days To Build` setting
- The value for `XMLTV Days To Build` cannot be larger than `Playout Days To Build`
- This allows, for example, a week of playout data while optimizing XMLTV data to only a day or two
- Add health check to detect config folder issue on MacOS
- ETV versions through v0.8.4-beta (using dotnet 7) stored config data in `$HOME/.local/share/ersatztv`
- ETV versions starting with v0.8.5-beta (using dotnet 8) store config data in `$HOME/Library/Application Support/ersatztv`
- If a dotnet 8 version of ETV has NOT been launched on MacOS, it will automatically migrate the config folder on startup
- If a dotnet 8 version of ETV *has* been launched on MacOS, a failing health check will display with instructions on how to resolve the config issue to restore data
### Fixed
- Fix some cases of 404s from Plex when files were replaced and scanning the library from ETV didn't help
@ -39,6 +44,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -39,6 +44,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- Use ffmpeg 7 in all docker images
- Show health checks at top of home page; scroll release notes if needed
## [0.8.6-beta] - 2024-04-03
### Added

8
ErsatzTV.Core/FileSystemLayout.cs

@ -62,4 +62,12 @@ public static class FileSystemLayout @@ -62,4 +62,12 @@ public static class FileSystemLayout
public static readonly string AudioStreamSelectorScriptsFolder =
Path.Combine(ScriptsFolder, "audio-stream-selector");
public static readonly string MacOsOldAppDataFolder = Path.Combine(
Environment.GetEnvironmentVariable("HOME") ?? string.Empty,
".local",
"share",
"ersatztv");
public static readonly string MacOsOldDatabasePath = Path.Combine(MacOsOldAppDataFolder, "ersatztv.sqlite3");
}

5
ErsatzTV.Core/Health/Checks/IMacOsConfigFolderHealthCheck.cs

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
namespace ErsatzTV.Core.Health.Checks;
public interface IMacOsConfigFolderHealthCheck : IHealthCheck
{
}

29
ErsatzTV.Infrastructure/Health/Checks/MacOsConfigFolderHealthCheck.cs

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
using System.Runtime.InteropServices;
using ErsatzTV.Core;
using ErsatzTV.Core.Health;
using ErsatzTV.Core.Health.Checks;
namespace ErsatzTV.Infrastructure.Health.Checks;
public class MacOsConfigFolderHealthCheck : BaseHealthCheck, IMacOsConfigFolderHealthCheck
{
public override string Title => "MacOS Config Folder";
public Task<HealthCheckResult> Check(CancellationToken cancellationToken)
{
// only applies to macos
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return NotApplicableResult().AsTask();
}
if (Directory.Exists(FileSystemLayout.MacOsOldAppDataFolder))
{
var message =
$"Old config data exists; to migrate: exit ETV, backup the folder {FileSystemLayout.AppDataFolder} to another location, and restart ETV. Otherwise, move the old folder {FileSystemLayout.MacOsOldAppDataFolder} to another location to remove this message";
return FailResult(message).AsTask();
}
return NotApplicableResult().AsTask();
}
}

8
ErsatzTV.Infrastructure/Health/HealthCheckService.cs

@ -10,6 +10,7 @@ public class HealthCheckService : IHealthCheckService @@ -10,6 +10,7 @@ public class HealthCheckService : IHealthCheckService
private readonly ILogger<HealthCheckService> _logger;
public HealthCheckService(
IMacOsConfigFolderHealthCheck macOsConfigFolderHealthCheck,
IFFmpegVersionHealthCheck ffmpegVersionHealthCheck,
IFFmpegReportsHealthCheck ffmpegReportsHealthCheck,
IHardwareAccelerationHealthCheck hardwareAccelerationHealthCheck,
@ -23,8 +24,9 @@ public class HealthCheckService : IHealthCheckService @@ -23,8 +24,9 @@ public class HealthCheckService : IHealthCheckService
ILogger<HealthCheckService> logger)
{
_logger = logger;
_checks = new List<IHealthCheck>
{
_checks =
[
macOsConfigFolderHealthCheck,
ffmpegVersionHealthCheck,
ffmpegReportsHealthCheck,
hardwareAccelerationHealthCheck,
@ -35,7 +37,7 @@ public class HealthCheckService : IHealthCheckService @@ -35,7 +37,7 @@ public class HealthCheckService : IHealthCheckService
unavailableHealthCheck,
vaapiDriverHealthCheck,
errorReportsHealthCheck
};
];
}
public Task<List<HealthCheckResult>> PerformHealthChecks(CancellationToken cancellationToken) =>

15
ErsatzTV/Pages/Index.razor

@ -47,14 +47,7 @@ @@ -47,14 +47,7 @@
}
else
{
<MudCard>
<MudCardContent Class="release-notes mud-typography mud-typography-body1">
<MarkdownView Content="@_releaseNotes"/>
</MudCardContent>
</MudCard>
<MudText Class="mt-6">Full changelog is available on <MudLink Href="https://github.com/ErsatzTV/ErsatzTV/blob/main/CHANGELOG.md">GitHub</MudLink></MudText>
<MudTable Class="mt-6"
Hover="true"
<MudTable Hover="true"
Dense="true"
ServerData="@(new Func<TableState, Task<TableData<HealthCheckResult>>>(ServerReload))"
@ref="_table">
@ -106,6 +99,12 @@ @@ -106,6 +99,12 @@
</MudTd>
</RowTemplate>
</MudTable>
<MudCard Class="mt-6" Style="max-height: 600px; overflow: auto">
<MudCardContent Class="release-notes mud-typography mud-typography-body1">
<MarkdownView Content="@_releaseNotes"/>
</MudCardContent>
</MudCard>
<MudText Class="mt-6">Full changelog is available on <MudLink Href="https://github.com/ErsatzTV/ErsatzTV/blob/main/CHANGELOG.md">GitHub</MudLink></MudText>
}
</MudContainer>

49
ErsatzTV/Startup.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Channels;
using Bugsnag.AspNet.Core;
@ -327,6 +328,8 @@ public class Startup @@ -327,6 +328,8 @@ public class Startup
"https://github.com/ErsatzTV/ErsatzTV",
"https://discord.gg/hHaJm3yGy6");
CopyMacOsConfigFolderIfNeeded();
List<string> directoriesToCreate =
[
FileSystemLayout.AppDataFolder,
@ -599,6 +602,7 @@ public class Startup @@ -599,6 +602,7 @@ public class Startup
AddChannel<ISearchIndexBackgroundServiceRequest>(services);
AddChannel<IScannerBackgroundServiceRequest>(services);
services.AddScoped<IMacOsConfigFolderHealthCheck, MacOsConfigFolderHealthCheck>();
services.AddScoped<IFFmpegVersionHealthCheck, FFmpegVersionHealthCheck>();
services.AddScoped<IFFmpegReportsHealthCheck, FFmpegReportsHealthCheck>();
services.AddScoped<IHardwareAccelerationHealthCheck, HardwareAccelerationHealthCheck>();
@ -716,4 +720,49 @@ public class Startup @@ -716,4 +720,49 @@ public class Startup
services.AddSingleton(
provider => provider.GetRequiredService<Channel<TMessageType>>().Writer);
}
private static void CopyMacOsConfigFolderIfNeeded()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return;
}
bool newDbExists = File.Exists(FileSystemLayout.DatabasePath);
if (newDbExists)
{
return;
}
bool oldDbExists = File.Exists(FileSystemLayout.MacOsOldDatabasePath);
if (!oldDbExists)
{
return;
}
// safe to move here since
// - old db exists
// - new db does not exist
Log.Logger.Information(
"Migrating config data from {OldFolder} to {NewFolder}",
FileSystemLayout.MacOsOldAppDataFolder,
FileSystemLayout.AppDataFolder);
try
{
// delete new config folder
if (Directory.Exists(FileSystemLayout.AppDataFolder))
{
Directory.Delete(FileSystemLayout.AppDataFolder, recursive: true);
}
// move old config folder to new config folder
Directory.Move(FileSystemLayout.MacOsOldAppDataFolder, FileSystemLayout.AppDataFolder);
}
catch (Exception ex)
{
Log.Logger.Warning(ex, "Failed to migrate config data");
}
}
}

Loading…
Cancel
Save