umamaheswararao commented on a change in pull request #2061:
URL: https://github.com/apache/hadoop/pull/2061#discussion_r437656020
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java
##########
@@ -1202,19 +1202,18 @@ public FileStatus getFileStatus(Path f) throws
IOException {
INodeLink<FileSystem> link = (INodeLink<FileSystem>) inode;
try {
String linkedPath = link.getTargetFileSystem().getUri().getPath();
- if("".equals(linkedPath)) {
+ if ("".equals(linkedPath)) {
linkedPath = "/";
}
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(),
- status.getPermission(), status.getOwner(), status.getGroup(),
- link.getTargetLink(),
- new Path(inode.fullPath).makeQualified(
- myUri, null));
+ ((ChRootedFileSystem) link.getTargetFileSystem()).getMyFs()
+ .getFileStatus(new Path(linkedPath));
+ result[i++] = new FileStatus(status.getLen(), status.isDirectory(),
+ status.getReplication(), status.getBlockSize(),
+ status.getModificationTime(), status.getAccessTime(),
+ status.getPermission(), status.getOwner(), status.getGroup(),
+ link.getTargetLink(),
+ new Path(inode.fullPath).makeQualified(myUri, null));
Review comment:
@ayushtkn
I have verified symlinks behavior in HDFS.
```
public void testSymlinkOnHDFS() throws Exception {
// add ur hdfs uri here: ex hdfs://10.0.1.75:9000
URI hdfsURI = dfs.getUri();
FileSystem.enableSymlinks();
try (FileSystem hdfs = new DistributedFileSystem()) {
hdfs.initialize(hdfsURI, new HdfsConfiguration());
final Path targetLinkDir = new Path("/user", "targetRegularDir");
hdfs.mkdirs(targetLinkDir);
Path symLinkDir = new Path("/links/linkDir");
hdfs.createSymlink(targetLinkDir, symLinkDir, true);
// ListStatus Test
FileStatus[] listStatus = hdfs.listStatus(new Path("/links"));
FileStatus fsFromLs = listStatus[0]; // FileStatus of /links/linkDir
Assert.assertEquals(fsFromLs.isDirectory(), false);
Assert.assertEquals("/links/linkDir",
Path.getPathWithoutSchemeAndAuthority(fsFromLs.getPath()).toString());
// GetFileStatus test
// FileStatus of /links/linkDir
FileStatus fileStatus = hdfs.getFileStatus(symLinkDir);
Assert.assertEquals(true, fileStatus.isDirectory());
// resolved to FileStatus of /user/targetRegularDir
Assert.assertEquals("/user/targetRegularDir", Path
.getPathWithoutSchemeAndAuthority(fileStatus.getPath()).toString());
}
}
```
It turns out that the behavior of listStatus and GetFileStatus are
different. They both returning different FileStatus. Same behavior in ViewFS
also.
GetFileStatus(/test), just runs on resolved path directly. So, it will not
be represented as symLink.
ListStatus(/) of gets /test as children FileStatus object. But that
represents as symLink.
Probably we should just clarify the behavior in user guide and API docs
about the behaviors in symlinks case? Otherwise fixing this needs to be done
all other places and it will be incompatible change across.
One advantage I see with the existing behavior is that, with listStatus we
can know dir is symlink. If one wants to know targetFs details, then issue
GetFileStatus on that path will resolved to targetFS and gets the FileStatus at
targetFS.
I will also check with Sanjay about his opinions on this.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]