mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-14 20:45:22 +02:00
[228230][219792] Fix FTPService implementation problems
This commit is contained in:
parent
6ec42deeac
commit
7c9bd1b6dd
1 changed files with 71 additions and 53 deletions
|
@ -432,7 +432,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
|
|
||||||
for (int i = 0; i < initialCommands.length; i++) {
|
for (int i = 0; i < initialCommands.length; i++) {
|
||||||
_ftpClient.sendCommand(initialCommands[i]);
|
_ftpClient.sendCommand(initialCommands[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_userHome = _ftpClient.printWorkingDirectory();
|
_userHome = _ftpClient.printWorkingDirectory();
|
||||||
|
|
||||||
|
@ -785,6 +785,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
_commandMutex.release();
|
_commandMutex.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (SystemMessageException e) {
|
||||||
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new RemoteFileIOException(e);
|
throw new RemoteFileIOException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -864,11 +866,9 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
bytes+=readCount;
|
bytes+=readCount;
|
||||||
output.write(buffer, 0, readCount);
|
output.write(buffer, 0, readCount);
|
||||||
progressMonitor.count(readCount);
|
progressMonitor.count(readCount);
|
||||||
if (progressMonitor.fMonitor!=null){
|
if (progressMonitor.isCanceled()) {
|
||||||
if (progressMonitor.fMonitor.isCanceled()) {
|
retValue = false;
|
||||||
retValue = false;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (retValue) {
|
if (retValue) {
|
||||||
|
@ -917,14 +917,20 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
try {
|
try {
|
||||||
if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
|
if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
|
||||||
{
|
{
|
||||||
retValue = internalDownload(remoteParent, remoteFile, localFile, isBinary, hostEncoding, progressMonitor);
|
try
|
||||||
|
{
|
||||||
|
retValue = internalDownload(remoteParent, remoteFile, localFile, isBinary, hostEncoding, progressMonitor);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_commandMutex.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new RemoteFileIOException(e);
|
throw new RemoteFileIOException(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RemoteFileIOException(e);
|
throw new RemoteFileIOException(e);
|
||||||
} finally {
|
} finally {
|
||||||
_commandMutex.release();
|
|
||||||
progressMonitor.end();
|
progressMonitor.end();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -945,7 +951,6 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
ftpClient.changeWorkingDirectory(remoteParent);
|
ftpClient.changeWorkingDirectory(remoteParent);
|
||||||
setFileType(isBinary);
|
setFileType(isBinary);
|
||||||
|
|
||||||
output = null;
|
|
||||||
input = ftpClient.retrieveFileStream(remoteFile);
|
input = ftpClient.retrieveFileStream(remoteFile);
|
||||||
|
|
||||||
if(input != null)
|
if(input != null)
|
||||||
|
@ -967,11 +972,9 @@ 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.fMonitor!=null){
|
if (progressMonitor.isCanceled()) {
|
||||||
if (progressMonitor.fMonitor.isCanceled()) {
|
retValue = false;
|
||||||
retValue = false;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1043,35 +1046,32 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
fileName = checkEncoding(fileName);
|
fileName = checkEncoding(fileName);
|
||||||
|
|
||||||
MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
|
MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
|
||||||
progressMonitor.init(FTPServiceResources.FTP_File_Service_Deleting_Task+fileName, 1);
|
progressMonitor.init(FTPServiceResources.FTP_File_Service_Deleting_Task + fileName, IProgressMonitor.UNKNOWN);
|
||||||
|
try {
|
||||||
|
IHostFile file = getFile(remoteParent, fileName, monitor);
|
||||||
|
|
||||||
IHostFile file = getFile(remoteParent, fileName, monitor);
|
if (_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) {
|
||||||
|
try {
|
||||||
if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) {
|
FTPClient ftpClient = getFTPClient();
|
||||||
try {
|
hasSucceeded = internalDelete(ftpClient, remoteParent, fileName, file.isFile(), progressMonitor);
|
||||||
FTPClient ftpClient = getFTPClient();
|
}
|
||||||
|
catch (IOException e)
|
||||||
hasSucceeded = internalDelete(ftpClient,file.getParentPath(),file.getName(),file.isFile(),monitor);
|
|
||||||
|
|
||||||
if(hasSucceeded)
|
|
||||||
{
|
{
|
||||||
monitor.worked(1);
|
throw new RemoteFileIOException(e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
_commandMutex.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(IOException e)
|
} finally {
|
||||||
{
|
progressMonitor.end();
|
||||||
throw new RemoteFileIOException(e);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
_commandMutex.release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
progressMonitor.end();
|
// Can only return true since !hasSucceeded always leads to Exception
|
||||||
|
|
||||||
return hasSucceeded;
|
return hasSucceeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean internalDelete(FTPClient ftpClient, String parentPath, String fileName, boolean isFile, IProgressMonitor monitor) throws RemoteFileException, IOException
|
private boolean internalDelete(FTPClient ftpClient, String parentPath, String fileName, boolean isFile, MyProgressMonitor monitor)
|
||||||
|
throws RemoteFileException, IOException
|
||||||
{
|
{
|
||||||
if(monitor.isCanceled())
|
if(monitor.isCanceled())
|
||||||
{
|
{
|
||||||
|
@ -1080,16 +1080,19 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
|
|
||||||
clearCache(parentPath);
|
clearCache(parentPath);
|
||||||
boolean hasSucceeded = FTPReply.isPositiveCompletion(ftpClient.cwd(parentPath));
|
boolean hasSucceeded = FTPReply.isPositiveCompletion(ftpClient.cwd(parentPath));
|
||||||
|
monitor.worked(1);
|
||||||
|
|
||||||
if(hasSucceeded)
|
if(hasSucceeded)
|
||||||
{
|
{
|
||||||
if(isFile)
|
if(isFile)
|
||||||
{
|
{
|
||||||
hasSucceeded = ftpClient.deleteFile(fileName);
|
hasSucceeded = ftpClient.deleteFile(fileName);
|
||||||
|
monitor.worked(1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hasSucceeded = ftpClient.removeDirectory(fileName);
|
hasSucceeded = ftpClient.removeDirectory(fileName);
|
||||||
|
monitor.worked(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1106,23 +1109,24 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
FTPFile[] fileNames = ftpClient.listFiles();
|
FTPFile[] fileNames = ftpClient.listFiles();
|
||||||
|
|
||||||
for (int i = 0; i < fileNames.length; i++) {
|
for (int i = 0; i < fileNames.length; i++) {
|
||||||
if(fileNames[i].getName().equals(".") || fileNames[i].getName().equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$
|
String curName = fileNames[i].getName();
|
||||||
|
if (curName == null || curName.equals(".") || curName.equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
hasSucceeded = internalDelete(ftpClient,newParentPath,fileNames[i].getName(),fileNames[i].isFile(),monitor);
|
hasSucceeded = internalDelete(ftpClient, newParentPath, curName, fileNames[i].isFile(), monitor);
|
||||||
if(!hasSucceeded)
|
|
||||||
{
|
|
||||||
throw new RemoteFileIOException(new Exception(ftpClient.getReplyString()+" ("+concat(newParentPath,fileNames[i].getName())+")")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove empty folder
|
//remove empty folder
|
||||||
ftpClient.changeWorkingDirectory(parentPath);
|
ftpClient.changeWorkingDirectory(parentPath);
|
||||||
hasSucceeded = ftpClient.removeDirectory(fileName);
|
hasSucceeded = ftpClient.removeDirectory(fileName);
|
||||||
|
if (!hasSucceeded)
|
||||||
|
{
|
||||||
|
throw new RemoteFileIOException(new Exception(ftpClient.getReplyString() + " (" + concat(parentPath, fileName) + ")")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Can only return true since !hasSucceeded always leads to Exception
|
||||||
return hasSucceeded;
|
return hasSucceeded;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1314,7 +1318,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
|
|
||||||
private boolean internalCopy(FTPClient ftpClient, String srcParent, String srcName, String tgtParent, String tgtName, boolean isDirectory, MyProgressMonitor monitor) throws SystemMessageException, IOException
|
private boolean internalCopy(FTPClient ftpClient, String srcParent, String srcName, String tgtParent, String tgtName, boolean isDirectory, MyProgressMonitor monitor) throws SystemMessageException, IOException
|
||||||
{
|
{
|
||||||
if(monitor.fMonitor.isCanceled())
|
if (monitor.isCanceled())
|
||||||
{
|
{
|
||||||
throw new RemoteFileCancelledException();
|
throw new RemoteFileCancelledException();
|
||||||
}
|
}
|
||||||
|
@ -1325,6 +1329,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
{
|
{
|
||||||
|
|
||||||
//create folder
|
//create folder
|
||||||
|
// TODO what happens if the destination folder already exists?
|
||||||
|
// Success=true or false?
|
||||||
success = ftpClient.makeDirectory(concat(tgtParent,tgtName));
|
success = ftpClient.makeDirectory(concat(tgtParent,tgtName));
|
||||||
|
|
||||||
//copy contents
|
//copy contents
|
||||||
|
@ -1335,10 +1341,12 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
FTPFile[] fileNames = ftpClient.listFiles();
|
FTPFile[] fileNames = ftpClient.listFiles();
|
||||||
|
|
||||||
for (int i = 0; i < fileNames.length; i++) {
|
for (int i = 0; i < fileNames.length; i++) {
|
||||||
if(fileNames[i].getName().equals(".") || fileNames[i].getName().equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$
|
String curName = fileNames[i].getName();
|
||||||
|
if (curName == null || curName.equals(".") || curName.equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
success = internalCopy(ftpClient,newSrcParentPath,fileNames[i].getName(), newTgtParentPath, fileNames[i].getName(), fileNames[i].isDirectory(),monitor);
|
// TODO should we bail out in case a single file fails?
|
||||||
|
success = internalCopy(ftpClient, newSrcParentPath, curName, newTgtParentPath, curName, fileNames[i].isDirectory(), monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1354,13 +1362,14 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Use binary raw transfer since the file will be uploaded again
|
//Use binary raw transfer since the file will be uploaded again
|
||||||
|
try {
|
||||||
success = internalDownload(srcParent, srcName, tempFile, true, null, monitor);
|
success = internalDownload(srcParent, srcName, tempFile, true, null, monitor);
|
||||||
|
if (success) {
|
||||||
if(success)
|
success = internalUpload(tempFile, tgtParent, tgtName, true, null, null, monitor);
|
||||||
{
|
}
|
||||||
success = internalUpload(tempFile,tgtParent,tgtName,true,null,null,monitor);
|
} finally {
|
||||||
}
|
tempFile.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
@ -1508,7 +1517,16 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
||||||
private long fWorkToDate;
|
private long fWorkToDate;
|
||||||
|
|
||||||
public MyProgressMonitor(IProgressMonitor monitor) {
|
public MyProgressMonitor(IProgressMonitor monitor) {
|
||||||
fMonitor = monitor;
|
if (monitor == null) {
|
||||||
|
fMonitor = new NullProgressMonitor();
|
||||||
|
} else {
|
||||||
|
fMonitor = monitor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCanceled() {
|
||||||
|
// embedded null progress monitor is never canceled
|
||||||
|
return fMonitor.isCanceled();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(int op, String src, String dest, long max){
|
public void init(int op, String src, String dest, long max){
|
||||||
|
|
Loading…
Add table
Reference in a new issue