GH-9129: SFTP: Remove extra / for the file_remoteDirectory header

Fixes: #9129

If `.remoteDirectory("/sftpSource")`, then `FileHeaders.REMOTE_DIRECTORY` is `//sftpSource`

* Fix `AbstractInboundFileSynchronizer` to not add `/` if one is already present in the beginning of the `remoteDirectoryPath`

(cherry picked from commit d87a7098ca)
This commit is contained in:
Artem Bilan
2024-05-08 15:48:08 -04:00
committed by Spring Builds
parent a7a9d47850
commit f18626fdce
2 changed files with 6 additions and 2 deletions

View File

@@ -505,7 +505,10 @@ public abstract class AbstractInboundFileSynchronizer<F>
try {
String remoteFileMetadata =
new URI(protocol(), null, host, Integer.parseInt(port),
'/' + remoteDirectoryPath, null, remoteFileName)
remoteDirectoryPath.charAt(0) == '/'
? remoteDirectoryPath :
'/' + remoteDirectoryPath,
null, remoteFileName)
.toString();
this.remoteFileMetadataStore.put(buildMetadataKey(localFile), remoteFileMetadata);
}