mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-03 23:25:26 +02:00
Fix bug 154419 - cannot delete broken symbolic links on ssh
This commit is contained in:
parent
bca6b002da
commit
062cbe4ec3
4 changed files with 29 additions and 8 deletions
|
@ -16,6 +16,10 @@ import org.eclipse.osgi.util.NLS;
|
|||
public class SshServiceResources extends NLS {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.rse.services.ssh.SshServiceResources"; //$NON-NLS-1$
|
||||
|
||||
public static String SftpFileService_Error_download_size;
|
||||
|
||||
public static String SftpFileService_Error_upload_size;
|
||||
|
||||
public static String SshPlugin_Unexpected_Exception;
|
||||
|
||||
public static String SftpFileService_Description;
|
||||
|
|
|
@ -14,6 +14,8 @@ SshPlugin_Unexpected_Exception=Unexpected {0}: {1}
|
|||
SftpFileService_Name=Ssh / Sftp File Service
|
||||
SftpFileService_Description=Access a remote file system via Ssh / Sftp protocol
|
||||
SftpFileService_Error_JschSessionLost=jsch session lost
|
||||
SftpFileService_Error_upload_size=Ssh upload: file size mismatch for {0}
|
||||
SftpFileService_Error_download_size=Ssh download: file size mismatch for {0}
|
||||
SftpFileService_Msg_Progress={0,number,integer} KB of {1,number,integer} KB complete ({2,number,percent})
|
||||
|
||||
SshShellService_Name=SSH Shell Service
|
||||
|
|
|
@ -22,10 +22,12 @@ import java.io.OutputStream;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
import com.jcraft.jsch.Channel;
|
||||
import com.jcraft.jsch.ChannelExec;
|
||||
|
@ -158,7 +160,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
|||
} else {
|
||||
messageException = new RemoteFileIOException(e);
|
||||
}
|
||||
messageException.getSystemMessage().makeSubstitution("Sftp: "+sftpe.toString());
|
||||
messageException.getSystemMessage().makeSubstitution("Sftp: "+sftpe.toString()); //$NON-NLS-1$ //Dont translate since the exception isnt translated either
|
||||
return messageException;
|
||||
}
|
||||
return new RemoteFileIOException(e);
|
||||
|
@ -213,7 +215,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
|||
List results = new ArrayList();
|
||||
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
||||
try {
|
||||
java.util.Vector vv=getChannel("SftpFileService.internalFetch").ls(parentPath); //$NON-NLS-1$
|
||||
Vector vv=getChannel("SftpFileService.internalFetch").ls(parentPath); //$NON-NLS-1$
|
||||
for(int ii=0; ii<vv.size(); ii++) {
|
||||
Object obj=vv.elementAt(ii);
|
||||
if(obj instanceof ChannelSftp.LsEntry){
|
||||
|
@ -334,8 +336,8 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
|||
channel.setStat(dst, attr);
|
||||
if (attr.getSize() != localFile.length()) {
|
||||
//Error: file truncated? - Inform the user!!
|
||||
//TODO test if this works, and externalize string
|
||||
throw makeSystemMessageException(new IOException("ssh.upload: file size mismatch for "+dst));
|
||||
//TODO test if this works
|
||||
throw makeSystemMessageException(new IOException(NLS.bind(SshServiceResources.SftpFileService_Error_upload_size,dst)));
|
||||
//return false;
|
||||
}
|
||||
}
|
||||
|
@ -445,8 +447,8 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
|||
//if (0==(attrs.getPermissions() & 00400)) localFile.setReadOnly();
|
||||
if (attr.getSize() != localFile.length()) {
|
||||
//Error: file truncated? - Inform the user!!
|
||||
//TODO test if this works, and externalize string
|
||||
throw makeSystemMessageException(new IOException("ssh.download: file size mismatch for "+remotePath)); //$NON-NLS-1$
|
||||
//TODO test if this works
|
||||
throw makeSystemMessageException(new IOException(NLS.bind(SshServiceResources.SftpFileService_Error_download_size,remotePath)));
|
||||
//return false;
|
||||
}
|
||||
}
|
||||
|
@ -538,7 +540,18 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
|||
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
||||
try {
|
||||
String fullPath = remoteParent + '/' + fileName;
|
||||
SftpATTRS attrs = getChannel("SftpFileService.delete").stat(fullPath); //$NON-NLS-1$
|
||||
SftpATTRS attrs = null;
|
||||
try {
|
||||
attrs = getChannel("SftpFileService.delete").stat(fullPath); //$NON-NLS-1$
|
||||
} catch (SftpException e) {
|
||||
//bug 154419: test for dangling symbolic link
|
||||
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
|
||||
//simply try to delete --> if it really doesnt exist, this will throw an exception
|
||||
getChannel("SftpFileService.delete.rm").rm(fullPath); //$NON-NLS-1$
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if (attrs==null) {
|
||||
//doesn't exist, nothing to do
|
||||
} else if (attrs.isDir()) {
|
||||
|
@ -547,6 +560,8 @@ public class SftpFileService extends AbstractFileService implements IFileService
|
|||
} catch(SftpException e) {
|
||||
if(e.id==ChannelSftp.SSH_FX_FAILURE) {
|
||||
throw new RemoteFolderNotEmptyException();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -171,7 +171,7 @@ public class SftpHostFile implements IHostFile {
|
|||
if (isLink()) {
|
||||
result = "symbolic link"; //$NON-NLS-1$
|
||||
if (fLinkTarget!=null) {
|
||||
if (fLinkTarget.equals(":dangling link")) {
|
||||
if (fLinkTarget.equals(":dangling link")) { //$NON-NLS-1$
|
||||
result = "broken symbolic link to `unknown'"; //$NON-NLS-1$
|
||||
} else if(isDirectory()) {
|
||||
result += "(directory):" + fLinkTarget; //$NON-NLS-1$
|
||||
|
|
Loading…
Add table
Reference in a new issue