[
https://issues.apache.org/jira/browse/HADOOP-20069?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18138467#comment-18138467
]
ASF GitHub Bot commented on HADOOP-20069:
-----------------------------------------
LuciferYang opened a new pull request, #8933:
URL: https://github.com/apache/hadoop/pull/8933
### Description of PR
JIRA: https://issues.apache.org/jira/browse/HADOOP-20069
`moveToTrash()` uses string prefix checks to decide whether a path is
already in the trash and whether it contains the trash, without respecting path
component boundaries:
- `hadoop fs -rm -r /user/alice/.Trash_old` run by alice: the path starts
with `/user/alice/.Trash`, so `moveToTrash()` returns false and `Delete` falls
back to `fs.delete()`. The directory is deleted permanently.
- `hadoop fs -rm -r /user/etl` run by etl_prod: `/user/etl_prod` starts with
`/user/etl`, so the command fails with `Cannot move "/user/etl" to the trash,
as it contains the trash`.
Encryption zone and snapshot trash roots have the same problem
(`/ez/.Trash/alice` and `/ez/.Trash/alice2`). This patch compares whole path
components. Paths inside the trash, or containing it, are handled as before.
### How was this patch tested?
Added two cases to `TestTrash` on a local file system whose home directory
is under the test directory:
- `testMoveToTrashTrashRootPrefixSibling`: `~/.Trashbackups` is moved to the
trash, and a path inside `~/.Trash/Current` is still reported as already there.
- `testMoveToTrashHomePrefixSibling`: `users/al` (home is `users/alice`) is
moved to the trash, and moving the home directory still fails with `contains
the trash`.
Without the fix the first fails because `moveToTrash` returns false and the
second fails with the `contains the trash` error.
### 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.
> TrashPolicyDefault#moveToTrash compares paths as strings, so ~/.Trash_old is
> deleted without the trash and a prefix of the home directory cannot be moved
> to it
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: HADOOP-20069
> URL: https://issues.apache.org/jira/browse/HADOOP-20069
> Project: Hadoop Common
> Issue Type: Bug
> Components: fs
> Reporter: Yang Jie
> Priority: Major
>
> moveToTrash() decides whether a path is already in the trash, and whether it
> contains the trash, with string prefix checks:
> {code:java}
> if (qpath.startsWith(trashRoot.toString())) {
> return false; // already in trash
> }
> if (trashRoot.getParent().toString().startsWith(qpath)) {
> throw new IOException("Cannot move \"" + path +
> "\" to the trash, as it contains the trash");
> }
> {code}
> Neither respects path component boundaries:
> * {{hadoop fs -rm -r /user/alice/.Trash_old}} run by alice: the path starts
> with /user/alice/.Trash, so moveToTrash() returns false and Delete falls back
> to fs.delete(). The directory is deleted permanently and the shell prints
> "Deleted ..." instead of "Moved: ... to trash at: ...".
> * {{hadoop fs -rm -r /user/etl}} run by etl_prod: /user/etl_prod starts with
> /user/etl, so the command fails with "Cannot move "/user/etl" to the trash,
> as it contains the trash. Consider using -skipTrash option".
> Encryption zone and snapshot trash roots have the same problem, e.g.
> /ez/.Trash/alice and /ez/.Trash/alice2.
> The fix compares whole path components. Paths that are inside the trash, or
> that contain it, are handled as before.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]