-
Notifications
You must be signed in to change notification settings - Fork 266
Description
Describe the bug
On windows, when using MockFileSystem().Path.GetRelativePath and the relativeTo path does not have a drive specified, the result is inconsistent depending on what drive you run the code on.
To Reproduce
var fs = new MockFileSystem();
fs.AddDirectory("/dir/subdir");
foreach (var d in fs.Directory.GetDirectories("/dir")) {
Console.WriteLine(d);
var relPath = fs.Path.GetRelativePath("/dir", d);
Console.WriteLine(relPath);
}
If I run this from the c drive (c:\temp\io-test), the output is:
C:\dir\subdir
subdir
But running it from the d drive, results in:
C:\dir\subdir
C:\dir\subdir
Expected behavior
subdir on both c and d drives.
Additional context
PathWrapper.GetRelativePath calls to the System.IO.Path.GetRelativePath which in turn calls to System.IO.Path.GetFullPath (https://github.com/dotnet/runtime/blob/01b7e73cd378145264a7cb7a09365b41ed42b240/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs#L882) which returns D:\dir for /dir.
We use paths without drive letters to make the tests compatible with both linux and windows. Guess the fix would be to implement GetRelativePath in PathWrapper, or to make MockFileSystem use the same root drive as System.IO?