From ca93156cc5eb5a06ad025dc5ce87c3c49599bd79 Mon Sep 17 00:00:00 2001 From: Kihwal Lee Date: Thu, 19 Sep 2019 08:27:23 -0500 Subject: [PATCH] HADOOP-16582. LocalFileSystem's mkdirs() does not work as expected under viewfs. Contributed by Kihwal Lee (cherry picked from commit d4205dce176287e863f567b333e0d408bf51ae6d) --- .../org/apache/hadoop/fs/FilterFileSystem.java | 4 ++++ .../hadoop/fs/viewfs/ChRootedFileSystem.java | 5 +++++ .../apache/hadoop/fs/viewfs/ViewFileSystem.java | 17 +++++++++++++++-- .../apache/hadoop/fs/TestFilterFileSystem.java | 1 - 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java index 954a041af1f..1c38df86f87 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java @@ -320,6 +320,10 @@ public boolean mkdirs(Path f, FsPermission permission) throws IOException { return fs.mkdirs(f, permission); } + @Override + public boolean mkdirs(Path f) throws IOException { + return fs.mkdirs(f); + } /** * The src file is on the local disk. Add it to FS at 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 5eeff15cdef..3d8f03accea 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 @@ -255,6 +255,11 @@ public boolean mkdirs(final Path f, final FsPermission permission) return super.mkdirs(fullPath(f), permission); } + @Override + public boolean mkdirs(final Path f) throws IOException { + return super.mkdirs(fullPath(f)); + } + @Override public FSDataInputStream open(final Path f, final int bufferSize) throws IOException { diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java index 27d8c0b80da..4c73eaea189 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java @@ -447,12 +447,19 @@ private Path getChrootedPath(InodeTree.ResolveResult res, suffix.length() == 0 ? f : new Path(res.resolvedPath, suffix)); } + @Override + public boolean mkdirs(Path dir) throws IOException { + InodeTree.ResolveResult res = + fsState.resolve(getUriPath(dir), false); + return res.targetFileSystem.mkdirs(res.remainingPath); + } + @Override public boolean mkdirs(final Path dir, final FsPermission permission) throws IOException { InodeTree.ResolveResult res = - fsState.resolve(getUriPath(dir), false); - return res.targetFileSystem.mkdirs(res.remainingPath, permission); + fsState.resolve(getUriPath(dir), false); + return res.targetFileSystem.mkdirs(res.remainingPath, permission); } @Override @@ -943,6 +950,12 @@ public boolean mkdirs(Path dir, FsPermission permission) throw readOnlyMountTable("mkdirs", dir); } + @Override + public boolean mkdirs(Path dir) + throws AccessControlException, FileAlreadyExistsException { + return mkdirs(dir, null); + } + @Override public FSDataInputStream open(Path f, int bufferSize) throws AccessControlException, FileNotFoundException, IOException { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java index c72f579b92d..7c0115e2d6b 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java @@ -77,7 +77,6 @@ public FSDataOutputStream createNonRecursive(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException; - public boolean mkdirs(Path f); public FSDataInputStream open(Path f); public FSDataOutputStream create(Path f); public FSDataOutputStream create(Path f, boolean overwrite);