diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 65a44bbc919..22a17ed8172 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -307,6 +307,9 @@ Release 2.0.3-alpha - Unreleased HADOOP-8791. Fix rm command documentation to indicte it deletes files and not directories. (Jing Zhao via suresh) + HADOOP-8616. ViewFS configuration requires a trailing slash. (Sandy Ryza + via atm) + Release 2.0.2-alpha - 2012-09-07 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java index 95d0a2d456a..b3acf506f6a 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java @@ -89,7 +89,11 @@ class ChRootedFileSystem extends FilterFileSystem { public ChRootedFileSystem(final URI uri, Configuration conf) throws IOException { super(FileSystem.get(uri, conf)); - chRootPathPart = new Path(uri.getPath()); + String pathString = uri.getPath(); + if (pathString.isEmpty()) { + pathString = "/"; + } + chRootPathPart = new Path(pathString); chRootPathPartString = chRootPathPart.toUri().getPath(); myUri = uri; workingDir = getHomeDirectory(); diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java index 130ff976f16..a8a77bec5d0 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java @@ -205,9 +205,13 @@ public class ViewFs extends AbstractFileSystem { protected AbstractFileSystem getTargetFileSystem(final URI uri) throws URISyntaxException, UnsupportedFileSystemException { + String pathString = uri.getPath(); + if (pathString.isEmpty()) { + pathString = "/"; + } return new ChRootedFs( AbstractFileSystem.createFileSystem(uri, config), - new Path(uri.getPath())); + new Path(pathString)); } @Override diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestChRootedFileSystem.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestChRootedFileSystem.java index e990b92465f..35e2cb7649c 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestChRootedFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestChRootedFileSystem.java @@ -342,6 +342,15 @@ public class TestChRootedFileSystem { chrootFs.close(); verify(mockFs).delete(eq(rawPath), eq(true)); } + + @Test + public void testURIEmptyPath() throws IOException { + Configuration conf = new Configuration(); + conf.setClass("fs.mockfs.impl", MockFileSystem.class, FileSystem.class); + + URI chrootUri = URI.create("mockfs://foo"); + new ChRootedFileSystem(chrootUri, conf); + } static class MockFileSystem extends FilterFileSystem { MockFileSystem() {