From fd216c1b6003fcc3a5abbd7d64ac58bed44ecbe8 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 6 Jan 2023 07:23:18 -0600 Subject: [PATCH] fix: Service URL is now part of cache directory name --- CHANGELOG.md | 1 + .../Command/Helpers/CacheStoragePathTest.cs | 2 +- .../Command/Helpers/CacheStoragePath.cs | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 829ce97a..c3d91670 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Custom Formats: Updates that conflict with existing CFs in Sonarr/Radarr are now skipped and a warning is printed. +- When changing instance URLs, use new cache data to avoid mismatched custom formats on next sync. ## [4.1.0] - 2022-12-30 diff --git a/src/Recyclarr.Cli.Tests/Command/Helpers/CacheStoragePathTest.cs b/src/Recyclarr.Cli.Tests/Command/Helpers/CacheStoragePathTest.cs index 1dd0e02c..78c40748 100644 --- a/src/Recyclarr.Cli.Tests/Command/Helpers/CacheStoragePathTest.cs +++ b/src/Recyclarr.Cli.Tests/Command/Helpers/CacheStoragePathTest.cs @@ -45,6 +45,6 @@ public class CacheStoragePathTest : IntegrationFixture var sut = scope.Resolve(); var result = sut.CalculatePath("obj"); - result.FullName.Should().MatchRegex(@".*[/\\]thename[/\\]obj\.json$"); + result.FullName.Should().MatchRegex(@".*[/\\]thename_[a-f0-9]+[/\\]obj\.json$"); } } diff --git a/src/Recyclarr.Cli/Command/Helpers/CacheStoragePath.cs b/src/Recyclarr.Cli/Command/Helpers/CacheStoragePath.cs index 8873845a..c8230767 100644 --- a/src/Recyclarr.Cli/Command/Helpers/CacheStoragePath.cs +++ b/src/Recyclarr.Cli/Command/Helpers/CacheStoragePath.cs @@ -26,16 +26,26 @@ public class CacheStoragePath : ICacheStoragePath _hash = FNV1aFactory.Instance.Create(FNVConfig.GetPredefinedConfig(32)); } - private string BuildServiceGuid() + private string BuildUniqueServiceDir(string? serviceName) { - return _hash.ComputeHash(Encoding.ASCII.GetBytes(_config.BaseUrl)).AsHexString(); + // In the future, once array-style configurations are removed, the service name will no longer be optional + // and the below condition can be removed and the logic simplified. + var dirName = new StringBuilder(); + if (serviceName is not null) + { + dirName.Append($"{serviceName}_"); + } + + var guid = _hash.ComputeHash(Encoding.ASCII.GetBytes(_config.BaseUrl)).AsHexString(); + dirName.Append(guid); + return dirName.ToString(); } public IFileInfo CalculatePath(string cacheObjectName) { return _paths.CacheDirectory .SubDirectory(_serviceCommand.Name.ToLower(CultureInfo.CurrentCulture)) - .SubDirectory(_config.Name ?? BuildServiceGuid()) + .SubDirectory(BuildUniqueServiceDir(_config.Name)) .File(cacheObjectName + ".json"); } }