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

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

LuciferYang commented on code in PR #8928:
URL: https://github.com/apache/hadoop/pull/8928#discussion_r4572866585


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java:
##########
@@ -472,11 +474,17 @@ public static boolean copy(FileSystem srcFS, FileStatus 
srcStatus,
         return false;
       }
       RemoteIterator<FileStatus> contents = srcFS.listStatusIterator(src);
+      boolean copiedAll = true;
       while (contents.hasNext()) {
         FileStatus next = contents.next();
-        copy(srcFS, next, dstFS,
+        if (!copy(srcFS, next, dstFS,
             new Path(dst, next.getPath().getName()),
-            deleteSource, overwrite, conf);
+            deleteSource, overwrite, conf)) {
+          copiedAll = false;
+        }
+      }
+      if (!copiedAll) {

Review Comment:
   Done. `copyToLocalFile()` now throws an `IOException` when `FileUtil.copy()` 
returns false, in `FileSystem` and in the `ChecksumFileSystem`, 
`LocalFileSystem` and `HarFileSystem` overrides. Two tests in 
`TestLocalFileSystem` call `moveToLocalFile()` through the base method and 
through the `LocalFileSystem` override, with one child's mkdirs failing. 
`copyFromLocalFile()` has the same gap; I'd leave it for a follow-up.





> FileUtil#copy ignores a failed child copy and deletes the source directory 
> when deleteSource is true
> ----------------------------------------------------------------------------------------------------
>
>                 Key: HADOOP-20064
>                 URL: https://issues.apache.org/jira/browse/HADOOP-20064
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: fs
>            Reporter: Yang Jie
>            Priority: Major
>              Labels: pull-request-available
>
> The recursive FileUtil#copy overloads (FileSystem to FileSystem, File to 
> FileSystem, FileSystem to File) copy each entry of a directory and ignore the 
> boolean that the copy of the entry returns. An entry returns false when 
> creating its destination directory fails without an exception, for example 
> when mkdirs returns false for permission denied on the local file system, or 
> when an FTP server refuses it. The parent goes on, returns true and, with 
> deleteSource=true, deletes the whole source directory.
> Example: {{hdfs.moveToLocalFile(/warehouse/t, /data/export)}} where 
> /data/export/t already exists and is not writable, and /warehouse/t only 
> contains partition directories. Every child mkdirs fails, nothing is copied, 
> and /warehouse/t is deleted permanently (delete does not use the trash). The 
> same code is used by LocalFileSystem#moveFromLocalFile and by the copy 
> fallback of RawLocalFileSystem#rename.
> The fix copies the remaining entries, remembers the failure, and returns 
> false before deleting the source directory, like copy(Path[]) in the same 
> class does for a failed source. Entries that were copied are still moved; the 
> failed entry and the directory itself are kept.



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