This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new c51374ab7de9 CAMEL-24095: camel-file - Add missing Move branch to
handleExistingTarget
c51374ab7de9 is described below
commit c51374ab7de9f92f2f6a3b58f5f0cd7f726bb98c
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jul 16 07:21:59 2026 +0200
CAMEL-24095: camel-file - Add missing Move branch to handleExistingTarget
GenericFileProducer.handleExistingTarget (the non-eager path used when
writing via tempFileName/tempPrefix with eagerDeleteTargetFile=false)
handled Ignore, Fail, and Override but had no Move branch. This meant
fileExist=Move with eagerDeleteTargetFile=false and tempFileName
silently overwrote the existing target instead of moving it to the
moveExisting destination.
The eager twin handleExistingTargetEager has had the Move branch since
CAMEL-15822 (2020), but the non-eager method was never patched. Add the
missing Move case mirroring the eager-path code.
Closes #24750
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../camel/component/file/GenericFileProducer.java | 3 +++
.../file/FileProducerMoveExistingTest.java | 21 ++++++++++++++-------
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
index ab50db46a208..03932fb9824d 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
@@ -254,6 +254,9 @@ public class GenericFileProducer<T> extends
DefaultAsyncProducer {
return doIgnore(target);
} else if (endpoint.getFileExist() == GenericFileExist.Fail) {
throwFileAlreadyExistException(target);
+ } else if (endpoint.getFileExist() == GenericFileExist.Move) {
+ // move any existing file first
+
this.endpoint.getMoveExistingFileStrategy().moveExistingFile(endpoint,
operations, target);
} else if (endpoint.getFileExist() == GenericFileExist.Override) {
// we override the target so we do this by deleting
// it so the temp file can be renamed later
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerMoveExistingTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerMoveExistingTest.java
index ce76d156154f..4e8228fd12d9 100644
---
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerMoveExistingTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerMoveExistingTest.java
@@ -107,14 +107,21 @@ public class FileProducerMoveExistingTest extends
ContextTestSupport {
template.sendBodyAndHeader(
fileUri("?tempFileName=${file:onlyname}.temp&fileExist=Move&moveExisting=${file:parent}/renamed-${file:onlyname}&eagerDeleteTargetFile=false"),
"Second File", Exchange.FILE_NAME, filename);
- // we should be okay as we will just delete any existing file
- template.sendBodyAndHeader(
-
fileUri("?tempFileName=${file:onlyname}.temp&fileExist=Move&moveExisting=${file:parent}/renamed-${file:onlyname}&eagerDeleteTargetFile=false"),
- "Third File", Exchange.FILE_NAME, filename);
- // we could write the new file so the old context should be moved
- assertFileExists(testFile(filename), "Third File");
- // and the renamed file should not be overridden
+ // should fail because the move destination already exists and
eagerDeleteTargetFile=false
+ CamelExecutionException e =
assertThrows(CamelExecutionException.class, () -> {
+ template.sendBodyAndHeader(
+
fileUri("?tempFileName=${file:onlyname}.temp&fileExist=Move&moveExisting=${file:parent}/renamed-${file:onlyname}&eagerDeleteTargetFile=false"),
+ "Third File", Exchange.FILE_NAME, filename);
+ }, "Should have thrown an exception");
+
+ GenericFileOperationFailedException cause
+ =
assertIsInstanceOf(GenericFileOperationFailedException.class, e.getCause());
+ assertTrue(cause.getMessage().startsWith("Cannot move existing file"));
+
+ // we could not write the new file so the previous content should be
there
+ assertFileExists(testFile(filename), "Second File");
+ // and the renamed file should be untouched
assertFileExists(testFile("renamed-" + filename), "First File");
}