fix(migrate): Skip moving cache directory if it does not exist

pull/76/head
Robert Dailey 2 years ago
parent bf8b860951
commit 7daca894f7

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- `create-config` would fail with `--path` specified.
- `migrate` no longer fails if the `cache` directory does not exist.
## [2.1.1] - 2022-05-29

@ -1,6 +1,7 @@
using System.IO.Abstractions.TestingHelpers;
using AutoFixture.NUnit3;
using FluentAssertions;
using NSubstitute;
using NUnit.Framework;
using Recyclarr.Migration.Steps;
using TestLibrary;
@ -12,8 +13,6 @@ namespace Recyclarr.Tests.Migration.Steps;
[Parallelizable(ParallelScope.All)]
public class MigrateTrashUpdaterAppDataDirTest
{
private const string BasePath = "base_path";
[Test, AutoMockData]
public void Migration_check_returns_true_if_trash_updater_dir_exists(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
@ -33,12 +32,13 @@ public class MigrateTrashUpdaterAppDataDirTest
}
[Test, AutoMockData]
public void Migration_throws_if_recyclarr_dir_already_exists(
public void Migration_throws_if_recyclarr_yml_already_exists(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
[Frozen(Matching.ImplementedInterfaces)] TestAppPaths paths,
MigrateTrashUpdaterAppDataDir sut)
{
fs.AddDirectory(Path.Combine(BasePath, "trash-updater"));
fs.AddDirectory(Path.Combine(BasePath, "recyclarr"));
fs.AddFileNoData($"{paths.BasePath}/trash-updater/recyclarr.yml");
fs.AddFileNoData($"{paths.BasePath}/recyclarr/recyclarr.yml");
var act = () => sut.Execute(null);
@ -67,4 +67,15 @@ public class MigrateTrashUpdaterAppDataDirTest
FileUtils.NormalizePath($"/{paths.BasePath}/recyclarr/recyclarr.yml"),
FileUtils.NormalizePath($"/{paths.BasePath}/recyclarr/cache/sonarr/test.txt"));
}
[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();
}
}

@ -44,15 +44,27 @@ public class MigrateTrashUpdaterAppDataDir : IMigrationStep
public void Execute(IConsole? console)
{
_fs.MergeDirectory(
_fs.Path.Combine(GetOldPath(), "cache"),
_fs.Path.Combine(GetNewPath(), "cache"),
console);
MoveDirectory("cache", console);
MoveFile("recyclarr.yml");
MoveFile("settings.yml");
_fs.Directory.Delete(GetOldPath(), true);
var oldDir = _fs.DirectoryInfo.FromDirectoryName(GetOldPath());
if (oldDir.Exists)
{
oldDir.Delete(true);
}
}
private void MoveDirectory(string directory, IConsole? console)
{
var oldPath = _fs.Path.Combine(GetOldPath(), directory);
if (_fs.Directory.Exists(oldPath))
{
_fs.MergeDirectory(
oldPath,
_fs.Path.Combine(GetNewPath(), directory),
console);
}
}
private void MoveFile(string file)

Loading…
Cancel
Save