From 56098533214f8b2d9553e7b24f6b5b9c5d33e782 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sun, 30 Apr 2023 21:38:48 -0500 Subject: [PATCH] feat!: Remove old migration steps The following migration steps were removed: - `MigrateTrashUpdaterAppDataDir` - `MigrateTrashYml` --- CHANGELOG.md | 1 + .../Migration/MigrationExecutorTest.cs | 15 ---- .../MigrateTrashUpdaterAppDataDirTest.cs | 78 ----------------- .../Migration/Steps/MigrateTrashYmlTest.cs | 57 ------------ .../Migration/MigrationAutofacModule.cs | 4 +- .../Steps/MigrateTrashUpdaterAppDataDir.cs | 87 ------------------- .../Migration/Steps/MigrateTrashYml.cs | 46 ---------- src/Recyclarr.Cli/Recyclarr.Cli.csproj | 4 + 8 files changed, 6 insertions(+), 286 deletions(-) delete mode 100644 src/Recyclarr.Cli.Tests/Migration/Steps/MigrateTrashUpdaterAppDataDirTest.cs delete mode 100644 src/Recyclarr.Cli.Tests/Migration/Steps/MigrateTrashYmlTest.cs delete mode 100644 src/Recyclarr.Cli/Migration/Steps/MigrateTrashUpdaterAppDataDir.cs delete mode 100644 src/Recyclarr.Cli/Migration/Steps/MigrateTrashYml.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a04f0d1..30551533 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ changes you may need to make. - **BREAKING**: Array-style instances are no longer supported. - **BREAKING**: Remove deprecated CLI commands: `radarr`, `sonarr`, and `create-config`. - **BREAKING**: Removed `reset_unmatched_scores` support under quality profile score section. +- **BREAKING**: Migration steps that dealt with the old `trash.yml` have been removed. ## [4.4.1] - 2023-04-08 diff --git a/src/Recyclarr.Cli.Tests/Migration/MigrationExecutorTest.cs b/src/Recyclarr.Cli.Tests/Migration/MigrationExecutorTest.cs index f9b17766..b3257260 100644 --- a/src/Recyclarr.Cli.Tests/Migration/MigrationExecutorTest.cs +++ b/src/Recyclarr.Cli.Tests/Migration/MigrationExecutorTest.cs @@ -1,5 +1,4 @@ using Recyclarr.Cli.Migration; -using Recyclarr.Cli.Migration.Steps; using Recyclarr.Cli.TestLibrary; using Spectre.Console.Testing; @@ -9,20 +8,6 @@ namespace Recyclarr.Cli.Tests.Migration; [Parallelizable(ParallelScope.All)] public class MigrationExecutorTest : CliIntegrationFixture { - [Test] - public void Migration_steps_are_in_expected_order() - { - var steps = Resolve>(); - var orderedSteps = steps.OrderBy(x => x.Order).Select(x => x.GetType()).ToList(); - orderedSteps.Should().BeEquivalentTo( - new[] - { - typeof(MigrateTrashYml), - typeof(MigrateTrashUpdaterAppDataDir) - }, - config => config.WithStrictOrdering()); - } - [Test] public void Step_not_executed_if_check_returns_false() { diff --git a/src/Recyclarr.Cli.Tests/Migration/Steps/MigrateTrashUpdaterAppDataDirTest.cs b/src/Recyclarr.Cli.Tests/Migration/Steps/MigrateTrashUpdaterAppDataDirTest.cs deleted file mode 100644 index 851085bd..00000000 --- a/src/Recyclarr.Cli.Tests/Migration/Steps/MigrateTrashUpdaterAppDataDirTest.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.IO.Abstractions; -using Recyclarr.Cli.Migration.Steps; -using Recyclarr.TestLibrary.AutoFixture; -using Recyclarr.TrashLib.TestLibrary; - -namespace Recyclarr.Cli.Tests.Migration.Steps; - -[TestFixture] -[Parallelizable(ParallelScope.All)] -public class MigrateTrashUpdaterAppDataDirTest -{ - [Test, AutoMockData] - public void Migration_check_returns_true_if_trash_updater_dir_exists( - [Frozen(Matching.ImplementedInterfaces)] TestAppPaths paths, - MigrateTrashUpdaterAppDataDir sut) - { - paths.AppDataDirectory.Parent.SubDirectory("trash-updater").Create(); - sut.CheckIfNeeded().Should().BeTrue(); - } - - [Test, AutoMockData] - public void Migration_check_returns_false_if_trash_updater_dir_doesnt_exists( - MigrateTrashUpdaterAppDataDir sut) - { - sut.CheckIfNeeded().Should().BeFalse(); - } - - [Test, AutoMockData] - public void Migration_throws_if_recyclarr_yml_already_exists( - [Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs, - [Frozen(Matching.ImplementedInterfaces)] TestAppPaths paths, - MigrateTrashUpdaterAppDataDir sut) - { - fs.AddEmptyFile(sut.OldPath.File("recyclarr.yml")); - fs.AddEmptyFile(sut.NewPath.File("recyclarr.yml")); - - var act = () => sut.Execute(null); - - act.Should().Throw(); - } - - [Test, AutoMockData] - public void Migration_success( - [Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs, - [Frozen(Matching.ImplementedInterfaces)] TestAppPaths paths, - MigrateTrashUpdaterAppDataDir sut) - { - // Add file instead of directory since the migration step only operates on files - var baseDir = sut.OldPath; - fs.AddEmptyFile(baseDir.File("settings.yml")); - fs.AddEmptyFile(baseDir.File("recyclarr.yml")); - fs.AddEmptyFile(baseDir.File("this-gets-ignored.yml")); - fs.AddDirectory(baseDir.SubDirectory("repo")); - fs.AddDirectory(baseDir.SubDirectory("cache")); - fs.AddEmptyFile(baseDir.File("cache/sonarr/test.txt")); - - sut.Execute(null); - - var expectedBase = sut.NewPath; - - fs.AllDirectories.Should().NotContain(x => x.Contains("trash-updater")); - fs.AllFiles.Should().BeEquivalentTo( - expectedBase.File("settings.yml").FullName, - expectedBase.File("recyclarr.yml").FullName, - expectedBase.SubDirectory("cache").SubDirectory("sonarr").File("test.txt").FullName); - } - - [Test, AutoMockData] - public void No_exception_if_source_files_do_not_exist( - [Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs, - [Frozen(Matching.ImplementedInterfaces)] TestAppPaths paths, - MigrateTrashUpdaterAppDataDir sut) - { - var act = () => sut.Execute(null); - - act.Should().NotThrow(); - } -} diff --git a/src/Recyclarr.Cli.Tests/Migration/Steps/MigrateTrashYmlTest.cs b/src/Recyclarr.Cli.Tests/Migration/Steps/MigrateTrashYmlTest.cs deleted file mode 100644 index 708c4a07..00000000 --- a/src/Recyclarr.Cli.Tests/Migration/Steps/MigrateTrashYmlTest.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Text.RegularExpressions; -using Recyclarr.Cli.Migration.Steps; -using Recyclarr.TestLibrary.AutoFixture; - -namespace Recyclarr.Cli.Tests.Migration.Steps; - -[TestFixture] -[Parallelizable(ParallelScope.All)] -public partial class MigrateTrashYmlTest -{ - private static readonly string BasePath = AppContext.BaseDirectory; - - [Test, AutoMockData] - public void Migration_check_returns_true_if_trash_yml_exists( - [Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs, - MigrateTrashYml sut) - { - fs.AddFile(Path.Combine(BasePath, "trash.yml"), new MockFileData("")); - sut.CheckIfNeeded().Should().BeTrue(); - } - - [Test, AutoMockData] - public void Migration_check_returns_false_if_trash_yml_doesnt_exists( - [Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs, - MigrateTrashYml sut) - { - sut.CheckIfNeeded().Should().BeFalse(); - } - - [Test, AutoMockData] - public void Migration_throws_if_recyclarr_yml_already_exists( - [Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs, - MigrateTrashYml sut) - { - fs.AddFile(Path.Combine(BasePath, "recyclarr.yml"), new MockFileData("")); - - var act = () => sut.Execute(null); - - act.Should().Throw(); - } - - [Test, AutoMockData] - public void Migration_success( - [Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs, - MigrateTrashYml sut) - { - const string expectedData = "fake contents"; - fs.AddFile(Path.Combine(BasePath, "trash.yml"), expectedData); - - sut.Execute(null); - - fs.AllFiles.Should().ContainSingle(x => RecyclarrYmlRegex().IsMatch(x)); - } - - [GeneratedRegex("[/\\\\]recyclarr\\.yml$", RegexOptions.None, 1000)] - private static partial Regex RecyclarrYmlRegex(); -} diff --git a/src/Recyclarr.Cli/Migration/MigrationAutofacModule.cs b/src/Recyclarr.Cli/Migration/MigrationAutofacModule.cs index 3bbf7726..13835437 100644 --- a/src/Recyclarr.Cli/Migration/MigrationAutofacModule.cs +++ b/src/Recyclarr.Cli/Migration/MigrationAutofacModule.cs @@ -1,5 +1,4 @@ using Autofac; -using Recyclarr.Cli.Migration.Steps; namespace Recyclarr.Cli.Migration; @@ -13,8 +12,7 @@ public class MigrationAutofacModule : Module // Migration Steps builder.RegisterTypes ( - typeof(MigrateTrashYml), - typeof(MigrateTrashUpdaterAppDataDir) + // Add migration steps here in order of execution ) .As(); } diff --git a/src/Recyclarr.Cli/Migration/Steps/MigrateTrashUpdaterAppDataDir.cs b/src/Recyclarr.Cli/Migration/Steps/MigrateTrashUpdaterAppDataDir.cs deleted file mode 100644 index 35dd4cda..00000000 --- a/src/Recyclarr.Cli/Migration/Steps/MigrateTrashUpdaterAppDataDir.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System.IO.Abstractions; -using JetBrains.Annotations; -using Recyclarr.Common.Extensions; -using Recyclarr.TrashLib.Startup; -using Spectre.Console; - -namespace Recyclarr.Cli.Migration.Steps; - -/// -/// Implemented on 4/30/2022. -/// -[UsedImplicitly] -public class MigrateTrashUpdaterAppDataDir : IMigrationStep -{ - private readonly IFileSystem _fs; - private readonly IAppPaths _paths; - - public int Order => 20; - public bool Required => true; - - public string Description - => $"Merge files from old app data directory `{OldPath}` into `{NewPath}` and delete old directory"; - - public IReadOnlyCollection Remediation => new[] - { - $"Check if `{NewPath}` already exists. If so, manually copy all files from `{OldPath}` and delete it to fix the error.", - $"Ensure Recyclarr has permission to recursively delete {OldPath}", - $"Ensure Recyclarr has permission to create and move files into {NewPath}" - }; - - public MigrateTrashUpdaterAppDataDir(IFileSystem fs, IAppPaths paths) - { - _fs = fs; - _paths = paths; - } - - public IDirectoryInfo NewPath - { - get - { - // Will be something like `/home/user/.config/recyclarr`. - var path = _paths.AppDataDirectory; - path.Refresh(); - return path; - } - } - - public IDirectoryInfo OldPath => NewPath.Parent.SubDirectory("trash-updater"); - - public bool CheckIfNeeded() - { - return OldPath.Exists; - } - - public void Execute(IAnsiConsole? console) - { - MoveDirectory("cache", console); - MoveFile("recyclarr.yml"); - MoveFile("settings.yml"); - - if (OldPath.Exists) - { - OldPath.Delete(true); - } - } - - private void MoveDirectory(string directory, IAnsiConsole? console) - { - var oldPath = OldPath.SubDirectory(directory); - if (oldPath.Exists) - { - _fs.MergeDirectory( - oldPath, - NewPath.SubDirectory(directory), - console); - } - } - - private void MoveFile(string file) - { - var recyclarrYaml = OldPath.File(file); - if (recyclarrYaml.Exists) - { - recyclarrYaml.MoveTo(NewPath.File(file).FullName); - } - } -} diff --git a/src/Recyclarr.Cli/Migration/Steps/MigrateTrashYml.cs b/src/Recyclarr.Cli/Migration/Steps/MigrateTrashYml.cs deleted file mode 100644 index 845153b1..00000000 --- a/src/Recyclarr.Cli/Migration/Steps/MigrateTrashYml.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.IO.Abstractions; -using JetBrains.Annotations; -using Spectre.Console; - -namespace Recyclarr.Cli.Migration.Steps; - -/// -/// Implemented on 4/30/2022. -/// -[UsedImplicitly] -public class MigrateTrashYml : IMigrationStep -{ - private readonly IFileSystem _fileSystem; - private readonly string _oldConfigPath = Path.Combine(AppContext.BaseDirectory, "trash.yml"); - - // Do not use AppPaths class here since that may change yet again in the future and break this migration step. - private readonly string _newConfigPath = Path.Combine(AppContext.BaseDirectory, "recyclarr.yml"); - - public int Order => 10; - public string Description { get; } - public IReadOnlyCollection Remediation { get; } - public bool Required => true; - - public MigrateTrashYml(IFileSystem fileSystem) - { - _fileSystem = fileSystem; - Remediation = new[] - { - $"Check if `{_newConfigPath}` already exists. If so, manually copy the data you want and then delete `{_oldConfigPath}` to fix the error.", - $"Ensure Recyclarr has permission to delete {_oldConfigPath}", - $"Ensure Recyclarr has permission to create {_newConfigPath}" - }; - - Description = $"Rename default YAML config from `{_oldConfigPath}` to `{_newConfigPath}`"; - } - - public bool CheckIfNeeded() - { - return _fileSystem.File.Exists(_oldConfigPath); - } - - public void Execute(IAnsiConsole? console) - { - _fileSystem.File.Move(_oldConfigPath, _newConfigPath); - } -} diff --git a/src/Recyclarr.Cli/Recyclarr.Cli.csproj b/src/Recyclarr.Cli/Recyclarr.Cli.csproj index 43d28082..fb5a6c83 100644 --- a/src/Recyclarr.Cli/Recyclarr.Cli.csproj +++ b/src/Recyclarr.Cli/Recyclarr.Cli.csproj @@ -37,4 +37,8 @@ + + + +