mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-08 17:45:24 +02:00
Check session connected when dealing with ssh errors.
This commit is contained in:
parent
9f11823b26
commit
c564e89d07
1 changed files with 40 additions and 15 deletions
|
@ -15,6 +15,7 @@ import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -30,7 +31,6 @@ import org.eclipse.rse.services.files.IHostFile;
|
||||||
import org.eclipse.rse.services.ssh.Activator;
|
import org.eclipse.rse.services.ssh.Activator;
|
||||||
import org.eclipse.rse.services.ssh.ISshService;
|
import org.eclipse.rse.services.ssh.ISshService;
|
||||||
import org.eclipse.rse.services.ssh.ISshSessionProvider;
|
import org.eclipse.rse.services.ssh.ISshSessionProvider;
|
||||||
import org.eclipse.swt.widgets.Display;
|
|
||||||
|
|
||||||
import com.jcraft.jsch.Channel;
|
import com.jcraft.jsch.Channel;
|
||||||
import com.jcraft.jsch.ChannelExec;
|
import com.jcraft.jsch.ChannelExec;
|
||||||
|
@ -77,24 +77,43 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the main ssh session is still connected.
|
||||||
|
* Notify ConnectorService of lost session if necessary.
|
||||||
|
* @return <code>true</code> if the session is still healthy.
|
||||||
|
*/
|
||||||
|
protected boolean checkSessionConnected() {
|
||||||
|
Session session = fSessionProvider.getSession();
|
||||||
|
if (session==null) {
|
||||||
|
// ConnectorService has disconnected already. Nothing to do.
|
||||||
|
return false;
|
||||||
|
} else if (session.isConnected()) {
|
||||||
|
// Session still healthy.
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// Session was lost, but ConnectorService doesn't know yet.
|
||||||
|
// notify of lost session. May reconnect asynchronously later.
|
||||||
|
fSessionProvider.handleSessionLost();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected ChannelSftp getChannel(String task) throws Exception
|
protected ChannelSftp getChannel(String task) throws Exception
|
||||||
{
|
{
|
||||||
Activator.trace(task);
|
Activator.trace(task);
|
||||||
if (fChannelSftp==null || !fChannelSftp.isConnected()) {
|
if (fChannelSftp==null || !fChannelSftp.isConnected()) {
|
||||||
Activator.trace(task + ": channel not connected: "+fChannelSftp); //$NON-NLS-1$
|
Activator.trace(task + ": channel not connected: "+fChannelSftp); //$NON-NLS-1$
|
||||||
Session session = fSessionProvider.getSession();
|
if (checkSessionConnected()) {
|
||||||
if (session!=null) {
|
//session connected but channel not: try to reconnect
|
||||||
if (!session.isConnected()) {
|
//(may throw Exception)
|
||||||
//notify of lost session. May reconnect asynchronously later.
|
connect();
|
||||||
fSessionProvider.handleSessionLost();
|
} else {
|
||||||
//dont throw an exception here, expect jsch to throw something useful
|
//session was lost: returned channelSftp will be invalid.
|
||||||
} else {
|
//This will lead to jsch exceptions (NPE, or disconnected)
|
||||||
//session connected but channel not: try to reconnect
|
//which are ignored for now since the connection is about
|
||||||
//(may throw Exception)
|
//to be disconnected anyways.
|
||||||
connect();
|
throw new IOException("jsch session lost");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//TODO might throw NPE if session has been disconnected
|
|
||||||
}
|
}
|
||||||
return fChannelSftp;
|
return fChannelSftp;
|
||||||
}
|
}
|
||||||
|
@ -174,8 +193,14 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
||||||
//of a symbolic link that turns out to point to a file rather than
|
//of a symbolic link that turns out to point to a file rather than
|
||||||
//a directory. In this case, the result is probably expected.
|
//a directory. In this case, the result is probably expected.
|
||||||
//We should try to classify symbolic links as "file" or "dir" correctly.
|
//We should try to classify symbolic links as "file" or "dir" correctly.
|
||||||
Activator.trace("SftpFileService.internalFetch failed: "+e.toString()); //$NON-NLS-1$
|
if (checkSessionConnected()) {
|
||||||
e.printStackTrace();
|
//TODO not quite sure who should really check for session conneced,
|
||||||
|
//perhaps this should be done in the caller? - If we eventually
|
||||||
|
//want to support re-connect and re-doing the failed operation
|
||||||
|
//after reconnect this might be necessary.
|
||||||
|
Activator.trace("SftpFileService.internalFetch failed: "+e.toString()); //$NON-NLS-1$
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (IHostFile[])results.toArray(new IHostFile[results.size()]);
|
return (IHostFile[])results.toArray(new IHostFile[results.size()]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue