GH-9453: Correct separator when checking smb path

Fixes: #9453
Issue link: https://github.com/spring-projects/spring-integration/issues/9453

On a smb file upload, to detect the need for new remote directories,
the remote path was checked for the local filesystem path separator.
On Windows that is \\ which is never found in a smb path, so the
necessary remote path was not created and the operation failed.

Use the correct separator which was already available as a constant.

**Auto-cherry-pick to `6.3.x` & `6.2.x`**
This commit is contained in:
pfosser
2024-09-13 21:41:25 +02:00
committed by GitHub
parent a6c3a30d5b
commit 4cccee7c3a

View File

@@ -23,7 +23,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.file.FileSystems;
import java.util.Arrays;
import jcifs.smb.SmbException;
@@ -54,6 +53,7 @@ import org.springframework.util.StringUtils;
* @author Prafull Kumar Soni
* @author Gregory Bragg
* @author Adam Jones
* @author Paolo Fosser
*
* @since 6.0
*/
@@ -61,8 +61,6 @@ public class SmbSession implements Session<SmbFile> {
private static final LogAccessor logger = new LogAccessor(SmbSession.class);
private static final String FILE_SEPARATOR = FileSystems.getDefault().getSeparator();
private static final String SMB_FILE_SEPARATOR = "/";
private final SmbShare smbShare;
@@ -338,7 +336,7 @@ public class SmbSession implements Session<SmbFile> {
* @throws IOException on error conditions returned by a CIFS server
*/
String mkdirs(String _path) throws IOException {
int idxPath = _path.lastIndexOf(FILE_SEPARATOR);
int idxPath = _path.lastIndexOf(SMB_FILE_SEPARATOR);
if (idxPath > -1) {
String path = _path.substring(0, idxPath + 1);
mkdir(path);