Skip to content

Commit 66036d6

Browse files
HADOOP-17060. listStatus and getFileStatus behave inconsistent in the case of ViewFs implementation for isDirectory
1 parent a8610c1 commit 66036d6

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,6 @@ public FileStatus(long length, boolean isdir, int block_replication,
170170
this.symlink = symlink;
171171
this.path = path;
172172
this.attr = attr;
173-
174-
// The variables isdir and symlink indicate the type:
175-
// 1. isdir implies directory, in which case symlink must be null.
176-
// 2. !isdir implies a file or symlink, symlink != null implies a
177-
// symlink, otherwise it's a file.
178-
assert (isdir && symlink == null) || !isdir;
179173
}
180174

181175
/**

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,19 +1202,18 @@ public FileStatus[] listStatus(Path f) throws AccessControlException,
12021202
INodeLink<FileSystem> link = (INodeLink<FileSystem>) inode;
12031203
try {
12041204
String linkedPath = link.getTargetFileSystem().getUri().getPath();
1205-
if("".equals(linkedPath)) {
1205+
if ("".equals(linkedPath)) {
12061206
linkedPath = "/";
12071207
}
12081208
FileStatus status =
1209-
((ChRootedFileSystem)link.getTargetFileSystem())
1210-
.getMyFs().getFileStatus(new Path(linkedPath));
1211-
result[i++] = new FileStatus(status.getLen(), false,
1212-
status.getReplication(), status.getBlockSize(),
1213-
status.getModificationTime(), status.getAccessTime(),
1214-
status.getPermission(), status.getOwner(), status.getGroup(),
1215-
link.getTargetLink(),
1216-
new Path(inode.fullPath).makeQualified(
1217-
myUri, null));
1209+
((ChRootedFileSystem) link.getTargetFileSystem()).getMyFs()
1210+
.getFileStatus(new Path(linkedPath));
1211+
result[i++] = new FileStatus(status.getLen(), status.isDirectory(),
1212+
status.getReplication(), status.getBlockSize(),
1213+
status.getModificationTime(), status.getAccessTime(),
1214+
status.getPermission(), status.getOwner(), status.getGroup(),
1215+
link.getTargetLink(),
1216+
new Path(inode.fullPath).makeQualified(myUri, null));
12181217
} catch (FileNotFoundException ex) {
12191218
result[i++] = new FileStatus(0, false, 0, 0,
12201219
creationTime, creationTime, PERMISSION_555,

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -992,15 +992,17 @@ public FileStatus[] listStatus(final Path f) throws AccessControlException,
992992

993993
try {
994994
String linkedPath = link.getTargetFileSystem().getUri().getPath();
995-
FileStatus status = ((ChRootedFs)link.getTargetFileSystem())
995+
if ("".equals(linkedPath)) {
996+
linkedPath = "/";
997+
}
998+
FileStatus status = ((ChRootedFs) link.getTargetFileSystem())
996999
.getMyFs().getFileStatus(new Path(linkedPath));
997-
result[i++] = new FileStatus(status.getLen(), false,
998-
status.getReplication(), status.getBlockSize(),
999-
status.getModificationTime(), status.getAccessTime(),
1000-
status.getPermission(), status.getOwner(), status.getGroup(),
1001-
link.getTargetLink(),
1002-
new Path(inode.fullPath).makeQualified(
1003-
myUri, null));
1000+
result[i++] = new FileStatus(status.getLen(), status.isDirectory(),
1001+
status.getReplication(), status.getBlockSize(),
1002+
status.getModificationTime(), status.getAccessTime(),
1003+
status.getPermission(), status.getOwner(), status.getGroup(),
1004+
link.getTargetLink(),
1005+
new Path(inode.fullPath).makeQualified(myUri, null));
10041006
} catch (FileNotFoundException ex) {
10051007
result[i++] = new FileStatus(0, false, 0, 0,
10061008
creationTime, creationTime, PERMISSION_555,

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ public void testListOnInternalDirsOfMountTable() throws IOException {
486486
fs = fileContextTestHelper.containsPath(fcView, "/user", dirPaths);
487487
Assert.assertNotNull(fs);
488488
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
489+
Assert.assertTrue(
490+
"A mount link should appear as directory if target is directory",
491+
fs.isDirectory());
489492
fs = fileContextTestHelper.containsPath(fcView, "/data", dirPaths);
490493
Assert.assertNotNull(fs);
491494
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
@@ -498,7 +501,9 @@ public void testListOnInternalDirsOfMountTable() throws IOException {
498501
fs = fileContextTestHelper.containsPath(fcView, "/linkToAFile", dirPaths);
499502
Assert.assertNotNull(fs);
500503
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
501-
504+
Assert.assertFalse(
505+
"A mount should appear as non dir if target link is a file",
506+
fs.isDirectory());
502507

503508

504509
// list on internal dir

0 commit comments

Comments
 (0)