diff --git a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorService.java b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorService.java index 39fdc70f4d9..4d8991c34c5 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorService.java +++ b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorService.java @@ -292,7 +292,11 @@ public class SshConnectorService extends AbstractConnectorService implements ISs { if (session != null) { // 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(); } else { @@ -300,13 +304,14 @@ public class SshConnectorService extends AbstractConnectorService implements ISs fireCommunicationsEvent(CommunicationsEvent.BEFORE_DISCONNECT); } - session.disconnect(); + if (session.isConnected()) { + session.disconnect(); + } // Fire comm event to signal state changed notifyDisconnection(); //TODO MOB - keep the session to avoid NPEs in services (disables gc for the session!) // session = null; - fSessionLostHandler = null; // DKM - no need to clear uid cache clearPasswordCache(false); // clear in-memory password //clearUserIdCache(); // Clear any cached local user IDs @@ -651,6 +656,7 @@ public class SshConnectorService extends AbstractConnectorService implements ISs if (session.isConnected()) { return true; } else if (fSessionLostHandler!=null) { + Activator.trace("SshConnectorService.isConnected: false -> sessionLost"); //$NON-NLS-1$ fSessionLostHandler.sessionLost(); } } diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java index 1f10a8ee5db..6ac55b2287b 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java @@ -100,10 +100,12 @@ public class SftpFileService extends AbstractFileService implements IFileService } public void disconnect() { - try { - getChannel("SftpFileService.disconnect").disconnect(); //$NON-NLS-1$ - } catch(Exception e) { - /*nothing to do*/ + //disconnect-service may be called after the session is already + //disconnected (due to event handling). Therefore, don't try to + //check the session and notify. + Activator.trace("SftpFileService.disconnect"); //$NON-NLS-1$ + if (fChannelSftp!=null && fChannelSftp.isConnected()) { + fChannelSftp.disconnect(); } fChannelSftp = null; } @@ -522,6 +524,7 @@ public class SftpFileService extends AbstractFileService implements IFileService // 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 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 fullPathNew = enQuote(tgtParent + '/' + tgtName); 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. // 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) + Activator.trace("SftpFileService.copy "+srcName); //$NON-NLS-1$ String fullPathOld = enQuote(srcParent + '/' + srcName); //$NON-NLS-1$ String fullPathNew = enQuote(tgtParent + '/' + tgtName); //$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 { + Activator.trace("SftpFileService.copyBatch "+srcNames); //$NON-NLS-1$ boolean ok = true; for (int i = 0; i < srcParents.length; i++) { @@ -549,6 +554,7 @@ public class SftpFileService extends AbstractFileService implements IFileService } public void initService(IProgressMonitor monitor) { + Activator.trace("SftpFileService.initService"); //$NON-NLS-1$ try { connect(); @@ -559,6 +565,7 @@ public class SftpFileService extends AbstractFileService implements IFileService } public void uninitService(IProgressMonitor monitor) { + Activator.trace("SftpFileService.uninitService"); //$NON-NLS-1$ disconnect(); }