1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Bug 437083 - Improve error message if ssh fails

Execute loadEnv once before trying sftp to make sure exec works.
This way we don't assume it is an sftp problem if the ssh
connection doesn't work at all. To make this work throw an
exception if ExecCommand fails (if exit code != 0). ExecCommand doesn't
have a way to check exit code. Thus this also fixes that if any command
executed with ExecCommand failed, the calling code didn't notice.

Change-Id: I30b8baa0d87166e179fad67643e31a9f17c8ead2
Signed-off-by: Roland Schulz <roland@utk.edu>
This commit is contained in:
Roland Schulz 2014-06-10 20:02:32 -04:00
parent 407382d8af
commit b511b31ad1
3 changed files with 12 additions and 14 deletions

View file

@ -171,7 +171,6 @@ public class JSchConnection implements IRemoteConnection {
public static final String EMPTY_STRING = ""; //$NON-NLS-1$
private String fWorkingDir;
private boolean fIsOpen;
private final IJSchService fJSchService;
@ -263,7 +262,6 @@ public class JSchConnection implements IRemoteConnection {
}
}
fSessions.clear();
fIsOpen = false;
fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_CLOSED);
}
@ -661,7 +659,7 @@ public class JSchConnection implements IRemoteConnection {
*/
@Override
public boolean isOpen() {
boolean isOpen = fIsOpen & fSessions.size() > 0;
boolean isOpen = fSessions.size() > 0;
if (isOpen) {
for (Session session : fSessions) {
isOpen &= session.isConnected();
@ -814,23 +812,18 @@ public class JSchConnection implements IRemoteConnection {
public void open(IProgressMonitor monitor) throws RemoteConnectionException {
if (!isOpen()) {
checkIsConfigured();
SubMonitor subMon = SubMonitor.convert(monitor, 70);
SubMonitor subMon = SubMonitor.convert(monitor, 60);
Session session = newSession(fManager.getUserAuthenticator(this), subMon.newChild(10));
if (subMon.isCanceled()) {
throw new RemoteConnectionException(Messages.JSchConnection_Connection_was_cancelled);
}
//getCwd checks the exec channel before checkConfiguration checks the sftp channel
fWorkingDir = getCwd(subMon.newChild(10));
if (!checkConfiguration(session, subMon.newChild(20))) {
newSession(fManager.getUserAuthenticator(this), subMon.newChild(10));
loadEnv(subMon.newChild(10));
}
fIsOpen = true;
try {
fWorkingDir = getCwd(subMon.newChild(10));
loadProperties(subMon.newChild(10));
} catch (RemoteConnectionException e) {
fIsOpen = false;
throw e;
}
loadProperties(subMon.newChild(10));
fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_OPENED);
}
}

View file

@ -126,7 +126,7 @@ public abstract class AbstractRemoteCommand<T> {
* @see java.util.concurrent.Callable#call()
*/
@Override
public abstract T1 call() throws JSchException, IOException;
public abstract T1 call() throws JSchException, IOException, RemoteConnectionException;
private void finalizeCmdInThread() {
setChannel(null);

View file

@ -29,10 +29,12 @@ public class ExecCommand extends AbstractRemoteCommand<String> {
final SubMonitor subMon = SubMonitor.convert(monitor, 10);
ExecCallable<String> c = new ExecCallable<String>() {
@Override
public String call() throws JSchException {
public String call() throws JSchException, RemoteConnectionException {
getChannel().setCommand(fCommand);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
getChannel().setOutputStream(stream);
getChannel().setErrStream(err);
getChannel().connect();
while (!getChannel().isClosed() && !getProgressMonitor().isCanceled()) {
synchronized (this) {
@ -46,6 +48,9 @@ public class ExecCommand extends AbstractRemoteCommand<String> {
if (getProgressMonitor().isCanceled()) {
return ""; //$NON-NLS-1$
}
if (getChannel().getExitStatus()!=0) {
throw new RemoteConnectionException(err.toString());
}
return stream.toString();
}
};