From 35cfe4e6eddfae9a10207b839d92040b01434162 Mon Sep 17 00:00:00 2001 From: Abhishek Das Date: Wed, 13 May 2020 05:15:36 -0700 Subject: [PATCH 1/5] HADOOP-17029. Return correct permission and owner for listing on internal directories in ViewFs --- .../hadoop/fs/viewfs/ViewFileSystem.java | 19 ++-- .../fs/viewfs/TestViewfsFileStatus.java | 98 ++++++++++++++----- 2 files changed, 85 insertions(+), 32 deletions(-) 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 4f02feeebec8b..d9bbd91f14e16 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 @@ -1087,6 +1087,7 @@ static class InternalDirOfViewFs extends FileSystem { final long creationTime; // of the the mount table final UserGroupInformation ugi; // the user/group of user who created mtable final URI myUri; + final Configuration conf; public InternalDirOfViewFs(final InodeTree.INodeDir dir, final long cTime, final UserGroupInformation ugi, URI uri, @@ -1100,6 +1101,7 @@ public InternalDirOfViewFs(final InodeTree.INodeDir dir, theInternalDir = dir; creationTime = cTime; this.ugi = ugi; + this.conf = config; } static private void checkPathIsSlash(final Path f) throws IOException { @@ -1200,12 +1202,17 @@ public FileStatus[] listStatus(Path f) throws AccessControlException, INode inode = iEntry.getValue(); if (inode.isLink()) { INodeLink link = (INodeLink) inode; - - result[i++] = new FileStatus(0, false, 0, 0, - creationTime, creationTime, PERMISSION_555, - ugi.getShortUserName(), ugi.getPrimaryGroupName(), - link.getTargetLink(), - new Path(inode.fullPath).makeQualified( + // For MERGE or NFLY links, the first target link is considered + // for fetching the FileStatus with an assumption that the permission + // and the owner will be the same for all the target directories. + FileStatus status = FileSystem.get(link.targetDirLinkList[0], conf) + .getFileStatus(new Path(link.targetDirLinkList[0].toString())); + + result[i++] = new FileStatus(status.getLen(), false, 0, 0, + status.getModificationTime(), status.getAccessTime(), + status.getPermission(), status.getOwner(), status.getGroup(), + link.getTargetLink(), + new Path(inode.fullPath).makeQualified( myUri, null)); } else { result[i++] = new FileStatus(0, true, 0, 0, diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java index 0c31c8ed6a901..a41cbd80861a9 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java @@ -32,7 +32,9 @@ import org.apache.hadoop.io.DataInputBuffer; import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.test.GenericTestUtils; +import org.junit.After; import org.junit.AfterClass; +import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -48,6 +50,17 @@ public class TestViewfsFileStatus { private static final File TEST_DIR = GenericTestUtils.getTestDir( TestViewfsFileStatus.class.getSimpleName()); + @Before + public void setUp() { + FileUtil.fullyDelete(TEST_DIR); + assertTrue(TEST_DIR.mkdirs()); + } + + @After + public void tearDown() throws IOException { + FileUtil.fullyDelete(TEST_DIR); + } + @Test public void testFileStatusSerialziation() throws IOException, URISyntaxException { @@ -56,38 +69,71 @@ public void testFileStatusSerialziation() File infile = new File(TEST_DIR, testfilename); final byte[] content = "dingos".getBytes(); - FileOutputStream fos = null; - try { - fos = new FileOutputStream(infile); + try (FileOutputStream fos = new FileOutputStream(infile)) { fos.write(content); - } finally { - if (fos != null) { - fos.close(); - } } assertEquals((long)content.length, infile.length()); Configuration conf = new Configuration(); ConfigUtil.addLink(conf, "/foo/bar/baz", TEST_DIR.toURI()); - FileSystem vfs = FileSystem.get(FsConstants.VIEWFS_URI, conf); - assertEquals(ViewFileSystem.class, vfs.getClass()); - Path path = new Path("/foo/bar/baz", testfilename); - FileStatus stat = vfs.getFileStatus(path); - assertEquals(content.length, stat.getLen()); - ContractTestUtils.assertNotErasureCoded(vfs, path); - assertTrue(path + " should have erasure coding unset in " + - "FileStatus#toString(): " + stat, - stat.toString().contains("isErasureCoded=false")); - - // check serialization/deserialization - DataOutputBuffer dob = new DataOutputBuffer(); - stat.write(dob); - DataInputBuffer dib = new DataInputBuffer(); - dib.reset(dob.getData(), 0, dob.getLength()); - FileStatus deSer = new FileStatus(); - deSer.readFields(dib); - assertEquals(content.length, deSer.getLen()); - assertFalse(deSer.isErasureCoded()); + try (FileSystem vfs = FileSystem.get(FsConstants.VIEWFS_URI, conf)) { + assertEquals(ViewFileSystem.class, vfs.getClass()); + Path path = new Path("/foo/bar/baz", testfilename); + FileStatus stat = vfs.getFileStatus(path); + assertEquals(content.length, stat.getLen()); + ContractTestUtils.assertNotErasureCoded(vfs, path); + assertTrue(path + " should have erasure coding unset in " + + "FileStatus#toString(): " + stat, + stat.toString().contains("isErasureCoded=false")); + + // check serialization/deserialization + DataOutputBuffer dob = new DataOutputBuffer(); + stat.write(dob); + DataInputBuffer dib = new DataInputBuffer(); + dib.reset(dob.getData(), 0, dob.getLength()); + FileStatus deSer = new FileStatus(); + deSer.readFields(dib); + assertEquals(content.length, deSer.getLen()); + assertFalse(deSer.isErasureCoded()); + } + } + + @Test + public void testListStatusACL() + throws IOException, URISyntaxException { + String testfilename = "testFileACL"; + String childDirectoryName = "testDirectoryACL"; + TEST_DIR.mkdirs(); + File infile = new File(TEST_DIR, testfilename); + final byte[] content = "dingos".getBytes(); + + try (FileOutputStream fos = new FileOutputStream(infile)) { + fos.write(content); + } + assertEquals((long)content.length, infile.length()); + File childDir = new File(TEST_DIR, childDirectoryName); + childDir.mkdirs(); + + Configuration conf = new Configuration(); + ConfigUtil.addLink(conf, "/file", infile.toURI()); + ConfigUtil.addLink(conf, "/dir", childDir.toURI()); + + try (FileSystem vfs = FileSystem.get(FsConstants.VIEWFS_URI, conf)) { + assertEquals(ViewFileSystem.class, vfs.getClass()); + FileStatus[] statuses = vfs.listStatus(new Path("/")); + + FileSystem localFs = FileSystem.getLocal(conf); + FileStatus fileStat = localFs.getFileStatus(new Path(infile.getPath())); + FileStatus dirStat = localFs.getFileStatus(new Path(childDir.getPath())); + + for (FileStatus status : statuses) { + if (status.getPath().getName().equals("file")) { + assertEquals(fileStat.getPermission(), status.getPermission()); + } else { + assertEquals(dirStat.getPermission(), status.getPermission()); + } + } + } } // Tests that ViewFileSystem.getFileChecksum calls res.targetFileSystem From 0243a701637c6296f77eb3c7ad0e9f8ccb63c8c4 Mon Sep 17 00:00:00 2001 From: Abhishek Das Date: Wed, 13 May 2020 16:13:55 -0700 Subject: [PATCH 2/5] HADOOP-17029. Change in ViewFs to cover FileContext based fs impl. --- .../hadoop/fs/viewfs/ViewFileSystem.java | 17 ++++++++-------- .../org/apache/hadoop/fs/viewfs/ViewFs.java | 20 ++++++++++++++----- 2 files changed, 24 insertions(+), 13 deletions(-) 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 d9bbd91f14e16..a16615ed59a69 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 @@ -1087,7 +1087,6 @@ static class InternalDirOfViewFs extends FileSystem { final long creationTime; // of the the mount table final UserGroupInformation ugi; // the user/group of user who created mtable final URI myUri; - final Configuration conf; public InternalDirOfViewFs(final InodeTree.INodeDir dir, final long cTime, final UserGroupInformation ugi, URI uri, @@ -1101,7 +1100,6 @@ public InternalDirOfViewFs(final InodeTree.INodeDir dir, theInternalDir = dir; creationTime = cTime; this.ugi = ugi; - this.conf = config; } static private void checkPathIsSlash(final Path f) throws IOException { @@ -1205,14 +1203,17 @@ public FileStatus[] listStatus(Path f) throws AccessControlException, // For MERGE or NFLY links, the first target link is considered // for fetching the FileStatus with an assumption that the permission // and the owner will be the same for all the target directories. - FileStatus status = FileSystem.get(link.targetDirLinkList[0], conf) + ChRootedFileSystem linkedFs = (ChRootedFileSystem) + link.getTargetFileSystem(); + FileStatus status = linkedFs.getMyFs() .getFileStatus(new Path(link.targetDirLinkList[0].toString())); - result[i++] = new FileStatus(status.getLen(), false, 0, 0, - status.getModificationTime(), status.getAccessTime(), - status.getPermission(), status.getOwner(), status.getGroup(), - link.getTargetLink(), - new Path(inode.fullPath).makeQualified( + result[i++] = new FileStatus(status.getLen(), false, + status.getReplication(), status.getBlockSize(), + status.getModificationTime(), status.getAccessTime(), + status.getPermission(), status.getOwner(), status.getGroup(), + link.getTargetLink(), + new Path(inode.fullPath).makeQualified( myUri, null)); } else { result[i++] = new FileStatus(0, true, 0, 0, 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 607bdb8d423a0..c75867db5bf6b 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 @@ -917,8 +917,13 @@ public FileStatus getFileLinkStatus(final Path f) if (inode.isLink()) { INodeLink inodelink = (INodeLink) inode; - result = new FileStatus(0, false, 0, 0, creationTime, creationTime, - PERMISSION_555, ugi.getShortUserName(), ugi.getPrimaryGroupName(), + ChRootedFs linkedFs = (ChRootedFs) inodelink.getTargetFileSystem(); + FileStatus status = linkedFs.getMyFs() + .getFileStatus(new Path(inodelink.targetDirLinkList[0].toString())); + result = new FileStatus(status.getLen(), false, + status.getReplication(), status.getBlockSize(), + status.getModificationTime(), status.getAccessTime(), + status.getPermission(), status.getOwner(), status.getGroup(), inodelink.getTargetLink(), new Path(inode.fullPath).makeQualified( myUri, null)); @@ -976,9 +981,14 @@ public FileStatus[] listStatus(final Path f) throws AccessControlException, INodeLink link = (INodeLink) inode; - result[i++] = new FileStatus(0, false, 0, 0, - creationTime, creationTime, - PERMISSION_555, ugi.getShortUserName(), ugi.getPrimaryGroupName(), + ChRootedFs linkedFs = (ChRootedFs) link.getTargetFileSystem(); + FileStatus status = linkedFs.getMyFs() + .getFileStatus(new Path(link.targetDirLinkList[0].toString())); + + result[i++] = new FileStatus(status.getLen(), false, + status.getReplication(), status.getBlockSize(), + status.getModificationTime(), status.getAccessTime(), + status.getPermission(), status.getOwner(), status.getGroup(), link.getTargetLink(), new Path(inode.fullPath).makeQualified( myUri, null)); From a7a7875038ca29f87d6f050547c35d081d9401e1 Mon Sep 17 00:00:00 2001 From: Abhishek Das Date: Thu, 14 May 2020 00:51:28 -0700 Subject: [PATCH 3/5] HADOOP-17029. Fix for dangling links --- .../hadoop/fs/viewfs/ViewFileSystem.java | 28 ++++++++----- .../org/apache/hadoop/fs/viewfs/ViewFs.java | 42 +++++++++++++------ 2 files changed, 47 insertions(+), 23 deletions(-) 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 a16615ed59a69..0c0fa56fd45c5 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 @@ -1203,18 +1203,26 @@ public FileStatus[] listStatus(Path f) throws AccessControlException, // For MERGE or NFLY links, the first target link is considered // for fetching the FileStatus with an assumption that the permission // and the owner will be the same for all the target directories. + Path linkedPath = new Path(link.targetDirLinkList[0].toString()); ChRootedFileSystem linkedFs = (ChRootedFileSystem) link.getTargetFileSystem(); - FileStatus status = linkedFs.getMyFs() - .getFileStatus(new Path(link.targetDirLinkList[0].toString())); - - result[i++] = new FileStatus(status.getLen(), false, - status.getReplication(), status.getBlockSize(), - status.getModificationTime(), status.getAccessTime(), - status.getPermission(), status.getOwner(), status.getGroup(), - link.getTargetLink(), - new Path(inode.fullPath).makeQualified( - myUri, null)); + try { + FileStatus status = linkedFs.getMyFs().getFileStatus(linkedPath); + result[i++] = new FileStatus(status.getLen(), false, + status.getReplication(), status.getBlockSize(), + status.getModificationTime(), status.getAccessTime(), + status.getPermission(), status.getOwner(), status.getGroup(), + link.getTargetLink(), + new Path(inode.fullPath).makeQualified( + myUri, null)); + } catch (FileNotFoundException ex) { + result[i++] = new FileStatus(0, false, 0, 0, + creationTime, creationTime, PERMISSION_555, + ugi.getShortUserName(), ugi.getPrimaryGroupName(), + link.getTargetLink(), + new Path(inode.fullPath).makeQualified( + myUri, null)); + } } else { result[i++] = new FileStatus(0, true, 0, 0, creationTime, creationTime, PERMISSION_555, 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 c75867db5bf6b..71d129bc9e27e 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 @@ -917,16 +917,24 @@ public FileStatus getFileLinkStatus(final Path f) if (inode.isLink()) { INodeLink inodelink = (INodeLink) inode; + Path linkedPath = new Path(inodelink.targetDirLinkList[0].toString()); ChRootedFs linkedFs = (ChRootedFs) inodelink.getTargetFileSystem(); - FileStatus status = linkedFs.getMyFs() - .getFileStatus(new Path(inodelink.targetDirLinkList[0].toString())); - result = new FileStatus(status.getLen(), false, + try { + FileStatus status = linkedFs.getMyFs().getFileStatus(linkedPath); + result = new FileStatus(status.getLen(), false, status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(), status.getPermission(), status.getOwner(), status.getGroup(), inodelink.getTargetLink(), new Path(inode.fullPath).makeQualified( myUri, null)); + } catch (FileNotFoundException ex) { + result = new FileStatus(0, false, 0, 0, creationTime, creationTime, + PERMISSION_555, ugi.getShortUserName(), ugi.getPrimaryGroupName(), + inodelink.getTargetLink(), + new Path(inode.fullPath).makeQualified( + myUri, null)); + } } else { result = new FileStatus(0, true, 0, 0, creationTime, creationTime, PERMISSION_555, ugi.getShortUserName(), ugi.getPrimaryGroupName(), @@ -981,17 +989,25 @@ public FileStatus[] listStatus(final Path f) throws AccessControlException, INodeLink link = (INodeLink) inode; + Path linkedPath = new Path(link.targetDirLinkList[0].toString()); ChRootedFs linkedFs = (ChRootedFs) link.getTargetFileSystem(); - FileStatus status = linkedFs.getMyFs() - .getFileStatus(new Path(link.targetDirLinkList[0].toString())); - - result[i++] = new FileStatus(status.getLen(), false, - status.getReplication(), status.getBlockSize(), - status.getModificationTime(), status.getAccessTime(), - status.getPermission(), status.getOwner(), status.getGroup(), - link.getTargetLink(), - new Path(inode.fullPath).makeQualified( - myUri, null)); + try { + FileStatus status = linkedFs.getMyFs().getFileStatus(linkedPath); + result[i++] = new FileStatus(status.getLen(), false, + status.getReplication(), status.getBlockSize(), + status.getModificationTime(), status.getAccessTime(), + status.getPermission(), status.getOwner(), status.getGroup(), + link.getTargetLink(), + new Path(inode.fullPath).makeQualified( + myUri, null)); + } catch (FileNotFoundException ex) { + result[i++] = new FileStatus(0, false, 0, 0, + creationTime, creationTime, PERMISSION_555, + ugi.getShortUserName(), ugi.getPrimaryGroupName(), + link.getTargetLink(), + new Path(inode.fullPath).makeQualified( + myUri, null)); + } } else { result[i++] = new FileStatus(0, true, 0, 0, creationTime, creationTime, From da1702af608f5f27d62d31dca4705c7872f2e6c3 Mon Sep 17 00:00:00 2001 From: Abhishek Das Date: Tue, 2 Jun 2020 22:56:07 -0700 Subject: [PATCH 4/5] HADOOP-17029. Addressed code review comments. --- .../hadoop/fs/viewfs/ViewFileSystem.java | 9 ++----- .../org/apache/hadoop/fs/viewfs/ViewFs.java | 10 +++---- .../fs/viewfs/TestViewfsFileStatus.java | 26 ++++++++++++++++--- 3 files changed, 29 insertions(+), 16 deletions(-) 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 0c0fa56fd45c5..9f499de3244f5 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 @@ -1200,14 +1200,9 @@ public FileStatus[] listStatus(Path f) throws AccessControlException, INode inode = iEntry.getValue(); if (inode.isLink()) { INodeLink link = (INodeLink) inode; - // For MERGE or NFLY links, the first target link is considered - // for fetching the FileStatus with an assumption that the permission - // and the owner will be the same for all the target directories. - Path linkedPath = new Path(link.targetDirLinkList[0].toString()); - ChRootedFileSystem linkedFs = (ChRootedFileSystem) - link.getTargetFileSystem(); try { - FileStatus status = linkedFs.getMyFs().getFileStatus(linkedPath); + FileStatus status = link.getTargetFileSystem() + .getFileStatus(new Path("/")); result[i++] = new FileStatus(status.getLen(), false, status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(), 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 71d129bc9e27e..02859b7c6f9b9 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 @@ -917,10 +917,9 @@ public FileStatus getFileLinkStatus(final Path f) if (inode.isLink()) { INodeLink inodelink = (INodeLink) inode; - Path linkedPath = new Path(inodelink.targetDirLinkList[0].toString()); - ChRootedFs linkedFs = (ChRootedFs) inodelink.getTargetFileSystem(); try { - FileStatus status = linkedFs.getMyFs().getFileStatus(linkedPath); + FileStatus status = inodelink.getTargetFileSystem() + .getFileStatus(new Path("/")); result = new FileStatus(status.getLen(), false, status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(), @@ -989,10 +988,9 @@ public FileStatus[] listStatus(final Path f) throws AccessControlException, INodeLink link = (INodeLink) inode; - Path linkedPath = new Path(link.targetDirLinkList[0].toString()); - ChRootedFs linkedFs = (ChRootedFs) link.getTargetFileSystem(); try { - FileStatus status = linkedFs.getMyFs().getFileStatus(linkedPath); + FileStatus status = link.getTargetFileSystem() + .getFileStatus(new Path("/")); result[i++] = new FileStatus(status.getLen(), false, status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(), diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java index a41cbd80861a9..29fcc22db1fe6 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java @@ -29,6 +29,7 @@ import org.apache.hadoop.fs.FsConstants; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.contract.ContractTestUtils; +import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.io.DataInputBuffer; import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.test.GenericTestUtils; @@ -98,9 +99,12 @@ public void testFileStatusSerialziation() } } + /** + * Tests the ACL returned from getFileStatus for directories and files. + * @throws IOException + */ @Test - public void testListStatusACL() - throws IOException, URISyntaxException { + public void testListStatusACL() throws IOException { String testfilename = "testFileACL"; String childDirectoryName = "testDirectoryACL"; TEST_DIR.mkdirs(); @@ -110,7 +114,7 @@ public void testListStatusACL() try (FileOutputStream fos = new FileOutputStream(infile)) { fos.write(content); } - assertEquals((long)content.length, infile.length()); + assertEquals(content.length, infile.length()); File childDir = new File(TEST_DIR, childDirectoryName); childDir.mkdirs(); @@ -133,6 +137,22 @@ public void testListStatusACL() assertEquals(dirStat.getPermission(), status.getPermission()); } } + + localFs.setPermission(new Path(infile.getPath()), + FsPermission.valueOf("-rwxr--r--")); + localFs.setPermission(new Path(childDir.getPath()), + FsPermission.valueOf("-r--rwxr--")); + + statuses = vfs.listStatus(new Path("/")); + for (FileStatus status : statuses) { + if (status.getPath().getName().equals("file")) { + assertEquals(FsPermission.valueOf("-rwxr--r--"), + status.getPermission()); + } else { + assertEquals(FsPermission.valueOf("-r--rwxr--"), + status.getPermission()); + } + } } } From 7d43b2932d38458041b2fc00c68b27b8ec0ee209 Mon Sep 17 00:00:00 2001 From: Abhishek Das Date: Fri, 5 Jun 2020 04:16:27 -0700 Subject: [PATCH 5/5] HADOOP-17029. Used link.getTargetFileSystem().getUri() for path --- .../org/apache/hadoop/fs/viewfs/ViewFileSystem.java | 6 ++++-- .../main/java/org/apache/hadoop/fs/viewfs/ViewFs.java | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) 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 9f499de3244f5..142785a88e4cd 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 @@ -1201,8 +1201,10 @@ public FileStatus[] listStatus(Path f) throws AccessControlException, if (inode.isLink()) { INodeLink link = (INodeLink) inode; try { - FileStatus status = link.getTargetFileSystem() - .getFileStatus(new Path("/")); + String linkedPath = link.getTargetFileSystem().getUri().getPath(); + FileStatus status = + ((ChRootedFileSystem)link.getTargetFileSystem()) + .getMyFs().getFileStatus(new Path(linkedPath)); result[i++] = new FileStatus(status.getLen(), false, status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(), 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 02859b7c6f9b9..df10dce50b78f 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 @@ -918,8 +918,10 @@ public FileStatus getFileLinkStatus(final Path f) INodeLink inodelink = (INodeLink) inode; try { - FileStatus status = inodelink.getTargetFileSystem() - .getFileStatus(new Path("/")); + String linkedPath = inodelink.getTargetFileSystem() + .getUri().getPath(); + FileStatus status = ((ChRootedFs)inodelink.getTargetFileSystem()) + .getMyFs().getFileStatus(new Path(linkedPath)); result = new FileStatus(status.getLen(), false, status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(), @@ -989,8 +991,9 @@ public FileStatus[] listStatus(final Path f) throws AccessControlException, (INodeLink) inode; try { - FileStatus status = link.getTargetFileSystem() - .getFileStatus(new Path("/")); + String linkedPath = link.getTargetFileSystem().getUri().getPath(); + FileStatus status = ((ChRootedFs)link.getTargetFileSystem()) + .getMyFs().getFileStatus(new Path(linkedPath)); result[i++] = new FileStatus(status.getLen(), false, status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(),