1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 17:55: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

@ -1,15 +1,15 @@
/******************************************************************************** /********************************************************************************
* Copyright (c) 2006, 2007 IBM Corporation. All rights reserved. * Copyright (c) 2006, 2007 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms * This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is * of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html * available at http://www.eclipse.org/legal/epl-v10.html
* *
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir, * component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* {Name} (company) - description of contribution. * {Name} (company) - description of contribution.
********************************************************************************/ ********************************************************************************/
@ -26,7 +26,9 @@ 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;
} }
} }
output.flush();
if (ok) {
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,53 +1054,58 @@ 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(isFile) if(hasSucceeded)
{ {
ftpClient.deleteFile(fileName); if(isFile)
monitor.worked(1);
}
else
{
ftpClient.removeDirectory(fileName);
monitor.worked(1);
}
if(isFile)
{
throw new RemoteFileIOException(new Exception(ftpClient.getReplyString()+" ("+concat(parentPath,fileName)+")")); //$NON-NLS-1$ //$NON-NLS-2$
}
else //folder recursively
{
String newParentPath = concat(parentPath,fileName);
ftpClient.changeWorkingDirectory(newParentPath);
FTPFile[] fileNames = ftpClient.listFiles();
for (int i = 0; i < fileNames.length; i++) {
String curName = fileNames[i].getName();
if (curName == null || curName.equals(".") || curName.equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$
continue;
}
internalDelete(ftpClient, newParentPath, curName, fileNames[i].isFile(), monitor);
}
//remove empty folder
ftpClient.changeWorkingDirectory(parentPath);
boolean hasSucceeded = ftpClient.removeDirectory(fileName);
if (!hasSucceeded)
{ {
throw new RemoteFileIOException(new Exception(ftpClient.getReplyString() + " (" + concat(parentPath, fileName) + ")")); //$NON-NLS-1$ //$NON-NLS-2$ hasSucceeded = ftpClient.deleteFile(fileName);
monitor.worked(1);
}
else
{
hasSucceeded = ftpClient.removeDirectory(fileName);
monitor.worked(1);
}
}
if(!hasSucceeded){
if(isFile)
{
throw new RemoteFileIOException(new Exception(ftpClient.getReplyString()+" ("+concat(parentPath,fileName)+")")); //$NON-NLS-1$ //$NON-NLS-2$
}
else //folder recursively
{
String newParentPath = concat(parentPath,fileName);
ftpClient.changeWorkingDirectory(newParentPath);
FTPFile[] fileNames = ftpClient.listFiles();
for (int i = 0; i < fileNames.length; i++) {
String curName = fileNames[i].getName();
if (curName == null || curName.equals(".") || curName.equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$
continue;
}
internalDelete(ftpClient, newParentPath, curName, fileNames[i].isFile(), monitor);
}
//remove empty folder
ftpClient.changeWorkingDirectory(parentPath);
hasSucceeded = ftpClient.removeDirectory(fileName);
if (!hasSucceeded)
{
throw new RemoteFileIOException(new Exception(ftpClient.getReplyString() + " (" + concat(parentPath, fileName) + ")")); //$NON-NLS-1$ //$NON-NLS-2$
}
} }
} }
} }
@ -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$
} }
/* /*
@ -1548,7 +1565,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
} catch (IOException e) { } catch (IOException e) {
String pluginId = Activator.getDefault().getBundle().getSymbolicName(); String pluginId = Activator.getDefault().getBundle().getSymbolicName();
String messageText = e.getLocalizedMessage(); String messageText = e.getLocalizedMessage();
SystemMessage message = new SimpleSystemMessage(pluginId, IStatus.ERROR, messageText, e); SystemMessage message = new SimpleSystemMessage(pluginId, IStatus.ERROR, messageText, e);
throw new SystemMessageException(message); throw new SystemMessageException(message);
} finally { } finally {
_commandMutex.release(); _commandMutex.release();
@ -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;