Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,29 @@ public boolean buildDirectory(String directory, boolean absolute) throws Generic
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
path = target;
} 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -66,7 +68,23 @@ public void testTempFileName() throws Exception {
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
Expand All @@ -84,6 +102,8 @@ protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:a").to(fileUrl);
from("direct:b").to(parentFileUrl);
from("direct:c").to(childFileUrl);
}
};
}
Expand Down