fix: Simplify app data migration

Due to the failures related to symlinks in the repo directory that
happened when doing a full directory merge, the migration logic has been
simplified. It now only copies useful YAML files and cache data. The
repo directory is ignored and will need to be re-cloned when the user
runs `recyclarr` next time.
pull/76/head
Robert Dailey 2 years ago
parent da38fd597f
commit cd9d9e7cdc

@ -4,6 +4,7 @@ using AutoFixture.NUnit3;
using FluentAssertions;
using NUnit.Framework;
using Recyclarr.Migration.Steps;
using TestLibrary;
using TestLibrary.AutoFixture;
namespace Recyclarr.Tests.Migration.Steps;
@ -52,11 +53,19 @@ public class MigrateTrashUpdaterAppDataDirTest
MigrateTrashUpdaterAppDataDir sut)
{
// Add file instead of directory since the migration step only operates on files
fs.AddFile(fs.Path.Combine(paths.BasePath, "trash-updater", "1", "2", "test.txt"), new MockFileData(""));
fs.AddFileNoData($"{paths.BasePath}/trash-updater/settings.yml");
fs.AddFileNoData($"{paths.BasePath}/trash-updater/recyclarr.yml");
fs.AddFileNoData($"{paths.BasePath}/trash-updater/this-gets-ignored.yml");
fs.AddDirectory2($"{paths.BasePath}/trash-updater/repo");
fs.AddDirectory2($"{paths.BasePath}/trash-updater/cache");
fs.AddFileNoData($"{paths.BasePath}/trash-updater/cache/sonarr/test.txt");
sut.Execute(null);
fs.AllDirectories.Should().NotContain(x => x.Contains("trash-updater"));
fs.AllFiles.Should().Contain(x => Regex.IsMatch(x, @"[/\\]recyclarr[/\\]1[/\\]2[/\\]test.txt$"));
fs.AllFiles.Should().BeEquivalentTo(
FileUtils.NormalizePath($"/{paths.BasePath}/recyclarr/settings.yml"),
FileUtils.NormalizePath($"/{paths.BasePath}/recyclarr/recyclarr.yml"),
FileUtils.NormalizePath($"/{paths.BasePath}/recyclarr/cache/sonarr/test.txt"));
}
}

@ -42,5 +42,25 @@ public class MigrateTrashUpdaterAppDataDir : IMigrationStep
public bool CheckIfNeeded() => _fs.Directory.Exists(GetOldPath());
public void Execute(IConsole? console) => _fs.MergeDirectory(GetOldPath(), GetNewPath(), console);
public void Execute(IConsole? console)
{
_fs.MergeDirectory(
_fs.Path.Combine(GetOldPath(), "cache"),
_fs.Path.Combine(GetNewPath(), "cache"),
console);
MoveFile("recyclarr.yml");
MoveFile("settings.yml");
_fs.Directory.Delete(GetOldPath(), true);
}
private void MoveFile(string file)
{
var recyclarrYaml = _fs.FileInfo.FromFileName(_fs.Path.Combine(GetOldPath(), file));
if (recyclarrYaml.Exists)
{
recyclarrYaml.MoveTo(_fs.Path.Combine(GetNewPath(), file));
}
}
}

Loading…
Cancel
Save