fix: Service URL is now part of cache directory name

pull/201/head
Robert Dailey 1 year ago
parent 5c3da551bb
commit fd216c1b60

@ -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 - Custom Formats: Updates that conflict with existing CFs in Sonarr/Radarr are now skipped and a
warning is printed. 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 ## [4.1.0] - 2022-12-30

@ -45,6 +45,6 @@ public class CacheStoragePathTest : IntegrationFixture
var sut = scope.Resolve<CacheStoragePath>(); var sut = scope.Resolve<CacheStoragePath>();
var result = sut.CalculatePath("obj"); var result = sut.CalculatePath("obj");
result.FullName.Should().MatchRegex(@".*[/\\]thename[/\\]obj\.json$"); result.FullName.Should().MatchRegex(@".*[/\\]thename_[a-f0-9]+[/\\]obj\.json$");
} }
} }

@ -26,16 +26,26 @@ public class CacheStoragePath : ICacheStoragePath
_hash = FNV1aFactory.Instance.Create(FNVConfig.GetPredefinedConfig(32)); _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) public IFileInfo CalculatePath(string cacheObjectName)
{ {
return _paths.CacheDirectory return _paths.CacheDirectory
.SubDirectory(_serviceCommand.Name.ToLower(CultureInfo.CurrentCulture)) .SubDirectory(_serviceCommand.Name.ToLower(CultureInfo.CurrentCulture))
.SubDirectory(_config.Name ?? BuildServiceGuid()) .SubDirectory(BuildUniqueServiceDir(_config.Name))
.File(cacheObjectName + ".json"); .File(cacheObjectName + ".json");
} }
} }

Loading…
Cancel
Save