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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1c8305d  Check if log folder exists (#3165)
1c8305d is described below

commit 1c8305d4ec6b9dd004c6a5da4a0ee1259c9e6b9e
Author: Ali Ahmed <alahmed...@gmail.com>
AuthorDate: Wed Dec 12 17:49:47 2018 -0800

    Check if log folder exists (#3165)
    
    * Check if log folder exists
    
    * Switch to Files.createDirectories
---
 .../apache/pulsar/functions/runtime/ProcessRuntime.java | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git 
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
 
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
index 6a5f79a..d3046ba 100644
--- 
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
+++ 
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/ProcessRuntime.java
@@ -42,6 +42,8 @@ import org.apache.pulsar.functions.utils.Utils;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.List;
 import java.util.TimerTask;
 import java.util.concurrent.CompletableFuture;
@@ -139,15 +141,17 @@ class ProcessRuntime implements Runtime {
 
         // Note: we create the expected log folder before the function process 
logger attempts to create it
         // This is because if multiple instances are launched they can 
encounter a race condition creation of the dir.
+
         log.info("Creating function log directory {}", funcLogDir);
-        boolean success = createFolder(funcLogDir);
 
-        if (!success) {
-            log.error("Log folder could not be created : {}", funcLogDir);
+        try {
+            Files.createDirectories(Paths.get(funcLogDir));
+        } catch (IOException e) {
+            log.info("Exception when creating log folder : {}",funcLogDir, e);
             throw new RuntimeException("Log folder creation error");
         }
 
-        log.info("Created function log directory {}", funcLogDir);
+        log.info("Created or found function log directory {}", funcLogDir);
 
         startProcess();
         if (channel == null && stub == null) {
@@ -348,11 +352,6 @@ class ProcessRuntime implements Runtime {
         return true;
     }
 
-    private boolean createFolder(final String path) {
-        final boolean success = new File(path).mkdirs();
-        return success;
-    }
-
     private void tryExtractingDeathException() {
         InputStream errorStream = process.getErrorStream();
         try {

Reply via email to