[
https://issues.apache.org/jira/browse/HADOOP-20064?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18144742#comment-18144742
]
ASF GitHub Bot commented on HADOOP-20064:
-----------------------------------------
slfan1989 commented on code in PR #8928:
URL: https://github.com/apache/hadoop/pull/8928#discussion_r4572479717
##########
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:
Thanks for fixing the source directory deletion!
`FileSystem.copyToLocalFile()` currently ignores the `false` returned here,
so `moveToLocalFile()` still returns normally when a child directory cannot be
copied.
I reproduced this with a destination that returns `false` from `mkdirs()`
for one child.
The source file is preserved, but the destination file is missing and the
caller sees no exception.
Could we have `copyToLocalFile()` throw an `IOException` when
`FileUtil.copy()` returns `false`, and add a regression test through
`moveToLocalFile()`?
> 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]