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 2017/01/22 18:51:57 UTC
[11/11] camel git commit: CAMEL-10737: file component should support
parent folder in tempFileName
CAMEL-10737: file component should support parent folder in tempFileName
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/06c6cd75
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/06c6cd75
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/06c6cd75
Branch: refs/heads/master
Commit: 06c6cd757c4e4c6cc4ec97fbfa1daf9aeb2cd14d
Parents: 13e5259
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Jan 22 19:20:45 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Jan 22 19:20:45 2017 +0100
----------------------------------------------------------------------
.../apache/camel/component/file/GenericFileProducer.java | 3 +++
.../src/main/java/org/apache/camel/util/FileUtil.java | 11 ++++++++++-
.../component/file/FileProduceTempFileNameTest.java | 11 +++++++++++
3 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/06c6cd75/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
index b27af40..a4769ec 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
@@ -389,6 +389,9 @@ public class GenericFileProducer<T> extends DefaultProducer {
answer = normalizePath(answer);
}
+ // stack path in case the temporary file uses .. paths
+ answer = FileUtil.compactPath(answer, getFileSeparator());
+
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/06c6cd75/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 81585fc..fee4be4 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
@@ -267,14 +267,23 @@ public final class FileUtil {
* and uses OS specific file separators (eg {@link java.io.File#separator}).
*/
public static String compactPath(String path) {
- return compactPath(path, File.separatorChar);
+ return compactPath(path, "" + File.separatorChar);
}
/**
* Compacts a path by stacking it and reducing <tt>..</tt>,
* and uses the given separator.
+ *
*/
public static String compactPath(String path, char separator) {
+ return compactPath(path, "" + separator);
+ }
+
+ /**
+ * Compacts a path by stacking it and reducing <tt>..</tt>,
+ * and uses the given separator.
+ */
+ public static String compactPath(String path, String separator) {
if (path == null) {
return null;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/06c6cd75/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempFileNameTest.java
----------------------------------------------------------------------
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 a136046..243c169 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
@@ -29,6 +29,7 @@ import org.apache.camel.builder.RouteBuilder;
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";
@Override
protected void setUp() throws Exception {
@@ -63,6 +64,16 @@ public class FileProduceTempFileNameTest extends ContextTestSupport {
assertEquals("The generated file should exists: " + file, true, file.exists());
}
+ public void testCreateParentTempFileName() throws Exception {
+ Endpoint endpoint = context.getEndpoint(parentFileUrl);
+ GenericFileProducer<?> producer = (GenericFileProducer<?>) endpoint.createProducer();
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setHeader(Exchange.FILE_NAME, "claus.txt");
+
+ String tempFileName = producer.createTempFileName(exchange, "target/tempandrename/claus.txt");
+ assertDirectoryEquals("target/work/claus.tmp", tempFileName);
+ }
+
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {