mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-22 15:53:58 +02:00
[180711] Checked return value of Mutex.waitForLock()
This commit is contained in:
parent
f3d3c8b2f7
commit
4b498e3e85
1 changed files with 55 additions and 56 deletions
|
@ -660,6 +660,7 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
|
||||||
*/
|
*/
|
||||||
public boolean download(IProgressMonitor monitor, String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding) throws SystemMessageException
|
public boolean download(IProgressMonitor monitor, String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding) throws SystemMessageException
|
||||||
{
|
{
|
||||||
|
boolean retValue = false;
|
||||||
|
|
||||||
if (monitor!=null){
|
if (monitor!=null){
|
||||||
if (monitor.isCanceled()) {
|
if (monitor.isCanceled()) {
|
||||||
|
@ -667,72 +668,70 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_downloadMutex.waitForLock(monitor, Long.MAX_VALUE);
|
if(_downloadMutex.waitForLock(monitor, Long.MAX_VALUE))
|
||||||
|
|
||||||
MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
|
|
||||||
|
|
||||||
IHostFile remoteHostFile = getFile(null,remoteParent,remoteFile);
|
|
||||||
|
|
||||||
boolean retValue = false;
|
|
||||||
|
|
||||||
FTPClient ftpClient = getFTPClient();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
remoteParent = adaptPath(remoteParent);
|
MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
|
||||||
|
|
||||||
ftpClient.changeWorkingDirectory(remoteParent);
|
IHostFile remoteHostFile = getFile(null,remoteParent,remoteFile);
|
||||||
|
|
||||||
if (isBinary)
|
FTPClient ftpClient = getFTPClient();
|
||||||
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
|
|
||||||
else
|
|
||||||
ftpClient.setFileType(FTP.ASCII_FILE_TYPE);
|
|
||||||
|
|
||||||
if (!localFile.exists())
|
try
|
||||||
{
|
{
|
||||||
File localParentFile = localFile.getParentFile();
|
remoteParent = adaptPath(remoteParent);
|
||||||
if (!localParentFile.exists())
|
|
||||||
|
ftpClient.changeWorkingDirectory(remoteParent);
|
||||||
|
|
||||||
|
if (isBinary)
|
||||||
|
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
|
||||||
|
else
|
||||||
|
ftpClient.setFileType(FTP.ASCII_FILE_TYPE);
|
||||||
|
|
||||||
|
if (!localFile.exists())
|
||||||
{
|
{
|
||||||
localParentFile.mkdirs();
|
File localParentFile = localFile.getParentFile();
|
||||||
|
if (!localParentFile.exists())
|
||||||
|
{
|
||||||
|
localParentFile.mkdirs();
|
||||||
|
}
|
||||||
|
localFile.createNewFile();
|
||||||
}
|
}
|
||||||
localFile.createNewFile();
|
|
||||||
}
|
OutputStream output = new FileOutputStream(localFile);
|
||||||
|
InputStream input = ftpClient.retrieveFileStream(remoteFile);
|
||||||
OutputStream output = new FileOutputStream(localFile);
|
|
||||||
InputStream input = ftpClient.retrieveFileStream(remoteFile);
|
progressMonitor.init(0, remoteFile, localFile.getName(), remoteHostFile.getSize());
|
||||||
|
|
||||||
progressMonitor.init(0, remoteFile, localFile.getName(), remoteHostFile.getSize());
|
byte[] buffer = new byte[4096];
|
||||||
|
|
||||||
byte[] buffer = new byte[4096];
|
int readCount;
|
||||||
|
while((readCount = input.read(buffer)) > 0)
|
||||||
int readCount;
|
{
|
||||||
while((readCount = input.read(buffer)) > 0)
|
output.write(buffer, 0, readCount);
|
||||||
{
|
progressMonitor.count(readCount);
|
||||||
output.write(buffer, 0, readCount);
|
if (monitor!=null){
|
||||||
progressMonitor.count(readCount);
|
if (monitor.isCanceled()) {
|
||||||
if (monitor!=null){
|
retValue = false;
|
||||||
if (monitor.isCanceled()) {
|
break;
|
||||||
retValue = false;
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progressMonitor.end();
|
||||||
|
|
||||||
|
output.flush();
|
||||||
|
input.close();
|
||||||
|
output.close();
|
||||||
|
|
||||||
|
ftpClient.completePendingCommand();
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
progressMonitor.end();
|
{
|
||||||
|
throw new RemoteFileIOException(e);
|
||||||
output.flush();
|
} finally {
|
||||||
input.close();
|
_downloadMutex.release();
|
||||||
output.close();
|
}
|
||||||
|
|
||||||
ftpClient.completePendingCommand();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new RemoteFileIOException(e);
|
|
||||||
} finally {
|
|
||||||
_downloadMutex.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue