diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 4286f8a8f8e..3864cbe90bf 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -127,6 +127,9 @@ Release 2.4.0 - UNRELEASED HADOOP-10407. Fix the javac warnings in org.apache.hadoop.ipc package. (szetszwo) + HADOOP-10191. Missing executable permission on viewfs internal dirs. + (Gera Shegalov via cnauroth) + BREAKDOWN OF HADOOP-10184 SUBTASKS AND RELATED JIRAS HADOOP-10185. FileSystem API for ACLs. (cnauroth) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/Constants.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/Constants.java index 0f862180ec5..ec8ab2b7fc7 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/Constants.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/Constants.java @@ -64,6 +64,6 @@ public interface Constants { */ public static final String CONFIG_VIEWFS_LINK_MERGE_SLASH = "linkMergeSlash"; - static public final FsPermission PERMISSION_RRR = - new FsPermission((short) 0444); + static public final FsPermission PERMISSION_555 = + new FsPermission((short) 0555); } 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 ac2664effdb..c95cb54a405 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 @@ -17,7 +17,7 @@ */ package org.apache.hadoop.fs.viewfs; -import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_RRR; +import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_555; import java.io.FileNotFoundException; import java.io.IOException; @@ -714,7 +714,7 @@ public FileChecksum getFileChecksum(final Path f) public FileStatus getFileStatus(Path f) throws IOException { checkPathIsSlash(f); return new FileStatus(0, true, 0, 0, creationTime, creationTime, - PERMISSION_RRR, ugi.getUserName(), ugi.getGroupNames()[0], + PERMISSION_555, ugi.getUserName(), ugi.getGroupNames()[0], new Path(theInternalDir.fullPath).makeQualified( myUri, ROOT_PATH)); @@ -734,14 +734,14 @@ public FileStatus[] listStatus(Path f) throws AccessControlException, INodeLink link = (INodeLink) inode; result[i++] = new FileStatus(0, false, 0, 0, - creationTime, creationTime, PERMISSION_RRR, + creationTime, creationTime, PERMISSION_555, ugi.getUserName(), ugi.getGroupNames()[0], link.getTargetLink(), new Path(inode.fullPath).makeQualified( myUri, null)); } else { result[i++] = new FileStatus(0, true, 0, 0, - creationTime, creationTime, PERMISSION_RRR, + creationTime, creationTime, PERMISSION_555, ugi.getUserName(), ugi.getGroupNames()[0], new Path(inode.fullPath).makeQualified( myUri, null)); 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 2bbdc164f87..f2a433b95f8 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 @@ -17,7 +17,7 @@ */ package org.apache.hadoop.fs.viewfs; -import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_RRR; +import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_555; import java.io.FileNotFoundException; import java.io.IOException; @@ -676,8 +676,8 @@ public FileChecksum getFileChecksum(final Path f) @Override public FileStatus getFileStatus(final Path f) throws IOException { checkPathIsSlash(f); - return new FileStatus(0, true, 0, 0, creationTime, creationTime, - PERMISSION_RRR, ugi.getUserName(), ugi.getGroupNames()[0], + return new FileStatus(0, true, 0, 0, creationTime, creationTime, + PERMISSION_555, ugi.getUserName(), ugi.getGroupNames()[0], new Path(theInternalDir.fullPath).makeQualified( myUri, null)); } @@ -697,13 +697,13 @@ public FileStatus getFileLinkStatus(final Path f) INodeLink inodelink = (INodeLink) inode; result = new FileStatus(0, false, 0, 0, creationTime, creationTime, - PERMISSION_RRR, ugi.getUserName(), ugi.getGroupNames()[0], + PERMISSION_555, ugi.getUserName(), ugi.getGroupNames()[0], inodelink.getTargetLink(), new Path(inode.fullPath).makeQualified( myUri, null)); } else { result = new FileStatus(0, true, 0, 0, creationTime, creationTime, - PERMISSION_RRR, ugi.getUserName(), ugi.getGroupNames()[0], + PERMISSION_555, ugi.getUserName(), ugi.getGroupNames()[0], new Path(inode.fullPath).makeQualified( myUri, null)); } @@ -742,14 +742,14 @@ public FileStatus[] listStatus(final Path f) throws AccessControlException, result[i++] = new FileStatus(0, false, 0, 0, creationTime, creationTime, - PERMISSION_RRR, ugi.getUserName(), ugi.getGroupNames()[0], + PERMISSION_555, ugi.getUserName(), ugi.getGroupNames()[0], link.getTargetLink(), new Path(inode.fullPath).makeQualified( myUri, null)); } else { result[i++] = new FileStatus(0, true, 0, 0, creationTime, creationTime, - PERMISSION_RRR, ugi.getUserName(), ugi.getGroupNames()[0], + PERMISSION_555, ugi.getUserName(), ugi.getGroupNames()[0], new Path(inode.fullPath).makeQualified( myUri, null)); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java index e5fcef7e4de..2d3cb270f11 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java @@ -31,6 +31,8 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FsConstants; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.permission.FsAction; +import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.viewfs.ConfigUtil; import org.apache.hadoop.fs.viewfs.ViewFileSystem; import org.apache.hadoop.fs.viewfs.ViewFileSystem.MountPoint; @@ -401,38 +403,41 @@ public void testListOnInternalDirsOfMountTable() throws IOException { FileStatus[] dirPaths = fsView.listStatus(new Path("/")); FileStatus fs; - Assert.assertEquals(getExpectedDirPaths(), dirPaths.length); - fs = fileSystemTestHelper.containsPath(fsView, "/user", dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); - fs = fileSystemTestHelper.containsPath(fsView, "/data", dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); - fs = fileSystemTestHelper.containsPath(fsView, "/internalDir", dirPaths); + verifyRootChildren(dirPaths); + + // list on internal dir + dirPaths = fsView.listStatus(new Path("/internalDir")); + Assert.assertEquals(2, dirPaths.length); + + fs = fileSystemTestHelper.containsPath(fsView, "/internalDir/internalDir2", dirPaths); Assert.assertNotNull(fs); Assert.assertTrue("A mount should appear as symlink", fs.isDirectory()); - fs = fileSystemTestHelper.containsPath(fsView, "/danglingLink", dirPaths); + fs = fileSystemTestHelper.containsPath(fsView, "/internalDir/linkToDir2", + dirPaths); Assert.assertNotNull(fs); Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); - fs = fileSystemTestHelper.containsPath(fsView, "/linkToAFile", dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); - - - - // list on internal dir - dirPaths = fsView.listStatus(new Path("/internalDir")); - Assert.assertEquals(2, dirPaths.length); - - fs = fileSystemTestHelper.containsPath(fsView, "/internalDir/internalDir2", dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("A mount should appear as symlink", fs.isDirectory()); - fs = fileSystemTestHelper.containsPath(fsView, "/internalDir/linkToDir2", - dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); } - + + private void verifyRootChildren(FileStatus[] dirPaths) throws IOException { + FileStatus fs; + Assert.assertEquals(getExpectedDirPaths(), dirPaths.length); + fs = fileSystemTestHelper.containsPath(fsView, "/user", dirPaths); + Assert.assertNotNull(fs); + Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); + fs = fileSystemTestHelper.containsPath(fsView, "/data", dirPaths); + Assert.assertNotNull(fs); + Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); + fs = fileSystemTestHelper.containsPath(fsView, "/internalDir", dirPaths); + Assert.assertNotNull(fs); + Assert.assertTrue("A mount should appear as symlink", fs.isDirectory()); + fs = fileSystemTestHelper.containsPath(fsView, "/danglingLink", dirPaths); + Assert.assertNotNull(fs); + Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); + fs = fileSystemTestHelper.containsPath(fsView, "/linkToAFile", dirPaths); + Assert.assertNotNull(fs); + Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); + } + int getExpectedDirPaths() { return 7; } @@ -681,4 +686,38 @@ public void testCreateNonRecursive() throws IOException { Assert.assertTrue("Target of created file should be type file", fsTarget.isFile(new Path(targetTestRoot,"user/foo"))); } + + @Test + public void testRootReadableExecutable() throws IOException { + // verify executable permission on root: cd / + // + Assert.assertFalse("In root before cd", + fsView.getWorkingDirectory().isRoot()); + fsView.setWorkingDirectory(new Path("/")); + Assert.assertTrue("Not in root dir after cd", + fsView.getWorkingDirectory().isRoot()); + + // verify readable + // + verifyRootChildren(fsView.listStatus(fsView.getWorkingDirectory())); + + // verify permissions + // + final FileStatus rootStatus = + fsView.getFileStatus(fsView.getWorkingDirectory()); + final FsPermission perms = rootStatus.getPermission(); + + Assert.assertTrue("User-executable permission not set!", + perms.getUserAction().implies(FsAction.EXECUTE)); + Assert.assertTrue("User-readable permission not set!", + perms.getUserAction().implies(FsAction.READ)); + Assert.assertTrue("Group-executable permission not set!", + perms.getGroupAction().implies(FsAction.EXECUTE)); + Assert.assertTrue("Group-readable permission not set!", + perms.getGroupAction().implies(FsAction.READ)); + Assert.assertTrue("Other-executable permission not set!", + perms.getOtherAction().implies(FsAction.EXECUTE)); + Assert.assertTrue("Other-readable permission not set!", + perms.getOtherAction().implies(FsAction.READ)); + } }