// The base FileSystemWatcher does a match check against the relative path before combining with
// the root dir; however, null is special cased to signify the root dir, so check if we should use that.
ReadOnlySpan<char> relativePath = ReadOnlySpan<char>.Empty;
- if (!path.Equals(_fullDirectory, StringComparison.OrdinalIgnoreCase))
+ if (path.Length > _fullDirectory.Length && path.StartsWith(_fullDirectory, StringComparison.OrdinalIgnoreCase))
{
// Remove the root directory to get the relative path
relativePath = path.Slice(_fullDirectory.Length);
{
// Remove the base directory prefix and add the paired event to the list of
// events to skip and notify the user of the rename
- ReadOnlySpan<char> newPathRelativeName = events[pairedId].Span.Slice(_fullDirectory.Length);
+ ReadOnlySpan<char> newPathRelativeName = events[pairedId].Span;
+ if (newPathRelativeName.Length >= _fullDirectory.Length &&
+ newPathRelativeName.StartsWith(_fullDirectory, StringComparison.OrdinalIgnoreCase))
+ {
+ newPathRelativeName = newPathRelativeName.Slice(_fullDirectory.Length);
+ }
watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, newPathRelativeName, relativePath);
// Create a new list, if necessary, and add the event