From f16f5c6867eede06c211017018d1bad3fc5ac3ca Mon Sep 17 00:00:00 2001 From: Mauro Molinari Date: Wed, 3 Nov 2021 15:06:31 +0100 Subject: [PATCH] GH-3652: File gateway: don't try delete no file Fixes spring-projects/spring-integration#3652 Do not try to delete non-existing file in `FileExistMode.REPLACE` in the `AbstractRemoteFileOutboundGateway` **Cherry-pick to `5.4.x` & `5.3.x`** --- .../remote/gateway/AbstractRemoteFileOutboundGateway.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java index 7af96d235e..5c8dc5d21b 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java @@ -68,6 +68,7 @@ import org.springframework.util.StringUtils; * * @author Gary Russell * @author Artem Bilan + * @author Mauro Molinari * * @since 2.1 */ @@ -1082,9 +1083,9 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply FileExistsMode existsMode = this.fileExistsMode; boolean appending = FileExistsMode.APPEND.equals(existsMode); boolean exists = localFile.exists(); - boolean replacing = FileExistsMode.REPLACE.equals(existsMode) - || (exists && FileExistsMode.REPLACE_IF_MODIFIED.equals(existsMode) - && localFile.lastModified() != getModified(fileInfo)); + boolean replacing = exists && (FileExistsMode.REPLACE.equals(existsMode) + || (FileExistsMode.REPLACE_IF_MODIFIED.equals(existsMode) + && localFile.lastModified() != getModified(fileInfo))); if (!exists || appending || replacing) { OutputStream outputStream; String tempFileName = localFile.getAbsolutePath() + this.remoteFileTemplate.getTemporaryFileSuffix();