You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/09/05 07:11:02 UTC

[camel] branch master updated (77e57f7 -> bb746b4)

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

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 77e57f7  CAMEL-13753: trigger the `master` build of website
     new ed70c1f  CAMEL-13931 tempFileName directory is not auto-created if it is relative before the endpoint path
     new bb746b4  CAMEL-13931 tempFileName directory is not auto-created if it is relative before the endpoint path

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/file/FileOperations.java       | 12 +++++++++---
 .../file/FileProduceTempFileNameTest.java          | 22 +++++++++++++++++++++-
 2 files changed, 30 insertions(+), 4 deletions(-)


[camel] 01/02: CAMEL-13931 tempFileName directory is not auto-created if it is relative before the endpoint path

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ed70c1f93695e38bb4d4f99a3445b16b7901446e
Author: Dimitri Kotlovsky <ku...@web.de>
AuthorDate: Wed Sep 4 00:32:51 2019 +0200

    CAMEL-13931 tempFileName directory is not auto-created if it is relative before the endpoint path
---
 .../camel/component/file/FileOperations.java       | 12 +++++++++---
 .../file/FileProduceTempFileNameTest.java          | 22 +++++++++++++++++++++-
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
index 16aade7..20aa69e 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
@@ -157,6 +157,9 @@ public class FileOperations implements GenericFileOperations<File> {
         File endpointPath = endpoint.getFile();
         File target = new File(directory);
 
+        // check if directory is a path
+        boolean isPath = Math.max(directory.lastIndexOf("/"), directory.lastIndexOf("\\")) != -1;
+
         File path;
         if (absolute) {
             // absolute path
@@ -164,16 +167,19 @@ public class FileOperations implements GenericFileOperations<File> {
         } else if (endpointPath.equals(target)) {
             // its just the root of the endpoint path
             path = endpointPath;
-        } else {
+        } else if (isPath) {
             // relative after the endpoint path
             String afterRoot = StringHelper.after(directory, endpointPath.getPath() + File.separator);
             if (ObjectHelper.isNotEmpty(afterRoot)) {
                 // dir is under the root path
                 path = new File(endpoint.getFile(), afterRoot);
             } else {
-                // dir is relative to the root path
-                path = new File(endpoint.getFile(), directory);
+                // dir path is relative to the root path
+                path = new File(directory);
             }
+        } else {
+            // dir is a child of the root path
+            path = new File(endpoint.getFile(), directory);
         }
 
         // We need to make sure that this is thread-safe and only one thread tries to create the path directory at the same time.
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempFileNameTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempFileNameTest.java
index 0aba449..f09d03c 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempFileNameTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempFileNameTest.java
@@ -32,11 +32,13 @@ public class FileProduceTempFileNameTest extends ContextTestSupport {
 
     private String fileUrl = "file://target/data/tempandrename/?tempFileName=inprogress-${file:name.noext}.tmp";
     private String parentFileUrl = "file://target/data/tempandrename/?tempFileName=../work/${file:name.noext}.tmp";
+    private String childFileUrl = "file://target/data/tempandrename/?tempFileName=work/${file:name.noext}.tmp";
 
     @Override
     @Before
     public void setUp() throws Exception {
         deleteDirectory("target/data/tempandrename");
+        deleteDirectory("target/data/work");
         super.setUp();
     }
 
@@ -67,7 +69,23 @@ public class FileProduceTempFileNameTest extends ContextTestSupport {
         template.sendBodyAndHeader("direct:a", "Hello World", Exchange.FILE_NAME, "hello.txt");
 
         File file = new File("target/data/tempandrename/hello.txt");
-        assertEquals("The generated file should exists: " + file, true, file.exists());
+        assertEquals("The generated file should exist: " + file, true, file.exists());
+    }
+
+    @Test
+    public void testParentTempFileName() throws Exception {
+        template.sendBodyAndHeader("direct:b", "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+        File file = new File("target/data/work");
+        assertEquals("The generated temp directory should exist: " + file, true, file.exists());
+    }
+
+    @Test
+    public void testChildTempFileName() throws Exception {
+        template.sendBodyAndHeader("direct:c", "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+        File file = new File("target/data/tempandrename/work");
+        assertEquals("The generated temp directory should exist: " + file, true, file.exists());
     }
 
     @Test
@@ -86,6 +104,8 @@ public class FileProduceTempFileNameTest extends ContextTestSupport {
         return new RouteBuilder() {
             public void configure() throws Exception {
                 from("direct:a").to(fileUrl);
+                from("direct:b").to(parentFileUrl);
+                from("direct:c").to(childFileUrl);
             }
         };
     }


[camel] 02/02: CAMEL-13931 tempFileName directory is not auto-created if it is relative before the endpoint path

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit bb746b445087be51eba51d0c8429759fa06b8321
Author: Dimitri Kotlovsky <ku...@web.de>
AuthorDate: Wed Sep 4 21:01:30 2019 +0200

    CAMEL-13931 tempFileName directory is not auto-created if it is relative before the endpoint path
---
 .../src/main/java/org/apache/camel/component/file/FileOperations.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
index 20aa69e..c74746e 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
@@ -158,7 +158,7 @@ public class FileOperations implements GenericFileOperations<File> {
         File target = new File(directory);
 
         // check if directory is a path
-        boolean isPath = Math.max(directory.lastIndexOf("/"), directory.lastIndexOf("\\")) != -1;
+        boolean isPath = directory.contains("/") || directory.contains("\\");
 
         File path;
         if (absolute) {