Skip to content

Commit e94f4e1

Browse files
committed
* Remove trailing slashes from remote dirs to create
1 parent ce47595 commit e94f4e1

File tree

2 files changed

+3
-46
lines changed

2 files changed

+3
-46
lines changed

spring-integration-sftp/src/test/java/org/springframework/integration/sftp/SftpTestSupport.java

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,9 @@
1717
package org.springframework.integration.sftp;
1818

1919
import java.io.File;
20-
import java.io.IOException;
21-
import java.nio.file.FileSystem;
22-
import java.nio.file.InvalidPathException;
23-
import java.nio.file.Path;
2420
import java.util.Collections;
25-
import java.util.Objects;
2621

27-
import org.apache.sshd.common.file.root.RootedFileSystem;
28-
import org.apache.sshd.common.file.root.RootedFileSystemProvider;
29-
import org.apache.sshd.common.file.root.RootedPath;
3022
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
31-
import org.apache.sshd.common.session.SessionContext;
32-
import org.apache.sshd.common.util.io.IoUtils;
3323
import org.apache.sshd.server.SshServer;
3424
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
3525
import org.apache.sshd.sftp.client.SftpClient;
@@ -81,7 +71,7 @@ public static void createServer() throws Exception {
8171
});
8272
sftpFactory.addSftpEventListener(EVENT_LISTENER);
8373
server.setSubsystemFactories(Collections.singletonList(sftpFactory));
84-
server.setFileSystemFactory(new FixedVirtualFileSystemFactory(getRemoteTempFolder()));
74+
server.setFileSystemFactory(new VirtualFileSystemFactory(getRemoteTempFolder().toPath()));
8575
server.start();
8676
port = server.getPort();
8777
}
@@ -111,37 +101,4 @@ public static void stopServer() throws Exception {
111101
}
112102
}
113103

114-
private static class FixedVirtualFileSystemFactory extends VirtualFileSystemFactory {
115-
116-
FixedVirtualFileSystemFactory(File defaultHomeDir) {
117-
super(defaultHomeDir.toPath());
118-
}
119-
120-
@Override
121-
public FileSystem createFileSystem(SessionContext session) throws IOException {
122-
Path dir = getUserHomeDir(session);
123-
if (dir == null) {
124-
throw new InvalidPathException(session.getUsername(), "Cannot resolve home directory");
125-
}
126-
127-
return new FixedRootedFileSystemProvider().newFileSystem(dir, Collections.emptyMap());
128-
}
129-
130-
private static class FixedRootedFileSystemProvider extends RootedFileSystemProvider {
131-
132-
protected Path resolveLocalPath(RootedPath path) {
133-
Objects.requireNonNull(path, "No rooted path to resolve");
134-
RootedFileSystem rfs = path.getFileSystem();
135-
Path root = rfs.getRoot();
136-
Path resolved = IoUtils.chroot(root, path).normalize();
137-
if (!resolved.startsWith(root)) {
138-
throw new InvalidPathException(root.toString(), "Not under root");
139-
}
140-
return resolved;
141-
}
142-
143-
}
144-
145-
}
146-
147104
}

spring-integration-sftp/src/test/java/org/springframework/integration/sftp/session/SftpRemoteFileTemplateTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public void testINT3412AppendStatRmdir() {
7777
template.afterPropertiesSet();
7878

7979
template.execute(session -> {
80-
session.mkdir("/foo/");
81-
return session.mkdir("/foo/bar/");
80+
session.mkdir("/foo");
81+
return session.mkdir("/foo/bar");
8282
});
8383
template.append(new GenericMessage<>("foo"));
8484
template.append(new GenericMessage<>("bar"));

0 commit comments

Comments
 (0)