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

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

slfan1989 commented on code in PR #8933:
URL: https://github.com/apache/hadoop/pull/8933#discussion_r4504630409


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java:
##########
@@ -121,6 +121,18 @@ private Path makeTrashRelativePath(Path basePath, Path 
rmFilePath) {
     return Path.mergePaths(basePath, rmFilePath);
   }
 
+  /**
+   * @return true if {@code ancestor} is {@code path} or one of its ancestors,
+   *         comparing whole path components: "/user/al" is not an ancestor
+   *         of "/user/alice".
+   */
+  private static boolean isAncestorOf(Path ancestor, Path path) {
+    String a = ancestor.toString();

Review Comment:
   Could we compare the URI path components here? 
   
   `Path.toString()` includes the fragment, but `RawLocalFileSystem` ignores it 
when resolving the file. 
   
   I reproduced this with a `Path` constructed from a URI ending in 
`.Trash#alias`: before the patch, `moveToTrash()` returns `false`; with this 
patch, it tries to move `.Trash` into its own `Current` directory and throws. 
   
   Could we add a regression test for this case?





> 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
>              Labels: pull-request-available
>
> 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]

Reply via email to