diff options
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/vfs/Path.java | 4 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/vfs/PathWindowsTest.java | 8 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/Path.java b/src/main/java/com/google/devtools/build/lib/vfs/Path.java index 03eb36d921..c6245b0e65 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/Path.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/Path.java @@ -658,7 +658,9 @@ public class Path implements Comparable<Path>, Serializable { return this; } else if (path.equals("..")) { return parent == null ? this : parent; - } else if ((path.indexOf('/') != -1)) { + } else if (path.indexOf('/') != -1) { + return getRelative(new PathFragment(path)); + } else if (path.indexOf(PathFragment.EXTRA_SEPARATOR_CHAR) != -1) { return getRelative(new PathFragment(path)); } else { return getCachedChildPath(path); diff --git a/src/test/java/com/google/devtools/build/lib/vfs/PathWindowsTest.java b/src/test/java/com/google/devtools/build/lib/vfs/PathWindowsTest.java index 461ce9bc1f..cb8b23b000 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/PathWindowsTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/PathWindowsTest.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.vfs; +import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; @@ -103,6 +104,13 @@ public class PathWindowsTest { assertStartsWithReturnsOnWindows(true, "C:/FIRST/X", "c:/first/x/y"); } + @Test + public void testGetRelative() { + Path root = filesystem.getPath("C:\\first\\x"); + Path other = root.getRelative("a\\b\\c"); + assertThat(other.asFragment().getPathString()).isEqualTo("C:/first/x/a/b/c"); + } + private void assertStartsWithReturnsOnWindows(boolean expected, String ancestor, String descendant) { |