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:24:36 UTC
[camel] branch camel-2.x updated: CAMEL-13931 tempFileName
directory is not auto-created if it is relative before the endpoint path
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.x by this push:
new 6aed257 CAMEL-13931 tempFileName directory is not auto-created if it is relative before the endpoint path
6aed257 is described below
commit 6aed25780b8bc0d6289aa271744ce5935a09bdf7
Author: Dimitri Kotlovsky <ku...@web.de>
AuthorDate: Thu Sep 5 00:44:18 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/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java b/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
index 9224b87..db4e3d4 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
@@ -148,6 +148,9 @@ public class FileOperations implements GenericFileOperations<File> {
File endpointPath = endpoint.getFile();
File target = new File(directory);
+ // check if directory is a path
+ boolean isPath = directory.contains("/") || directory.contains("\\");
+
File path;
if (absolute) {
// absolute path
@@ -155,16 +158,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/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempFileNameTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempFileNameTest.java
index 7277284..d0e3376 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempFileNameTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempFileNameTest.java
@@ -31,11 +31,13 @@ public class FileProduceTempFileNameTest extends ContextTestSupport {
private String fileUrl = "file://target/tempandrename/?tempFileName=inprogress-${file:name.noext}.tmp";
private String parentFileUrl = "file://target/tempandrename/?tempFileName=../work/${file:name.noext}.tmp";
+ private String childFileUrl = "file://target/tempandrename/?tempFileName=work/${file:name.noext}.tmp";
@Override
@Before
public void setUp() throws Exception {
deleteDirectory("target/tempandrename");
+ deleteDirectory("target/work");
super.setUp();
}
@@ -66,7 +68,23 @@ public class FileProduceTempFileNameTest extends ContextTestSupport {
template.sendBodyAndHeader("direct:a", "Hello World", Exchange.FILE_NAME, "hello.txt");
File file = new File("target/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/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/tempandrename/work");
+ assertEquals("The generated temp directory should exist: " + file, true, file.exists());
}
@Test
@@ -84,6 +102,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);
}
};
}