You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@uniffle.apache.org by "kaijchen (via GitHub)" <gi...@apache.org> on 2023/02/17 02:51:42 UTC

[GitHub] [incubator-uniffle] kaijchen commented on a diff in pull request #616: [#571][FOLLOWUP] fix: don't recreate base dir if it's already an dir

kaijchen commented on code in PR #616:
URL: https://github.com/apache/incubator-uniffle/pull/616#discussion_r1109235399


##########
storage/src/main/java/org/apache/uniffle/storage/common/LocalStorage.java:
##########
@@ -81,9 +81,16 @@ private LocalStorage(Builder builder) {
       if (isEmptyAndWritableDir(baseFolder)) {
         LOG.warn("Base directory is already an empty dir, skip init");
       } else {
-        FileUtils.deleteDirectory(baseFolder);
-        if (!baseFolder.mkdirs()) {
-          throw new IOException("Failed to create base folder: " + basePath);
+        // base folder could be the mounted path, which could not be deleted.
+        // just clean the directory instead.
+        if (baseFolder.isDirectory()) {
+          LOG.info("Base directory is already existed, just clean the directory");
+          FileUtils.cleanDirectory(baseFolder);
+        } else {
+          FileUtils.deleteDirectory(baseFolder);
+          if (!baseFolder.mkdirs()) {
+            throw new IOException("Failed to create base folder: " + basePath);
+          }
         }
       }

Review Comment:
   I mean this
   ```java
         } else if (baseFolder.isDirectory()) {
           // base folder could be the mounted path, which could not be deleted.
           // just clean the directory instead.
           LOG.info("Base directory is already existed, just clean the directory");
           FileUtils.cleanDirectory(baseFolder);
         } else {
           FileUtils.deleteDirectory(baseFolder);
           if (!baseFolder.mkdirs()) {
             throw new IOException("Failed to create base folder: " + basePath);
           }
         }
   ```



##########
storage/src/main/java/org/apache/uniffle/storage/common/LocalStorage.java:
##########
@@ -81,9 +81,16 @@ private LocalStorage(Builder builder) {
       if (isEmptyAndWritableDir(baseFolder)) {
         LOG.warn("Base directory is already an empty dir, skip init");
       } else {
-        FileUtils.deleteDirectory(baseFolder);
-        if (!baseFolder.mkdirs()) {
-          throw new IOException("Failed to create base folder: " + basePath);
+        // base folder could be the mounted path, which could not be deleted.
+        // just clean the directory instead.
+        if (baseFolder.isDirectory()) {
+          LOG.info("Base directory is already existed, just clean the directory");
+          FileUtils.cleanDirectory(baseFolder);
+        } else {
+          FileUtils.deleteDirectory(baseFolder);

Review Comment:
   Also, why call `FileUtils.deleteDirectory` if `baseFolder` is not a directory?



-- 
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: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org