Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Path.GetRelativePath is there in .NET now #961

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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

42 changes: 1 addition & 41 deletions Source/EventFlow/EventStores/Files/FilesEventPersistence.cs
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ public async Task<IReadOnlyCollection<ICommittedDomainEvent>> 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,
};
}

/// <summary>
/// Creates a relative path from one file or folder to another.
/// </summary>
/// <param name="relativeTo">Contains the directory that defines the start of the relative path.</param>
/// <param name="path">Contains the path that defines the endpoint of the relative path.</param>
/// <returns>The relative path from the start directory to the end path or <c>toPath</c> if the paths are not related.</returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="UriFormatException"></exception>
/// <exception cref="InvalidOperationException"></exception>
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
}
}
}