1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 18:35:32 +02:00

[187096] Fix invalid use of Mutex

This commit is contained in:
Martin Oberhuber 2007-05-18 10:36:17 +00:00
parent 4892a31c45
commit b4d23ea0c6

View file

@ -464,24 +464,21 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
{ {
if (fileFilter == null)
{
fileFilter = "*"; //$NON-NLS-1$
}
IMatcher filematcher = null;
if (fileFilter.endsWith(",")) { //$NON-NLS-1$
String[] types = fileFilter.split(","); //$NON-NLS-1$
filematcher = new FileTypeMatcher(types, true);
} else {
filematcher = new NamePatternMatcher(fileFilter, true, true);
}
try try
{ {
_ftpClient = getFTPClient(); if (fileFilter == null)
{
fileFilter = "*"; //$NON-NLS-1$
}
IMatcher filematcher = null;
if (fileFilter.endsWith(",")) { //$NON-NLS-1$
String[] types = fileFilter.split(","); //$NON-NLS-1$
filematcher = new FileTypeMatcher(types, true);
} else {
filematcher = new NamePatternMatcher(fileFilter, true, true);
}
_ftpClient = getFTPClient();
if(!_ftpClient.changeWorkingDirectory(parentPath)) if(!_ftpClient.changeWorkingDirectory(parentPath))
{ {
throw new RemoteFileIOException(new Exception(_ftpClient.getReplyString())); throw new RemoteFileIOException(new Exception(_ftpClient.getReplyString()));
@ -543,16 +540,12 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
{ {
FTPClient ftpClient = getFTPClient();
MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
try try
{ {
MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
FTPClient ftpClient = getFTPClient();
ftpClient.changeWorkingDirectory(remoteParent); ftpClient.changeWorkingDirectory(remoteParent);
setFileType(isBinary); setFileType(isBinary);
FileInputStream input = new FileInputStream(localFile); FileInputStream input = new FileInputStream(localFile);
@ -661,19 +654,17 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
{ {
FTPClient ftpClient = getFTPClient();
MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
//IHostFile remoteHostFile = null;
OutputStream output = null;
InputStream input = null;
try try
{ {
FTPClient ftpClient = getFTPClient();
MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
//IHostFile remoteHostFile = null;
OutputStream output = null;
InputStream input = null;
ftpClient.changeWorkingDirectory(remoteParent); ftpClient.changeWorkingDirectory(remoteParent);
setFileType(isBinary); setFileType(isBinary);
if (!localFile.exists()) if (!localFile.exists())
{ {
File localParentFile = localFile.getParentFile(); File localParentFile = localFile.getParentFile();
@ -687,23 +678,11 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
output = new FileOutputStream(localFile); output = new FileOutputStream(localFile);
input = ftpClient.retrieveFileStream(remoteFile); input = ftpClient.retrieveFileStream(remoteFile);
} if(remoteHostFile != null && input != null)
catch (Exception e) {
{ progressMonitor.init(0, remoteFile, localFile.getName(), remoteHostFile.getSize());
throw new RemoteFileIOException(e); byte[] buffer = new byte[4096];
} int readCount;
if(remoteHostFile != null && input != null)
{
progressMonitor.init(0, remoteFile, localFile.getName(), remoteHostFile.getSize());
byte[] buffer = new byte[4096];
int readCount;
try{
while((readCount = input.read(buffer)) > 0) while((readCount = input.read(buffer)) > 0)
{ {
output.write(buffer, 0, readCount); output.write(buffer, 0, readCount);
@ -723,16 +702,15 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
output.close(); output.close();
ftpClient.completePendingCommand(); ftpClient.completePendingCommand();
}catch(IOException e)
{
e.printStackTrace();
}
finally {
_commandMutex.release();
} }
} }
catch (Exception e)
{
throw new RemoteFileIOException(e);
} finally
{
_commandMutex.release();
}
} }
return retValue; return retValue;
} }
@ -828,10 +806,8 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
{ {
FTPClient ftpClient = getFTPClient();
try { try {
FTPClient ftpClient = getFTPClient();
String source = remoteParent.endsWith(String.valueOf(getSeparator())) ? remoteParent + oldName : remoteParent + getSeparator() + oldName; String source = remoteParent.endsWith(String.valueOf(getSeparator())) ? remoteParent + oldName : remoteParent + getSeparator() + oldName;
@ -872,10 +848,8 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
{ {
FTPClient ftpClient = getFTPClient();
try{ try{
FTPClient ftpClient = getFTPClient();
String source = srcParent.endsWith(String.valueOf(getSeparator())) ? srcParent + srcName : srcParent + getSeparator() + srcName; String source = srcParent.endsWith(String.valueOf(getSeparator())) ? srcParent + srcName : srcParent + getSeparator() + srcName;
String target = tgtParent.endsWith(String.valueOf(getSeparator())) ? tgtParent + tgtName : tgtParent + getSeparator() + tgtName; String target = tgtParent.endsWith(String.valueOf(getSeparator())) ? tgtParent + tgtName : tgtParent + getSeparator() + tgtName;
@ -904,10 +878,9 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
{ {
if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
{ {
FTPClient ftpClient = getFTPClient();
try try
{ {
FTPClient ftpClient = getFTPClient();
if(!ftpClient.changeWorkingDirectory(remoteParent)) if(!ftpClient.changeWorkingDirectory(remoteParent))
{ {
throw new Exception(ftpClient.getReplyString()+" ("+remoteParent+")"); //$NON-NLS-1$ //$NON-NLS-2$ throw new Exception(ftpClient.getReplyString()+" ("+remoteParent+")"); //$NON-NLS-1$ //$NON-NLS-2$