CAMEL-8121 Fixed the issue that Infinite Loop Within Camel if the temp file 
directory is not writable


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/85f6210e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/85f6210e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/85f6210e

Branch: refs/heads/camel-2.13.x
Commit: 85f6210e497e80a973bda340389e2ea111e0e2d7
Parents: aca0256
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Thu Dec 4 10:37:18 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Thu Dec 4 10:42:14 2014 +0800

----------------------------------------------------------------------
 .../main/java/org/apache/camel/util/FileUtil.java  | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/85f6210e/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java 
b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index 61694e3..abedc64 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -324,13 +324,28 @@ public final class FileUtil {
                                    + " does not exist, please set 
java.io.tempdir"
                                    + " to an existing directory");
         }
+        
+        if (!checkExists.canWrite()) {
+            throw new RuntimeException("The directory "
+                + checkExists.getAbsolutePath()
+                + " is not writable, please set java.io.tempdir"
+                + " to a writable directory");
+        }
 
         // create a sub folder with a random number
         Random ran = new Random();
         int x = ran.nextInt(1000000);
-
         File f = new File(s, "camel-tmp-" + x);
+        int count = 0;
+        // Let us just try 100 times to avoid the infinite loop
         while (!f.mkdir()) {
+            count++;
+            if (count >= 100) {
+                throw new RuntimeException("Camel cannot a temp directory from"
+                    + checkExists.getAbsolutePath()
+                    + " 100 times , please set java.io.tempdir"
+                    + " to a writable directory");
+            }
             x = ran.nextInt(1000000);
             f = new File(s, "camel-tmp-" + x);
         }

Reply via email to