From 19cb381c6b36d3e174da7ecba977112716794f91 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Fri, 11 Nov 2022 11:05:28 +0100 Subject: [PATCH] Fix: Path.GetRelativePath is there in .NET now --- RELEASE_NOTES.md | 1 + .../Files/FilesEventPersistence.cs | 42 +------------------ 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 62b2cb051..8410a82fc 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -18,6 +18,7 @@ Changes since 1.0.5001-alpha vulnerability - https://github.com/advisories/GHSA-5crp-9r3c-p9vr - https://security.snyk.io/vuln/SNYK-DOTNET-NEWTONSOFTJSON-2774678 +* Fix: `UseFilesEventPersistence` should no longer throw exception for .NET regarding relative paths Complete 1.0 change log diff --git a/Source/EventFlow/EventStores/Files/FilesEventPersistence.cs b/Source/EventFlow/EventStores/Files/FilesEventPersistence.cs index e0d49dae2..27b6dfc02 100644 --- a/Source/EventFlow/EventStores/Files/FilesEventPersistence.cs +++ b/Source/EventFlow/EventStores/Files/FilesEventPersistence.cs @@ -153,7 +153,7 @@ public async Task> CommitEventsAsync( { var eventPath = _filesEventLocator.GetEventPath(id, serializedEvent.AggregateSequenceNumber); _globalSequenceNumber++; - _eventLog[_globalSequenceNumber] = GetRelativePath(_configuration.StorePath, eventPath); + _eventLog[_globalSequenceNumber] = Path.GetRelativePath(_configuration.StorePath, eventPath); var fileEventData = new FileEventData { @@ -278,45 +278,5 @@ private EventStoreLog RecreateEventStoreLog(string path) Log = directory, }; } - - /// - /// Creates a relative path from one file or folder to another. - /// - /// Contains the directory that defines the start of the relative path. - /// Contains the path that defines the endpoint of the relative path. - /// The relative path from the start directory to the end path or toPath if the paths are not related. - /// - /// - /// - private string GetRelativePath(string relativeTo, string path) - { -#if NETCOREAPP3_1 || NETCOREAPP3_0 - return Path.GetRelativePath(relativeTo, path); -#else - if (string.IsNullOrEmpty(relativeTo)) - throw new ArgumentNullException(nameof(relativeTo)); - if (string.IsNullOrEmpty(path)) - throw new ArgumentNullException(nameof(path)); - - if (relativeTo.Last() != Path.DirectorySeparatorChar && relativeTo.Last() != Path.AltDirectorySeparatorChar) - relativeTo += Path.DirectorySeparatorChar; - - var fromUri = new Uri(relativeTo); - var toUri = new Uri(path); - - if (fromUri.Scheme != toUri.Scheme) - return path; // path can't be made relative. - - var relativeUri = fromUri.MakeRelativeUri(toUri); - var relativePath = Uri.UnescapeDataString(relativeUri.ToString()); - - if (toUri.Scheme.Equals("file", StringComparison.OrdinalIgnoreCase)) - { - relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); - } - - return relativePath; -#endif - } } } \ No newline at end of file