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

J.Andreina commented on HDFS-9123:
----------------------------------

Thanks [~jojochuang] . That was a good catch. I have few comments .

bq.if the source path is ended with a '/' path separator, the existing 
validation for sub-directories fails
As I have verified, issue of copying indefinitely, exist only if src is just 
root ('/"). It will not happen for any other paths ending with '/'.
{noformat}
        > ./hdfs dfs -cp /abc/ /abc/abcdef
        cp: `/abc' to `/abc/abcdef/abc': is a subdirectory of itself
{noformat}

*So, I feel since this is only for src is root, validation can be updated 
addressing this special case.*
*I think below code would fix it correctly*
{code}
-      String srcPath = src.fs.makeQualified(src.path).toString();
-      String dstPath = dst.fs.makeQualified(target.path).toString();
+      Path srcPath = src.fs.makeQualified(src.path);
+      Path dstPath = dst.fs.makeQualified(target.path);
       if (dstPath.equals(srcPath)) {
         PathIOException e = new PathIOException(src.toString(),
             "are identical");
         e.setTargetPath(dstPath.toString());
         throw e;
       }
-      if (dstPath.startsWith(srcPath+Path.SEPARATOR)) {
+      if (srcPath.isRoot() || dstPath.toString().startsWith(srcPath.toString() 
+ Path.SEPARATOR)) {
{code}

*Also  it would be good if you can update the jira title and summary to reflect 
the special case*


> Validation of a path ended with a '/'
> -------------------------------------
>
>                 Key: HDFS-9123
>                 URL: https://issues.apache.org/jira/browse/HDFS-9123
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: fs
>            Reporter: Wei-Chiu Chuang
>            Assignee: Wei-Chiu Chuang
>            Priority: Minor
>         Attachments: HDFS-9123.001.patch, HDFS-9123.002.patch
>
>
> HDFS forbids copying from a directory to its subdirectory (e.g. hdfs dfs -cp 
> /abc /abc/xyz) as otherwise it could cause infinite copying (/abc/xyz/xyz, 
> /abc/xyz/xyz, /abc/xyz/xyz/xyz,... etc)
> However, if the source path is ended with a '/' path separator, the existing 
> validation for sub-directories fails. For example, copying from / to /abc 
> would cause infinite copying, until the disk space is filled up.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to