Skip to content

Commit 3c6ad60

Browse files
authoredNov 11, 2022
Merge pull request #961 from eventflow/fix-relative-path
Fix: Path.GetRelativePath is there in .NET now
2 parents acc2317 + 19cb381 commit 3c6ad60

File tree

2 files changed

+2
-41
lines changed

2 files changed

+2
-41
lines changed
 

‎RELEASE_NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Changes since last 1.x pre-release, `1.0.5001-alpha`
2727
vulnerability
2828
- https://github.com/advisories/GHSA-5crp-9r3c-p9vr
2929
- https://security.snyk.io/vuln/SNYK-DOTNET-NEWTONSOFTJSON-2774678
30+
* Fix: `UseFilesEventPersistence` should no longer throw exception for .NET regarding relative paths
3031

3132
Complete 1.0 change log
3233

‎Source/EventFlow/EventStores/Files/FilesEventPersistence.cs

+1-41
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public async Task<IReadOnlyCollection<ICommittedDomainEvent>> CommitEventsAsync(
153153
{
154154
var eventPath = _filesEventLocator.GetEventPath(id, serializedEvent.AggregateSequenceNumber);
155155
_globalSequenceNumber++;
156-
_eventLog[_globalSequenceNumber] = GetRelativePath(_configuration.StorePath, eventPath);
156+
_eventLog[_globalSequenceNumber] = Path.GetRelativePath(_configuration.StorePath, eventPath);
157157

158158
var fileEventData = new FileEventData
159159
{
@@ -278,45 +278,5 @@ private EventStoreLog RecreateEventStoreLog(string path)
278278
Log = directory,
279279
};
280280
}
281-
282-
/// <summary>
283-
/// Creates a relative path from one file or folder to another.
284-
/// </summary>
285-
/// <param name="relativeTo">Contains the directory that defines the start of the relative path.</param>
286-
/// <param name="path">Contains the path that defines the endpoint of the relative path.</param>
287-
/// <returns>The relative path from the start directory to the end path or <c>toPath</c> if the paths are not related.</returns>
288-
/// <exception cref="ArgumentNullException"></exception>
289-
/// <exception cref="UriFormatException"></exception>
290-
/// <exception cref="InvalidOperationException"></exception>
291-
private string GetRelativePath(string relativeTo, string path)
292-
{
293-
#if NETCOREAPP3_1 || NETCOREAPP3_0
294-
return Path.GetRelativePath(relativeTo, path);
295-
#else
296-
if (string.IsNullOrEmpty(relativeTo))
297-
throw new ArgumentNullException(nameof(relativeTo));
298-
if (string.IsNullOrEmpty(path))
299-
throw new ArgumentNullException(nameof(path));
300-
301-
if (relativeTo.Last() != Path.DirectorySeparatorChar && relativeTo.Last() != Path.AltDirectorySeparatorChar)
302-
relativeTo += Path.DirectorySeparatorChar;
303-
304-
var fromUri = new Uri(relativeTo);
305-
var toUri = new Uri(path);
306-
307-
if (fromUri.Scheme != toUri.Scheme)
308-
return path; // path can't be made relative.
309-
310-
var relativeUri = fromUri.MakeRelativeUri(toUri);
311-
var relativePath = Uri.UnescapeDataString(relativeUri.ToString());
312-
313-
if (toUri.Scheme.Equals("file", StringComparison.OrdinalIgnoreCase))
314-
{
315-
relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
316-
}
317-
318-
return relativePath;
319-
#endif
320-
}
321281
}
322282
}

0 commit comments

Comments
 (0)
Please sign in to comment.