mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 09:15:38 +02:00
Make ssh connection-lost handling more robust
This commit is contained in:
parent
6ed9345743
commit
6e734d44bb
2 changed files with 20 additions and 7 deletions
|
@ -292,7 +292,11 @@ public class SshConnectorService extends AbstractConnectorService implements ISs
|
||||||
{
|
{
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
// Is disconnect being called because the network (connection) went down?
|
// Is disconnect being called because the network (connection) went down?
|
||||||
if (fSessionLostHandler != null && fSessionLostHandler.isSessionLost()) {
|
boolean sessionLost = (fSessionLostHandler!=null && fSessionLostHandler.isSessionLost());
|
||||||
|
// no more interested in handling session-lost, since we are disconnecting anyway
|
||||||
|
fSessionLostHandler = null;
|
||||||
|
// handle events
|
||||||
|
if (sessionLost) {
|
||||||
notifyError();
|
notifyError();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -300,13 +304,14 @@ public class SshConnectorService extends AbstractConnectorService implements ISs
|
||||||
fireCommunicationsEvent(CommunicationsEvent.BEFORE_DISCONNECT);
|
fireCommunicationsEvent(CommunicationsEvent.BEFORE_DISCONNECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (session.isConnected()) {
|
||||||
session.disconnect();
|
session.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
// Fire comm event to signal state changed
|
// Fire comm event to signal state changed
|
||||||
notifyDisconnection();
|
notifyDisconnection();
|
||||||
//TODO MOB - keep the session to avoid NPEs in services (disables gc for the session!)
|
//TODO MOB - keep the session to avoid NPEs in services (disables gc for the session!)
|
||||||
// session = null;
|
// session = null;
|
||||||
fSessionLostHandler = null;
|
|
||||||
// DKM - no need to clear uid cache
|
// DKM - no need to clear uid cache
|
||||||
clearPasswordCache(false); // clear in-memory password
|
clearPasswordCache(false); // clear in-memory password
|
||||||
//clearUserIdCache(); // Clear any cached local user IDs
|
//clearUserIdCache(); // Clear any cached local user IDs
|
||||||
|
@ -651,6 +656,7 @@ public class SshConnectorService extends AbstractConnectorService implements ISs
|
||||||
if (session.isConnected()) {
|
if (session.isConnected()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (fSessionLostHandler!=null) {
|
} else if (fSessionLostHandler!=null) {
|
||||||
|
Activator.trace("SshConnectorService.isConnected: false -> sessionLost"); //$NON-NLS-1$
|
||||||
fSessionLostHandler.sessionLost();
|
fSessionLostHandler.sessionLost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,10 +100,12 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
try {
|
//disconnect-service may be called after the session is already
|
||||||
getChannel("SftpFileService.disconnect").disconnect(); //$NON-NLS-1$
|
//disconnected (due to event handling). Therefore, don't try to
|
||||||
} catch(Exception e) {
|
//check the session and notify.
|
||||||
/*nothing to do*/
|
Activator.trace("SftpFileService.disconnect"); //$NON-NLS-1$
|
||||||
|
if (fChannelSftp!=null && fChannelSftp.isConnected()) {
|
||||||
|
fChannelSftp.disconnect();
|
||||||
}
|
}
|
||||||
fChannelSftp = null;
|
fChannelSftp = null;
|
||||||
}
|
}
|
||||||
|
@ -522,6 +524,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
||||||
// TODO check if newer versions of sftp support move directly
|
// TODO check if newer versions of sftp support move directly
|
||||||
// TODO Interpret some error messages like "command not found" (use ren instead of mv on windows)
|
// TODO Interpret some error messages like "command not found" (use ren instead of mv on windows)
|
||||||
// TODO mimic by copy if the remote does not support copying between file systems?
|
// TODO mimic by copy if the remote does not support copying between file systems?
|
||||||
|
Activator.trace("SftpFileService.move "+srcName); //$NON-NLS-1$
|
||||||
String fullPathOld = enQuote(srcParent + '/' + srcName);
|
String fullPathOld = enQuote(srcParent + '/' + srcName);
|
||||||
String fullPathNew = enQuote(tgtParent + '/' + tgtName);
|
String fullPathNew = enQuote(tgtParent + '/' + tgtName);
|
||||||
int rv = runCommand(monitor, "mv "+fullPathOld+' '+fullPathNew); //$NON-NLS-1$
|
int rv = runCommand(monitor, "mv "+fullPathOld+' '+fullPathNew); //$NON-NLS-1$
|
||||||
|
@ -532,6 +535,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
||||||
// move is not supported by sftp directly. Use the ssh shell instead.
|
// move is not supported by sftp directly. Use the ssh shell instead.
|
||||||
// TODO check if newer versions of sftp support move directly
|
// TODO check if newer versions of sftp support move directly
|
||||||
// TODO Interpret some error messages like "command not found" (use (x)copy instead of cp on windows)
|
// TODO Interpret some error messages like "command not found" (use (x)copy instead of cp on windows)
|
||||||
|
Activator.trace("SftpFileService.copy "+srcName); //$NON-NLS-1$
|
||||||
String fullPathOld = enQuote(srcParent + '/' + srcName); //$NON-NLS-1$
|
String fullPathOld = enQuote(srcParent + '/' + srcName); //$NON-NLS-1$
|
||||||
String fullPathNew = enQuote(tgtParent + '/' + tgtName); //$NON-NLS-1$
|
String fullPathNew = enQuote(tgtParent + '/' + tgtName); //$NON-NLS-1$
|
||||||
int rv = runCommand(monitor, "cp "+fullPathOld+' '+fullPathNew); //$NON-NLS-1$
|
int rv = runCommand(monitor, "cp "+fullPathOld+' '+fullPathNew); //$NON-NLS-1$
|
||||||
|
@ -540,6 +544,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
||||||
|
|
||||||
public boolean copyBatch(IProgressMonitor monitor, String[] srcParents, String[] srcNames, String tgtParent) throws SystemMessageException
|
public boolean copyBatch(IProgressMonitor monitor, String[] srcParents, String[] srcNames, String tgtParent) throws SystemMessageException
|
||||||
{
|
{
|
||||||
|
Activator.trace("SftpFileService.copyBatch "+srcNames); //$NON-NLS-1$
|
||||||
boolean ok = true;
|
boolean ok = true;
|
||||||
for (int i = 0; i < srcParents.length; i++)
|
for (int i = 0; i < srcParents.length; i++)
|
||||||
{
|
{
|
||||||
|
@ -549,6 +554,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initService(IProgressMonitor monitor) {
|
public void initService(IProgressMonitor monitor) {
|
||||||
|
Activator.trace("SftpFileService.initService"); //$NON-NLS-1$
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
connect();
|
connect();
|
||||||
|
@ -559,6 +565,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uninitService(IProgressMonitor monitor) {
|
public void uninitService(IProgressMonitor monitor) {
|
||||||
|
Activator.trace("SftpFileService.uninitService"); //$NON-NLS-1$
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue