You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wagon-commits@maven.apache.org by br...@apache.org on 2006/01/05 07:35:31 UTC
svn commit: r366098 - in
/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh:
AbstractSshWagon.java ScpWagon.java
Author: brett
Date: Wed Jan 4 22:35:26 2006
New Revision: 366098
URL: http://svn.apache.org/viewcvs?rev=366098&view=rev
Log:
[WAGONSSH-28] adjust i/o handling to better match protocol as far as I can determine from Ganymede SSH2
Modified:
maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java?rev=366098&r1=366097&r2=366098&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java Wed Jan 4 22:35:26 2006
@@ -46,10 +46,13 @@
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
+import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -72,7 +75,7 @@
public static final String EXEC_CHANNEL = "exec";
- private static final int LINE_BUFFER_SIZE = 256;
+ private static final int LINE_BUFFER_SIZE = 8192;
private static final byte LF = '\n';
@@ -82,6 +85,8 @@
private UIKeyboardInteractive uIKeyboardInteractive;
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
+
public void openConnection()
throws AuthenticationException
{
@@ -278,18 +283,35 @@
channel.connect();
- sendEom( out );
+ BufferedReader r = new BufferedReader( new InputStreamReader( err ) );
- String line = readLine( err );
+ List output = null;
- if ( line != null )
+ while ( true )
{
- // ignore this error
+ String line = r.readLine();
+ if ( line == null )
+ {
+ break;
+ }
+
+ if ( output == null )
+ {
+ output = new ArrayList();
+ }
+
+ // ignore this error. TODO: output a warning
if ( !line.startsWith( "Could not chdir to home directory" ) )
{
- throw new CommandExecutionException( line );
+ output.add( line );
}
}
+
+ if ( output != null && !output.isEmpty() )
+ {
+ throw new CommandExecutionException(
+ "Exit code: " + channel.getExitStatus() + " - " + StringUtils.join( output.iterator(), "\n" ) );
+ }
}
catch ( JSchException e )
{
@@ -314,22 +336,30 @@
protected String readLine( InputStream in )
throws IOException
{
- byte[] buf = new byte[LINE_BUFFER_SIZE];
+ StringBuffer sb = new StringBuffer();
- String result = null;
- for ( int i = 0; result == null; i++ )
+ while ( true )
{
- if ( in.read( buf, i, 1 ) != 1 )
+ if ( sb.length() > LINE_BUFFER_SIZE )
{
- return null;
+ throw new IOException( "Remote server sent a too long line" );
}
- if ( buf[i] == LF )
+ int c = in.read();
+
+ if ( c < 0 )
{
- result = new String( buf, 0, i );
+ throw new IOException( "Remote connection terminated unexpectedly." );
}
+
+ if ( c == LF )
+ {
+ break;
+ }
+
+ sb.append( (char) c );
}
- return result;
+ return sb.toString();
}
protected static void sendEom( OutputStream out )
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java?rev=366098&r1=366097&r2=366098&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java Wed Jan 4 22:35:26 2006
@@ -56,6 +56,8 @@
private static final char ACK_SEPARATOR = ' ';
+ private static final String END_OF_FILES_MSG = "E\n";
+
public void put( File source, String resourceName )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
@@ -106,7 +108,7 @@
try
{
- // exec 'scp -t rfile' remotely
+ // exec 'scp -t -d rfile' remotely
String command = "scp -t " + path;
fireTransferDebug( "Executing command: " + command );
@@ -165,6 +167,10 @@
sendEom( out );
checkAck( in );
+
+ // This came from SCPClient in Ganymede SSH2. It is sent after all files.
+ out.write( END_OF_FILES_MSG.getBytes() );
+ out.flush();
}
catch ( IOException e )
{
@@ -203,7 +209,7 @@
}
}
- private static void checkAck( InputStream in )
+ private void checkAck( InputStream in )
throws IOException, TransferFailedException
{
int code = in.read();
@@ -211,9 +217,19 @@
{
throw new TransferFailedException( "Unexpected end of data" );
}
+ else if ( code == 1 )
+ {
+ String line = readLine( in );
+
+ throw new TransferFailedException( "SCP terminated with error: '" + line + "'" );
+ }
+ else if ( code == 2 )
+ {
+ throw new TransferFailedException( "SCP terminated with error (code: " + code + ")" );
+ }
else if ( code != 0 )
{
- throw new TransferFailedException( "Did receive proper ACK: '" + code + "'" );
+ throw new TransferFailedException( "SCP terminated with unknown error code" );
}
}
@@ -255,6 +271,13 @@
int exitCode = in.read();
+ if ( exitCode == 'P' )
+ {
+ // ignore modification times
+
+ exitCode = in.read();
+ }
+
String line = readLine( in );
if ( exitCode != COPY_START_CHAR )
@@ -277,7 +300,7 @@
String perms = line.substring( 0, 4 );
fireTransferDebug( "Remote file permissions: " + perms );
- if ( line.charAt( 4 ) != ACK_SEPARATOR )
+ if ( line.charAt( 4 ) != ACK_SEPARATOR && line.charAt( 5 ) != ACK_SEPARATOR )
{
throw new TransferFailedException( "Invalid transfer header: " + line );
}
@@ -311,12 +334,6 @@
checkAck( in );
sendEom( out );
-
- if ( in.read() != -1 )
- {
- throw new TransferFailedException(
- "End of stream not encountered - server possibly attempted to send multiple files" );
- }
}
catch ( JSchException e )
{
---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org