Browse Source

Properly parser return codes from server.

Also fixes PR: 23986
Suggested by:	Atsuhiko Yamanaka <ymnk at jcraft dot com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275561 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 21 years ago
parent
commit
a5ec1501c9
1 changed files with 37 additions and 5 deletions
  1. +37
    -5
      src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java

+ 37
- 5
src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java View File

@@ -64,6 +64,8 @@ import java.io.OutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.text.NumberFormat; import java.text.NumberFormat;


import org.apache.tools.ant.BuildException;

public abstract class AbstractSshMessage { public abstract class AbstractSshMessage {


private Session session; private Session session;
@@ -91,11 +93,41 @@ public abstract class AbstractSshMessage {
out.flush(); out.flush();
} }


protected void waitForAck(InputStream in) throws IOException {
int b = 0;
do {
b = in.read();
} while (b > 0);
/**
* Reads the response, throws a BuildException if the response
* indicates an error.
*/
protected void waitForAck(InputStream in)
throws IOException, BuildException {
int b = in.read();

// b may be 0 for success,
// 1 for error,
// 2 for fatal error,

if (b == -1) {
// didn't receive any response
throw new BuildException("No response from server");
} else if (b != 0) {
StringBuffer sb = new StringBuffer();

int c = in.read();
while (c > 0 && c != '\n') {
sb.append((char) c);
c = in.read();
}
if (b == 1) {
throw new BuildException("server indicated an error: "
+ sb.toString());
} else if (b == 2) {
throw new BuildException("server indicated a fatal error: "
+ sb.toString());
} else {
throw new BuildException("unknown response, code " + b
+ " message: " + sb.toString());
}
}
} }


public abstract void execute() throws IOException, JSchException; public abstract void execute() throws IOException, JSchException;


Loading…
Cancel
Save