[ 
https://issues.apache.org/jira/browse/HADOOP-20063?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18138460#comment-18138460
 ] 

ASF GitHub Bot commented on HADOOP-20063:
-----------------------------------------

LuciferYang opened a new pull request, #8927:
URL: https://github.com/apache/hadoop/pull/8927

   ### Description of PR
   
   JIRA: https://issues.apache.org/jira/browse/HADOOP-20063
   
   `FileContext.Util#copy` only runs its "Cannot copy ... to its subdirectory" 
check when `isSameFS()` returns true, and `isSameFS()` returns `scheme equal && 
!(both authorities non-null && equal)`, which is false exactly when the 
authorities match. Since HADOOP-6906 the check only works for paths without an 
authority. On HDFS, `fc.util().copy(new Path("/a"), new Path("/a/b"))` keeps 
copying into `/a/b/b/b/...` until the NameNode rejects the path depth, and 
`copy(dir, dir, true, true)` overwrites each file with itself and then deletes 
the directory.
   
   This patch compares the authorities with `Objects.equals`, so two null 
authorities still match and copies between clusters are still allowed.
   
   ### How was this patch tested?
   
   Added `TestFileContextCopyDependencies` with a mocked `AbstractFileSystem`. 
Copying `hdfs://nn:8020/a` to `/a/b` and to itself must fail with the 
subdirectory and "to itself" messages without calling `mkdir`; these two fail 
without the fix. Copying to another authority must go ahead, and a `file:///` 
copy into a subdirectory must still be rejected; these two pin the cases that 
already worked.
   
   ### For code changes:
   
   - [x] Does the title of this PR start with the corresponding JIRA issue id 
(e.g. 'HADOOP-17799. Your PR title ...')?
   - [ ] Object storage: Have the integration tests been executed and the 
endpoint declared according to the connector-specific documentation?
   - [ ] If adding new dependencies to the code, are these dependencies 
licensed in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the `LICENSE`, `LICENSE-binary`, 
`NOTICE-binary` files?
   
   ### AI Tooling
   
   - [x] The PR includes the phrase "Contains content generated by Claude Opus".
   - [x] My use of AI contributions follows the ASF legal policy 
https://www.apache.org/legal/generative-tooling.html
   
   Contains content generated by Claude Opus.
   




> 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
>
> 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]

Reply via email to