This is an automated email from the ASF dual-hosted git repository.

srowen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 0bb54ec0682 [SPARK-39256][CORE] Reduce multiple file attribute calls 
of `JavaUtils#deleteRecursivelyUsingJavaIO`
0bb54ec0682 is described below

commit 0bb54ec0682ad532808b9507307e66b426d31984
Author: yangjie01 <yangji...@baidu.com>
AuthorDate: Tue May 24 09:26:06 2022 -0500

    [SPARK-39256][CORE] Reduce multiple file attribute calls of 
`JavaUtils#deleteRecursivelyUsingJavaIO`
    
    ### What changes were proposed in this pull request?
    This pr is a minor fix: `JavaUtils#deleteRecursivelyUsingJavaIO` method  
performs multiple file attribute calls, this pr change to use 
`Files.readAttributes` instead of them.
    
    ### Why are the changes needed?
    Reduce multiple file attribute calls.
    
    ### Does this PR introduce _any_ user-facing change?
    No
    
    ### How was this patch tested?
    Pass Github Actions
    
    Closes #36636 from LuciferYang/use-BasicFileAttributes.
    
    Lead-authored-by: yangjie01 <yangji...@baidu.com>
    Co-authored-by: YangJie <yangji...@baidu.com>
    Signed-off-by: Sean Owen <sro...@gmail.com>
---
 .../src/main/java/org/apache/spark/network/util/JavaUtils.java    | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/common/network-common/src/main/java/org/apache/spark/network/util/JavaUtils.java
 
b/common/network-common/src/main/java/org/apache/spark/network/util/JavaUtils.java
index f699bdd95c3..544fe16a569 100644
--- 
a/common/network-common/src/main/java/org/apache/spark/network/util/JavaUtils.java
+++ 
b/common/network-common/src/main/java/org/apache/spark/network/util/JavaUtils.java
@@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
 import java.nio.channels.ReadableByteChannel;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.util.Locale;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
@@ -123,7 +124,9 @@ public class JavaUtils {
   private static void deleteRecursivelyUsingJavaIO(
       File file,
       FilenameFilter filter) throws IOException {
-    if (file.isDirectory() && !isSymlink(file)) {
+    BasicFileAttributes fileAttributes =
+      Files.readAttributes(file.toPath(), BasicFileAttributes.class);
+    if (fileAttributes.isDirectory() && !isSymlink(file)) {
       IOException savedIOException = null;
       for (File child : listFilesSafely(file, filter)) {
         try {
@@ -139,7 +142,8 @@ public class JavaUtils {
     }
 
     // Delete file only when it's a normal file or an empty directory.
-    if (file.isFile() || (file.isDirectory() && listFilesSafely(file, 
null).length == 0)) {
+    if (fileAttributes.isRegularFile() ||
+      (fileAttributes.isDirectory() && listFilesSafely(file, null).length == 
0)) {
       boolean deleted = file.delete();
       // Delete can also fail if the file simply did not exist.
       if (!deleted && file.exists()) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to