1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-13 03:05:39 +02:00

[221211] Throw SystemLockTimeoutException in Sftp and FTP in case a lock can not be obtained

This commit is contained in:
Martin Oberhuber 2008-05-07 03:23:14 +00:00
parent e869ef164d
commit c2b968e905
2 changed files with 87 additions and 68 deletions

View file

@ -27,6 +27,8 @@ public class Activator extends Plugin {
//The shared instance. //The shared instance.
private static Activator plugin; private static Activator plugin;
public static final String PLUGIN_ID = "org.eclipse.rse.internal.services.files.ftp"; //$NON-NLS-1$
/** /**
* The constructor. * The constructor.
*/ */

View file

@ -111,16 +111,17 @@ import org.eclipse.rse.services.clientserver.IMatcher;
import org.eclipse.rse.services.clientserver.NamePatternMatcher; import org.eclipse.rse.services.clientserver.NamePatternMatcher;
import org.eclipse.rse.services.clientserver.PathUtility; import org.eclipse.rse.services.clientserver.PathUtility;
import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage; import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage;
import org.eclipse.rse.services.clientserver.messages.SystemLockTimeoutException;
import org.eclipse.rse.services.clientserver.messages.SystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessage;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.services.clientserver.messages.SystemOperationCancelledException;
import org.eclipse.rse.services.clientserver.messages.SystemUnsupportedOperationException;
import org.eclipse.rse.services.files.AbstractFileService; import org.eclipse.rse.services.files.AbstractFileService;
import org.eclipse.rse.services.files.IFilePermissionsService; import org.eclipse.rse.services.files.IFilePermissionsService;
import org.eclipse.rse.services.files.IFileService; import org.eclipse.rse.services.files.IFileService;
import org.eclipse.rse.services.files.IHostFile; import org.eclipse.rse.services.files.IHostFile;
import org.eclipse.rse.services.files.IHostFilePermissions; import org.eclipse.rse.services.files.IHostFilePermissions;
import org.eclipse.rse.services.files.IHostFilePermissionsContainer; import org.eclipse.rse.services.files.IHostFilePermissionsContainer;
import org.eclipse.rse.services.files.RemoteFileCancelledException;
import org.eclipse.rse.services.files.RemoteFileException;
import org.eclipse.rse.services.files.RemoteFileIOException; import org.eclipse.rse.services.files.RemoteFileIOException;
import org.eclipse.rse.services.files.RemoteFileSecurityException; import org.eclipse.rse.services.files.RemoteFileSecurityException;
@ -571,7 +572,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
fileName = checkEncoding(fileName); fileName = checkEncoding(fileName);
if (monitor!=null){ if (monitor!=null){
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
} }
@ -611,7 +612,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
if(!listFiles(monitor)) if(!listFiles(monitor))
{ {
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
synchronized(_fCachePreviousFiles) { synchronized(_fCachePreviousFiles) {
@ -646,6 +647,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
} finally { } finally {
_commandMutex.release(); _commandMutex.release();
} }
} else {
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
return file; return file;
@ -671,7 +674,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
parentPath = checkEncoding(parentPath); parentPath = checkEncoding(parentPath);
if (monitor!=null){ if (monitor!=null){
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
} }
@ -701,7 +704,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
if(!listFiles(monitor)) if(!listFiles(monitor))
{ {
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
synchronized (_fCachePreviousFiles) { synchronized (_fCachePreviousFiles) {
@ -743,6 +746,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
} finally { } finally {
_commandMutex.release(); _commandMutex.release();
} }
} else {
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
return (IHostFile[])results.toArray(new IHostFile[results.size()]); return (IHostFile[])results.toArray(new IHostFile[results.size()]);
@ -765,7 +770,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
if (monitor!=null){ if (monitor!=null){
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
} }
else{ else{
@ -785,6 +790,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
finally { finally {
_commandMutex.release(); _commandMutex.release();
} }
} else {
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
} catch (SystemMessageException e) { } catch (SystemMessageException e) {
throw e; throw e;
@ -818,7 +825,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
bos.write(buffer, 0, readCount); bos.write(buffer, 0, readCount);
if (monitor!=null) { if (monitor!=null) {
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
break; throw new SystemOperationCancelledException();
} }
} }
} }
@ -858,7 +865,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
output.write(buffer, 0, readCount); output.write(buffer, 0, readCount);
progressMonitor.count(readCount); progressMonitor.count(readCount);
if (progressMonitor.isCanceled()) { if (progressMonitor.isCanceled()) {
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
} }
output.flush(); output.flush();
@ -889,7 +896,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
if (monitor!=null){ if (monitor!=null){
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
} }
@ -908,6 +915,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
{ {
_commandMutex.release(); _commandMutex.release();
} }
} else {
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new RemoteFileIOException(e); throw new RemoteFileIOException(e);
@ -947,20 +956,15 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
output = new FileOutputStream(localFile); output = new FileOutputStream(localFile);
byte[] buffer = new byte[4096]; byte[] buffer = new byte[4096];
int readCount; int readCount;
boolean ok = true;
while((readCount = input.read(buffer)) > 0) while((readCount = input.read(buffer)) > 0)
{ {
output.write(buffer, 0, readCount); output.write(buffer, 0, readCount);
progressMonitor.count(readCount); progressMonitor.count(readCount);
if (progressMonitor.isCanceled()) { if (progressMonitor.isCanceled()) {
ok = false; throw new SystemOperationCancelledException();
break;
} }
} }
if (ok) {
output.flush(); output.flush();
}
input.close(); input.close();
input = null; input = null;
ftpClient.completePendingCommand(); ftpClient.completePendingCommand();
@ -1041,6 +1045,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
finally { finally {
_commandMutex.release(); _commandMutex.release();
} }
} else {
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
} finally { } finally {
progressMonitor.end(); progressMonitor.end();
@ -1048,28 +1054,32 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
} }
private void internalDelete(FTPClient ftpClient, String parentPath, String fileName, boolean isFile, MyProgressMonitor monitor) private void internalDelete(FTPClient ftpClient, String parentPath, String fileName, boolean isFile, MyProgressMonitor monitor)
throws RemoteFileException, IOException throws SystemMessageException, IOException
{ {
if(monitor.isCanceled()) if(monitor.isCanceled())
{ {
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
clearCache(parentPath); clearCache(parentPath);
FTPReply.isPositiveCompletion(ftpClient.cwd(parentPath)); boolean hasSucceeded = FTPReply.isPositiveCompletion(ftpClient.cwd(parentPath));
monitor.worked(1); monitor.worked(1);
if(hasSucceeded)
{
if(isFile) if(isFile)
{ {
ftpClient.deleteFile(fileName); hasSucceeded = ftpClient.deleteFile(fileName);
monitor.worked(1); monitor.worked(1);
} }
else else
{ {
ftpClient.removeDirectory(fileName); hasSucceeded = ftpClient.removeDirectory(fileName);
monitor.worked(1); monitor.worked(1);
} }
}
if(!hasSucceeded){
if(isFile) if(isFile)
{ {
throw new RemoteFileIOException(new Exception(ftpClient.getReplyString()+" ("+concat(parentPath,fileName)+")")); //$NON-NLS-1$ //$NON-NLS-2$ throw new RemoteFileIOException(new Exception(ftpClient.getReplyString()+" ("+concat(parentPath,fileName)+")")); //$NON-NLS-1$ //$NON-NLS-2$
@ -1091,13 +1101,14 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
//remove empty folder //remove empty folder
ftpClient.changeWorkingDirectory(parentPath); ftpClient.changeWorkingDirectory(parentPath);
boolean hasSucceeded = ftpClient.removeDirectory(fileName); hasSucceeded = ftpClient.removeDirectory(fileName);
if (!hasSucceeded) if (!hasSucceeded)
{ {
throw new RemoteFileIOException(new Exception(ftpClient.getReplyString() + " (" + concat(parentPath, fileName) + ")")); //$NON-NLS-1$ //$NON-NLS-2$ throw new RemoteFileIOException(new Exception(ftpClient.getReplyString() + " (" + concat(parentPath, fileName) + ")")); //$NON-NLS-1$ //$NON-NLS-2$
} }
} }
} }
}
/* (non-Javadoc) /* (non-Javadoc)
@ -1131,6 +1142,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
}finally { }finally {
_commandMutex.release(); _commandMutex.release();
} }
} else {
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
} }
@ -1172,7 +1185,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
}finally { }finally {
_commandMutex.release(); _commandMutex.release();
} }
} else {
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
} }
@ -1205,7 +1219,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
}finally { }finally {
_commandMutex.release(); _commandMutex.release();
} }
} else {
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
return getFile(remoteParent, folderName, monitor); return getFile(remoteParent, folderName, monitor);
@ -1246,7 +1261,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
if (monitor!=null){ if (monitor!=null){
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
} }
@ -1267,6 +1282,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
finally { finally {
_commandMutex.release(); _commandMutex.release();
} }
} else {
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
} }
@ -1274,7 +1291,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
{ {
if (monitor.isCanceled()) if (monitor.isCanceled())
{ {
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
if(isDirectory) if(isDirectory)
@ -1513,7 +1530,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
public void setLastModified(String parent, String name, public void setLastModified(String parent, String name,
long timestamp, IProgressMonitor monitor) throws SystemMessageException long timestamp, IProgressMonitor monitor) throws SystemMessageException
{ {
// not applicable for FTP throw new SystemUnsupportedOperationException(Activator.PLUGIN_ID, "setLastModified"); //$NON-NLS-1$
} }
/* /*
@ -1564,7 +1581,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
public InputStream getInputStream(String remoteParent, String remoteFile, boolean isBinary, IProgressMonitor monitor) throws SystemMessageException { public InputStream getInputStream(String remoteParent, String remoteFile, boolean isBinary, IProgressMonitor monitor) throws SystemMessageException {
if (monitor != null && monitor.isCanceled()){ if (monitor != null && monitor.isCanceled()){
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
InputStream stream = null; InputStream stream = null;
@ -1599,7 +1616,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
remoteFile = checkEncoding(remoteFile); remoteFile = checkEncoding(remoteFile);
if (monitor != null && monitor.isCanceled()){ if (monitor != null && monitor.isCanceled()){
throw new RemoteFileCancelledException(); throw new SystemOperationCancelledException();
} }
OutputStream stream = null; OutputStream stream = null;