You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2014/03/17 17:56:08 UTC
git commit: [SSHD-298] ScpClient failures on Windows with absolute
paths
Repository: mina-sshd
Updated Branches:
refs/heads/master 4bee7cada -> c8fcdd461
[SSHD-298] ScpClient failures on Windows with absolute paths
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/c8fcdd46
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/c8fcdd46
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/c8fcdd46
Branch: refs/heads/master
Commit: c8fcdd4618902224e7a92061696196bab69d1128
Parents: 4bee7ca
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon Mar 17 17:55:25 2014 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon Mar 17 17:55:25 2014 +0100
----------------------------------------------------------------------
.../common/file/nativefs/NativeSshFile.java | 11 ++++++++-
.../src/test/java/org/apache/sshd/ScpTest.java | 26 ++++++++++++++++++++
.../common/file/nativefs/NativeSshFileTest.java | 5 ++++
3 files changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/c8fcdd46/sshd-core/src/main/java/org/apache/sshd/common/file/nativefs/NativeSshFile.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/file/nativefs/NativeSshFile.java b/sshd-core/src/main/java/org/apache/sshd/common/file/nativefs/NativeSshFile.java
index eef3a73..ee2626c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/file/nativefs/NativeSshFile.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/file/nativefs/NativeSshFile.java
@@ -453,6 +453,15 @@ public class NativeSshFile implements SshFile {
return normalizedPathName;
}
+ public final static String normalizePath(final String pathName) {
+ // Support windows drive as
+ if (pathName.matches("[A-Z]:\\\\.*")) {
+ return "/" + normalizeSeparateChar(pathName);
+ } else {
+ return normalizeSeparateChar(pathName);
+ }
+ }
+
/**
* Get the physical canonical file name. It works like
* File.getCanonicalPath().
@@ -482,7 +491,7 @@ public class NativeSshFile implements SshFile {
normalizedRootDir += '/';
}
- String normalizedFileName = normalizeSeparateChar(fileName);
+ String normalizedFileName = normalizePath(fileName);
String resArg;
String normalizedCurrDir = currDir;
if (normalizedFileName.charAt(0) != '/') {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/c8fcdd46/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ScpTest.java b/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
index 49913aa..48baa8c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
@@ -100,6 +100,32 @@ public class ScpTest extends BaseTest {
}
@Test
+ public void testUploadAbsoluteDriveLetter() throws Exception {
+ SshClient client = SshClient.setUpDefaultClient();
+ client.start();
+ ClientSession session = client.connect("localhost", port).await().getSession();
+ session.authPassword("test", "test").await();
+
+ ScpClient scp = session.createScpClient();
+
+ String data = "0123456789\n";
+
+ File root = new File("target/scp");
+ Utils.deleteRecursive(root);
+ root.mkdirs();
+ new File(root, "local").mkdirs();
+ assertTrue(root.exists());
+
+
+ writeFile(new File("target/scp/local/out.txt"), data);
+ new File(root, "remote").mkdirs();
+ scp.upload(new File("target/scp/local/out.txt").getAbsolutePath(), "/" + new File("target/scp/remote/out.txt").getAbsolutePath().replace(File.separatorChar, '/'));
+ assertFileLength(new File("target/scp/remote/out.txt"), data.length(), 5000);
+ scp.upload(new File("target/scp/local/out.txt").getAbsolutePath(), new File("target/scp/remote/out2.txt").getAbsolutePath());
+ assertFileLength(new File("target/scp/remote/out2.txt"), data.length(), 5000);
+ }
+
+ @Test
public void testScpNativeOnSingleFile() throws Exception {
SshClient client = SshClient.setUpDefaultClient();
client.start();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/c8fcdd46/sshd-core/src/test/java/org/apache/sshd/common/file/nativefs/NativeSshFileTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/file/nativefs/NativeSshFileTest.java b/sshd-core/src/test/java/org/apache/sshd/common/file/nativefs/NativeSshFileTest.java
index 5781df3..0d6f77c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/file/nativefs/NativeSshFileTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/file/nativefs/NativeSshFileTest.java
@@ -27,6 +27,11 @@ public class NativeSshFileTest extends BaseTest {
@Test
public void testResolve() {
+ assertEquals("/Z:/git/mina-sshd/sshd-core/target/scp/remote/out.txt",
+ NativeSshFile.getPhysicalName("/", "Z:\\git\\mina-sshd\\sshd-core", "Z:\\git\\mina-sshd\\sshd-core\\target\\scp\\remote\\out.txt", false));
+ assertEquals("/Z:/git/mina-sshd/sshd-core/target/scp/remote/out.txt",
+ NativeSshFile.getPhysicalName("/", "Z:\\git\\mina-sshd\\sshd-core", "/Z:/git/mina-sshd/sshd-core/target/scp/remote/out.txt", false));
+
assertEquals("/bar", NativeSshFile.getPhysicalName("/", "/foo", "/bar", false));
assertEquals("/bar", NativeSshFile.getPhysicalName("/", "/", "/bar", false));
assertEquals("/bar", NativeSshFile.getPhysicalName("/", "/", "bar", false));