[
https://issues.apache.org/jira/browse/HADOOP-20063?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18144743#comment-18144743
]
ASF GitHub Bot commented on HADOOP-20063:
-----------------------------------------
slfan1989 commented on code in PR #8927:
URL: https://github.com/apache/hadoop/pull/8927#discussion_r4572522683
##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java:
##########
@@ -2298,17 +2299,17 @@ private static void checkDependencies(Path qualSrc,
Path qualDst)
}
/**
- * Are qualSrc and qualDst of the same file system?
+ * Are qualPath1 and qualPath2 on the same file system, i.e. do they have
+ * the same scheme and authority?
* @param qualPath1 - fully qualified path
* @param qualPath2 - fully qualified path
- * @return is same fs true,not false.
+ * @return true if the two paths are on the same file system, else false.
*/
private static boolean isSameFS(Path qualPath1, Path qualPath2) {
URI srcUri = qualPath1.toUri();
URI dstUri = qualPath2.toUri();
- return (srcUri.getScheme().equals(dstUri.getScheme()) &&
- !(srcUri.getAuthority() != null && dstUri.getAuthority() != null &&
srcUri
- .getAuthority().equals(dstUri.getAuthority())));
+ return srcUri.getScheme().equals(dstUri.getScheme())
+ && Objects.equals(srcUri.getAuthority(), dstUri.getAuthority());
Review Comment:
Thanks for fixing the inverted authority comparison!
I reproduced a remaining case where copying `hdfs://nn:8020/a` to
`hdfs://nn/a/b` still returns `true` and calls `mkdir()`, even though both
paths resolve to the same filesystem. The same happens with
`hdfs://NN:8020/a/b`.
Could we use the filesystem’s host and default-port rules for the identity
check, then compare the path components for the self/subdirectory check?
A regression test for the omitted default port would cover this case.
> FileContext.Util#copy does not reject copying a directory into itself or its
> subdirectory when both paths have the same authority
> ---------------------------------------------------------------------------------------------------------------------------------
>
> Key: HADOOP-20063
> URL: https://issues.apache.org/jira/browse/HADOOP-20063
> Project: Hadoop Common
> Issue Type: Bug
> Components: fs
> Reporter: Yang Jie
> Priority: Major
> Labels: pull-request-available
>
> FileContext.Util#copy calls checkDependencies() to reject copying a directory
> into itself or into one of its subdirectories, but only when isSameFS() says
> the two paths are on the same file system. isSameFS() returns {{scheme equal
> && !(both authorities non-null && equal)}}, which is false exactly when the
> authorities are equal. Since HADOOP-6906, which made the old
> {{getAuthority().equals()}} check null-safe and inverted it in the same
> change, the check only works for paths without an authority, such as local
> paths.
> On HDFS, {{fc.util().copy(new Path("/a"), new Path("/a/b"))}} creates /a/b,
> lists /a (which now includes b) and recurses into /a/b/b, /a/b/b/b and so on,
> until the NameNode rejects a path that is too deep. Files listed before b are
> copied again at every level. {{copy(dir, dir, true, true)}} overwrites each
> file with itself and then deletes the source directory.
> The fix compares the authorities with {{Objects.equals}}. Two null
> authorities still count as the same file system, and copies between clusters
> are still allowed.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]