Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Fix GetRelativePath with different volumes #2685

Merged
merged 1 commit into from
Sep 11, 2015
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/Microsoft.Dnx.Runtime/NuGet/Utility/PathUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public static string GetRelativePath(string path1, string path2, char separator)
if (Microsoft.Dnx.Runtime.RuntimeEnvironmentHelper.IsWindows)
{
compare = StringComparison.OrdinalIgnoreCase;
// check if paths are on the same volume
if (!string.Equals(Path.GetPathRoot(path1), Path.GetPathRoot(path2)))
{
// on different volumes, "relative" path is just path2
return path2;
}
}
else
{
Expand Down
5 changes: 4 additions & 1 deletion test/Microsoft.Dnx.Runtime.Tests/PathUtilityFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public static IEnumerable<object[]> FolderPaths
new object[] { "", "C:/folder/app", "C:/folder/app" },
new object[] { "app/", "C:/folder/app", "C:/folder/app/" },
new object[] { "../diff/app/", "C:/folder/app", "C:/diff/app/" },
new object[] { "../folder1/file", "C:\\folder\\file", "C:\\folder1\\file" }
new object[] { "../folder1/file", "C:\\folder\\file", "C:\\folder1\\file" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add?

  1. "C:\\", "C:\\folder1\\file"
  2. C:\\folder1\\file", "C:\\"

new object[] { "H:\\folder\\file", "C:\\folder\\file", "H:\\folder\\file" },
new object[] { "folder/file", "C:\\", "C:\\folder\\file" },
new object[] { "..\\", "C:\\folder\\file", "C:\\" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the result here correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

});
}
else
Expand Down