diff options
Diffstat (limited to 'jimfs/src')
4 files changed, 14 insertions, 7 deletions
diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsPath.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsPath.java index 7c6b115..9d18837 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsPath.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsPath.java @@ -251,11 +251,7 @@ final class JimfsPath implements Path { /** Resolves the given name against this path. The name is assumed not to be a root name. */ JimfsPath resolve(Name name) { - if (name.toString().isEmpty()) { - return this; - } - return pathService.createPathInternal( - root, ImmutableList.<Name>builder().addAll(names).add(name).build()); + return resolve(pathService.createFileName(name)); } @Override diff --git a/jimfs/src/main/java/com/google/common/jimfs/PathService.java b/jimfs/src/main/java/com/google/common/jimfs/PathService.java index 49717bd..2bd11a7 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/PathService.java +++ b/jimfs/src/main/java/com/google/common/jimfs/PathService.java @@ -19,7 +19,6 @@ package com.google.common.jimfs; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; -import static com.google.common.jimfs.PathType.ParseResult; import static java.nio.file.LinkOption.NOFOLLOW_LINKS; import com.google.common.annotations.VisibleForTesting; @@ -31,6 +30,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Ordering; +import com.google.common.jimfs.PathType.ParseResult; import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.Files; diff --git a/jimfs/src/test/java/com/google/common/jimfs/DirectoryTest.java b/jimfs/src/test/java/com/google/common/jimfs/DirectoryTest.java index 217509d..1fee1e5 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/DirectoryTest.java +++ b/jimfs/src/test/java/com/google/common/jimfs/DirectoryTest.java @@ -217,7 +217,7 @@ public class DirectoryTest { /* * If we inline this into the assertThat call below, javac resolves it to assertThat(SortedSet), - * which isn't available publicly. Our @GoogleInternal checks consider that to be an error, even + * which isn't available publicly. Our internal build system considers that to be an error, even * though the code will compile fine externally by resolving to assertThat(Iterable) instead. So * we avoid that by assigning to a non-SortedSet type here. */ diff --git a/jimfs/src/test/java/com/google/common/jimfs/JimfsPathTest.java b/jimfs/src/test/java/com/google/common/jimfs/JimfsPathTest.java index da7d43c..5b59081 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/JimfsPathTest.java +++ b/jimfs/src/test/java/com/google/common/jimfs/JimfsPathTest.java @@ -219,6 +219,17 @@ public class JimfsPathTest { } @Test + public void testResolveName_againstEmptyPath() { + // resolve(Name) is only used in the DirectoryStream implementation, so it's only used to + // resolve the names of real existing files against some base directory's path. The base + // directory path could be the working directory path (i.e. just an empty string), in which case + // we need to be sure to return a path that is just the name of the file as opposed a path with + // two names, one being the empty string and the other the file name). + // See https://github.com/google/jimfs/issues/105 + assertPathEquals("foo", pathService.emptyPath().resolve(Name.simple("foo"))); + } + + @Test public void testResolveSibling_givenEmptyPath() { Path path = pathService.parsePath("foo/bar"); Path resolved = path.resolveSibling(""); |