bodewig 2003/10/24 01:31:36
Modified: src/main/org/apache/tools/ant/taskdefs/optional/ssh
AbstractSshMessage.java
Log:
Properly parser return codes from server.
Also fixes PR: 23986
Suggested by: Atsuhiko Yamanaka <ymnk at jcraft dot com>
Revision Changes Path
1.5 +37 -5
ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java
Index: AbstractSshMessage.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractSshMessage.java 9 Jul 2003 12:12:59 -0000 1.4
+++ AbstractSshMessage.java 24 Oct 2003 08:31:35 -0000 1.5
@@ -64,6 +64,8 @@
import java.io.InputStream;
import java.text.NumberFormat;
+import org.apache.tools.ant.BuildException;
+
public abstract class AbstractSshMessage {
private Session session;
@@ -91,11 +93,41 @@
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;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]