FrankinRUC commented on a change in pull request #3431:
URL: https://github.com/apache/hadoop/pull/3431#discussion_r707954677
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
##########
@@ -182,7 +183,7 @@ public static boolean fullyDelete(final File dir, boolean
tryGrantPermissions) {
return true;
}
// handle nonempty directory deletion
- if (!fullyDeleteContents(dir, tryGrantPermissions)) {
+ if (!FileUtils.isSymlink(dir) && !fullyDeleteContents(dir,
tryGrantPermissions)) {
Review comment:
dir.isDirectory() cannot tell whether dir is a symlink or not. Here is a
test:
Environment:
```
total 8
-rw-r--r-- 1 foo bar 328B 9 14 14:28 Main.java
lrwxr-xr-x 1 foo bar 8B 9 14 14:18 sym-test-dir -> test-dir
lrwxr-xr-x 1 foo bar 9B 9 14 14:18 sym-test-file -> test-file
drwxr-xr-x 2 foo bar 64B 9 14 14:18 test-dir
-rw-r--r-- 1 foo bar 0B 9 14 14:18 test-file
```
Test Code:
```java
import java.io.*;
import java.util.Arrays;
class Main {
public static void main(String[] args) {
for (String path : Arrays.asList(new String[]{"test-dir",
"test-file", "sym-test-dir", "sym-test-file"})) {
System.out.println(String.format("%s\t%s", path, new
File(path).isDirectory()));
}
}
}
```
Test Result:
```
test-dir true
test-file false
sym-test-dir true
sym-test-file false
```
So I think just add isSymlink checking is ok, since original code can handle
file or file symlink param.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]