Skip to content

Commit da1702a

Browse files
committed
HADOOP-17029. Addressed code review comments.
1 parent a7a7875 commit da1702a

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,14 +1200,9 @@ public FileStatus[] listStatus(Path f) throws AccessControlException,
12001200
INode<FileSystem> inode = iEntry.getValue();
12011201
if (inode.isLink()) {
12021202
INodeLink<FileSystem> link = (INodeLink<FileSystem>) inode;
1203-
// For MERGE or NFLY links, the first target link is considered
1204-
// for fetching the FileStatus with an assumption that the permission
1205-
// and the owner will be the same for all the target directories.
1206-
Path linkedPath = new Path(link.targetDirLinkList[0].toString());
1207-
ChRootedFileSystem linkedFs = (ChRootedFileSystem)
1208-
link.getTargetFileSystem();
12091203
try {
1210-
FileStatus status = linkedFs.getMyFs().getFileStatus(linkedPath);
1204+
FileStatus status = link.getTargetFileSystem()
1205+
.getFileStatus(new Path("/"));
12111206
result[i++] = new FileStatus(status.getLen(), false,
12121207
status.getReplication(), status.getBlockSize(),
12131208
status.getModificationTime(), status.getAccessTime(),

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,9 @@ public FileStatus getFileLinkStatus(final Path f)
917917
if (inode.isLink()) {
918918
INodeLink<AbstractFileSystem> inodelink =
919919
(INodeLink<AbstractFileSystem>) inode;
920-
Path linkedPath = new Path(inodelink.targetDirLinkList[0].toString());
921-
ChRootedFs linkedFs = (ChRootedFs) inodelink.getTargetFileSystem();
922920
try {
923-
FileStatus status = linkedFs.getMyFs().getFileStatus(linkedPath);
921+
FileStatus status = inodelink.getTargetFileSystem()
922+
.getFileStatus(new Path("/"));
924923
result = new FileStatus(status.getLen(), false,
925924
status.getReplication(), status.getBlockSize(),
926925
status.getModificationTime(), status.getAccessTime(),
@@ -989,10 +988,9 @@ public FileStatus[] listStatus(final Path f) throws AccessControlException,
989988
INodeLink<AbstractFileSystem> link =
990989
(INodeLink<AbstractFileSystem>) inode;
991990

992-
Path linkedPath = new Path(link.targetDirLinkList[0].toString());
993-
ChRootedFs linkedFs = (ChRootedFs) link.getTargetFileSystem();
994991
try {
995-
FileStatus status = linkedFs.getMyFs().getFileStatus(linkedPath);
992+
FileStatus status = link.getTargetFileSystem()
993+
.getFileStatus(new Path("/"));
996994
result[i++] = new FileStatus(status.getLen(), false,
997995
status.getReplication(), status.getBlockSize(),
998996
status.getModificationTime(), status.getAccessTime(),

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.hadoop.fs.FsConstants;
3030
import org.apache.hadoop.fs.Path;
3131
import org.apache.hadoop.fs.contract.ContractTestUtils;
32+
import org.apache.hadoop.fs.permission.FsPermission;
3233
import org.apache.hadoop.io.DataInputBuffer;
3334
import org.apache.hadoop.io.DataOutputBuffer;
3435
import org.apache.hadoop.test.GenericTestUtils;
@@ -98,9 +99,12 @@ public void testFileStatusSerialziation()
9899
}
99100
}
100101

102+
/**
103+
* Tests the ACL returned from getFileStatus for directories and files.
104+
* @throws IOException
105+
*/
101106
@Test
102-
public void testListStatusACL()
103-
throws IOException, URISyntaxException {
107+
public void testListStatusACL() throws IOException {
104108
String testfilename = "testFileACL";
105109
String childDirectoryName = "testDirectoryACL";
106110
TEST_DIR.mkdirs();
@@ -110,7 +114,7 @@ public void testListStatusACL()
110114
try (FileOutputStream fos = new FileOutputStream(infile)) {
111115
fos.write(content);
112116
}
113-
assertEquals((long)content.length, infile.length());
117+
assertEquals(content.length, infile.length());
114118
File childDir = new File(TEST_DIR, childDirectoryName);
115119
childDir.mkdirs();
116120

@@ -133,6 +137,22 @@ public void testListStatusACL()
133137
assertEquals(dirStat.getPermission(), status.getPermission());
134138
}
135139
}
140+
141+
localFs.setPermission(new Path(infile.getPath()),
142+
FsPermission.valueOf("-rwxr--r--"));
143+
localFs.setPermission(new Path(childDir.getPath()),
144+
FsPermission.valueOf("-r--rwxr--"));
145+
146+
statuses = vfs.listStatus(new Path("/"));
147+
for (FileStatus status : statuses) {
148+
if (status.getPath().getName().equals("file")) {
149+
assertEquals(FsPermission.valueOf("-rwxr--r--"),
150+
status.getPermission());
151+
} else {
152+
assertEquals(FsPermission.valueOf("-r--rwxr--"),
153+
status.getPermission());
154+
}
155+
}
136156
}
137157
}
138158

0 commit comments

Comments
 (0)