Skip to content

Commit

Permalink
GH-9453: Correct separator when checking smb path
Browse files Browse the repository at this point in the history
Fixes: #9453
Issue link: #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`**
  • Loading branch information
pfosser authored Sep 13, 2024
1 parent a6c3a30 commit 4cccee7
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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;
Expand Down Expand Up @@ -54,15 +53,14 @@
* @author Prafull Kumar Soni
* @author Gregory Bragg
* @author Adam Jones
* @author Paolo Fosser
*
* @since 6.0
*/
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;
Expand Down Expand Up @@ -338,7 +336,7 @@ public boolean isDirectory(String _path) throws IOException {
* @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);
Expand Down

0 comments on commit 4cccee7

Please sign in to comment.