From ba07826c2fe608368a799d8cffb70dc86f3ddf03 Mon Sep 17 00:00:00 2001 From: David Dykstal Date: Mon, 5 May 2008 22:40:04 +0000 Subject: [PATCH] [221211] [api][breaking][files] need batch operations to indicate which operations were successful https://bugs.eclipse.org/bugs/show_bug.cgi?id=221211 --- .../dstore/files/DStoreFileService.java | 234 ++++++++---------- .../services/files/ftp/FTPService.java | 222 ++++++----------- .../local/files/LocalFileService.java | 187 +++++++------- .../services/ssh/files/SftpFileService.java | 58 ++--- .../services/files/AbstractFileService.java | 37 ++- .../rse/services/files/IFileService.java | 69 ++---- .../FileServiceSubSystem.java | 37 ++- 7 files changed, 364 insertions(+), 480 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/files/DStoreFileService.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/files/DStoreFileService.java index 3c2422e72b7..b77e4c9c083 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/files/DStoreFileService.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/files/DStoreFileService.java @@ -58,6 +58,7 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -272,7 +273,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer - public boolean upload(InputStream inputStream, String remoteParent, String remoteFile, boolean isBinary, + public void upload(InputStream inputStream, String remoteParent, String remoteFile, boolean isBinary, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException { BufferedInputStream bufInputStream = null; @@ -438,12 +439,10 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer throw new RemoteFileCancelledException(); } } - - return true; } - public boolean upload(File file, String remoteParent, String remoteFile, boolean isBinary, + public void upload(File file, String remoteParent, String remoteFile, boolean isBinary, String srcEncoding, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException { FileInputStream inputStream = null; @@ -658,12 +657,10 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer // } } } - - return true; } - public boolean download(String remoteParent, String remoteFile, File localFile, boolean isBinary, + public void download(String remoteParent, String remoteFile, File localFile, boolean isBinary, String encoding, IProgressMonitor monitor) throws SystemMessageException { DataStore ds = getDataStore(); @@ -672,12 +669,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer //int mode = isBinary ? IUniversalDataStoreConstants.BINARY_MODE : IUniversalDataStoreConstants.TEXT_MODE; int mode = IUniversalDataStoreConstants.BINARY_MODE; - if (!makeSureLocalExists(localFile)) - { - FileNotFoundException e = new FileNotFoundException(); - throw new RemoteFileIOException(e); - } - + makeSureLocalExists(localFile); String remotePath = remoteParent + getSeparator(remoteParent) + remoteFile; @@ -779,10 +771,6 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer codePageConverter.convertFileFromRemoteEncoding(remotePath, localFile, encoding, localEncoding, this); } - - - - return true; } else if (resultChild.getType().equals(IUniversalDataStoreConstants.DOWNLOAD_RESULT_FILE_NOT_FOUND_EXCEPTION)) { @@ -825,10 +813,9 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer { //monitor.done(); } - return true; } - private boolean makeSureLocalExists(File localFile) + private void makeSureLocalExists(File localFile) throws SystemMessageException { if (!localFile.exists()) { @@ -844,19 +831,18 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer } catch (IOException e) { - return false; + SimpleSystemMessage message = new SimpleSystemMessage(Activator.PLUGIN_ID, IStatus.ERROR, e.getLocalizedMessage()); + throw new SystemMessageException(message); } - return true; } /** * Default implementation - just iterate through each file */ - public boolean downloadMultiple(String[] remoteParents, String[] remoteFiles, + public void downloadMultiple(String[] remoteParents, String[] remoteFiles, File[] localFiles, boolean[] isBinaries, String[] hostEncodings, IProgressMonitor monitor) throws SystemMessageException { - boolean result = true; List downloadListeners = new ArrayList(); @@ -900,7 +886,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer // kick off all downloads - for (int i = 0; i < des.length && result == true; i++) + for (int i = 0; i < des.length; i++) { int mode = IUniversalDataStoreConstants.BINARY_MODE; DataElement de = des[i]; @@ -909,11 +895,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer File localFile = localFiles[i]; String hostEncoding = hostEncodings[i]; - if (!makeSureLocalExists(localFile)) - { - FileNotFoundException e = new FileNotFoundException(); - throw new RemoteFileIOException(e); - } + makeSureLocalExists(localFile); long fileLength = DStoreHostFile.getFileLength(de.getSource()); if (monitor != null) @@ -1018,8 +1000,6 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer codePageConverter.convertFileFromRemoteEncoding(remoteElement.getName(), localFile, hostEncodings[i], localEncoding, this); } - - result = true; } else if (resultChild.getType().equals(IUniversalDataStoreConstants.DOWNLOAD_RESULT_FILE_NOT_FOUND_EXCEPTION)) { @@ -1034,12 +1014,19 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer } else if (resultChild.getType().equals(IUniversalDataStoreConstants.DOWNLOAD_RESULT_UNSUPPORTED_ENCODING_EXCEPTION)) { + // TODO inspect this + localFile.delete(); + String msgTxt = ServiceResources.FILEMSG_SECURITY_ERROR; + String msgDetails = NLS.bind(ServiceResources.FILEMSG_SECURITY_ERROR_DETAILS, IUniversalDataStoreConstants.DOWNLOAD_RESULT_UNSUPPORTED_ENCODING_EXCEPTION); + SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, + IDStoreMessageIds.FILEMSG_SECURITY_ERROR, + IStatus.ERROR, msgTxt, msgDetails); + throw new SystemMessageException(msg); //SystemMessage msg = getMessage(); //throw new SystemMessageException(msg); //UnsupportedEncodingException e = new UnsupportedEncodingException(resultChild.getName()); //UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error reading file " + remotePath, e); //throw new RemoteFileIOException(e); - result = false; } else if (resultChild.getType().equals(IUniversalDataStoreConstants.DOWNLOAD_RESULT_IO_EXCEPTION)) @@ -1057,7 +1044,14 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer } else { - result = false; + // TODO inspect this + localFile.delete(); + String msgTxt = ServiceResources.FILEMSG_SECURITY_ERROR; + String msgDetails = NLS.bind(ServiceResources.FILEMSG_SECURITY_ERROR_DETAILS, IUniversalDataStoreConstants.DOWNLOAD_RESULT_IO_EXCEPTION); + SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, + IDStoreMessageIds.FILEMSG_SECURITY_ERROR, + IStatus.ERROR, msgTxt, msgDetails); + throw new SystemMessageException(msg); } } @@ -1067,19 +1061,17 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer } } } - return result; } /** * Default implementation - just iterate through each file */ - public boolean uploadMultiple(File[] localFiles, String[] remoteParents, + public void uploadMultiple(File[] localFiles, String[] remoteParents, String[] remoteFiles, boolean[] isBinaries, String[] srcEncodings, String[] hostEncodings, IProgressMonitor monitor) throws SystemMessageException { - boolean result = true; - for (int i = 0; i < localFiles.length && result == true; i++) + for (int i = 0; i < localFiles.length; i++) { File localFile = localFiles[i]; String remoteParent = remoteParents[i]; @@ -1088,9 +1080,8 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer boolean isBinary = isBinaries[i]; String srcEncoding = srcEncodings[i]; String hostEncoding = hostEncodings[i]; - result = upload(localFile, remoteParent, remoteFile, isBinary, srcEncoding, hostEncoding, monitor); + upload(localFile, remoteParent, remoteFile, isBinary, srcEncoding, hostEncoding, monitor); } - return result; } private DataElement getSubjectFor(String remoteParent, String name) @@ -1359,7 +1350,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer } - public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException + public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException { String remotePath = remoteParent + getSeparator(remoteParent) + fileName; DataElement de = getElementFor(remotePath); @@ -1382,21 +1373,23 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer // When running a server older than 2.0.1 success is not set for directories, so we must // check if the source message is an empty string if (sourceMsg.equals(IServiceConstants.SUCCESS) || sourceMsg.equals("")) { //$NON-NLS-1$ - return true; - } else { - String msgTxt = NLS.bind(ServiceResources.FILEMSG_DELETE_FILE_FAILED, FileSystemMessageUtil.getSourceLocation(status)); - String msgDetails = ServiceResources.FILEMSG_DELETE_FILE_FAILED_DETAILS; - SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, - IDStoreMessageIds.FILEMSG_DELETE_FILE_FAILED, - IStatus.ERROR, msgTxt, msgDetails); - - throw new SystemMessageException(msg); + return; } + String msgTxt = NLS.bind(ServiceResources.FILEMSG_DELETE_FILE_FAILED, FileSystemMessageUtil.getSourceLocation(status)); + String msgDetails = ServiceResources.FILEMSG_DELETE_FILE_FAILED_DETAILS; + SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, + IDStoreMessageIds.FILEMSG_DELETE_FILE_FAILED, + IStatus.ERROR, msgTxt, msgDetails); + + throw new SystemMessageException(msg); } - public boolean deleteBatch(String[] remoteParents, String[] fileNames, IProgressMonitor monitor) throws SystemMessageException + public void deleteBatch(String[] remoteParents, String[] fileNames, IProgressMonitor monitor) throws SystemMessageException { - if (remoteParents.length == 1) return delete(remoteParents[0], fileNames[0], monitor); + if (remoteParents.length == 1) { + delete(remoteParents[0], fileNames[0], monitor); + return; + } ArrayList dataElements = new ArrayList(remoteParents.length); for (int i = 0; i < remoteParents.length; i++) @@ -1420,31 +1413,27 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer // When running a server older than 2.0.1 success is not set for directories, so we must // check if the source message is an empty string if (sourceMsg.equals(IServiceConstants.SUCCESS) || sourceMsg.equals("")) { //$NON-NLS-1$ - return true; - } else { - String msgTxt = NLS.bind(ServiceResources.FILEMSG_DELETE_FILE_FAILED, FileSystemMessageUtil.getSourceLocation(status)); - String msgDetails = ServiceResources.FILEMSG_DELETE_FILE_FAILED_DETAILS; - SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, - IDStoreMessageIds.FILEMSG_DELETE_FILE_FAILED, - IStatus.ERROR, msgTxt, msgDetails); - - throw new SystemMessageException(msg); + return; } + String msgTxt = NLS.bind(ServiceResources.FILEMSG_DELETE_FILE_FAILED, FileSystemMessageUtil.getSourceLocation(status)); + String msgDetails = ServiceResources.FILEMSG_DELETE_FILE_FAILED_DETAILS; + SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, + IDStoreMessageIds.FILEMSG_DELETE_FILE_FAILED, + IStatus.ERROR, msgTxt, msgDetails); + + throw new SystemMessageException(msg); } else { // no delete batch descriptor so need to fall back to single command approach - boolean result = true; - for (int i = 0; i < remoteParents.length && result; i++){ + for (int i = 0; i < remoteParents.length; i++){ String parent = remoteParents[i]; String name = fileNames[i]; - result = delete(parent, name, monitor); + delete(parent, name, monitor); } - return result; - } } - public boolean rename(String remoteParent, String oldName, String newName, IProgressMonitor monitor) throws SystemMessageException + public void rename(String remoteParent, String oldName, String newName, IProgressMonitor monitor) throws SystemMessageException { String oldPath, newPath = null; // if remoteParent is null or empty then we are doing a move @@ -1498,57 +1487,48 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer //This operation has been cancelled by the user. throw new SystemMessageException(msg); } - if (FileSystemMessageUtil.getSourceMessage(status).equals(IServiceConstants.SUCCESS)) - return true; - else - { - String msgTxt = NLS.bind(ServiceResources.FILEMSG_RENAME_FILE_FAILED, FileSystemMessageUtil.getSourceLocation(status)); - String msgDetails = ServiceResources.FILEMSG_RENAME_FILE_FAILED_DETAILS; - SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, - IDStoreMessageIds.FILEMSG_RENAME_FILE_FAILED, - IStatus.ERROR, msgTxt, msgDetails); - - throw new SystemMessageException(msg); + if (FileSystemMessageUtil.getSourceMessage(status).equals(IServiceConstants.SUCCESS)) { + return; } + String msgTxt = NLS.bind(ServiceResources.FILEMSG_RENAME_FILE_FAILED, FileSystemMessageUtil.getSourceLocation(status)); + String msgDetails = ServiceResources.FILEMSG_RENAME_FILE_FAILED_DETAILS; + SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, + IDStoreMessageIds.FILEMSG_RENAME_FILE_FAILED, + IStatus.ERROR, msgTxt, msgDetails); + + throw new SystemMessageException(msg); } - public boolean rename(String remoteParent, String oldName, String newName, IHostFile oldFile, IProgressMonitor monitor) throws SystemMessageException + public void rename(String remoteParent, String oldName, String newName, IHostFile oldFile, IProgressMonitor monitor) throws SystemMessageException { - boolean retVal = rename(remoteParent, oldName, newName, monitor); + rename(remoteParent, oldName, newName, monitor); String newPath = remoteParent + getSeparator(remoteParent) + newName; oldFile.renameTo(newPath); - return retVal; } - protected boolean moveByCopy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException + protected void moveByCopy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException { - boolean movedOk = false; - - if (copy(srcParent, srcName, tgtParent, tgtName, monitor)) + copy(srcParent, srcName, tgtParent, tgtName, monitor); + try { - try - { - movedOk = delete(srcParent, srcName, monitor); - } - catch (SystemMessageException exc) - { - if (null != monitor && monitor.isCanceled()) - { - //This mean the copy operation is ok, but delete operation has been cancelled by user. - //The delete() call will take care of recovered from the cancel operation. - //So we need to make sure to remove the already copied file/folder. - getFile(tgtParent, tgtName, null); //need to call getFile first to put this object into DataElement map first - //otherwise it type will default to FilterObject, and could not be deleted properly for virtual object. - delete(tgtParent, tgtName, null); - } - throw exc; - } + delete(srcParent, srcName, monitor); + } + catch (SystemMessageException exc) + { + if (null != monitor && monitor.isCanceled()) + { + //This mean the copy operation is ok, but delete operation has been cancelled by user. + //The delete() call will take care of recovered from the cancel operation. + //So we need to make sure to remove the already copied file/folder. + getFile(tgtParent, tgtName, null); //need to call getFile first to put this object into DataElement map first + //otherwise it type will default to FilterObject, and could not be deleted properly for virtual object. + delete(tgtParent, tgtName, null); + } + throw exc; } - - return movedOk; } - public boolean move(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException + public void move(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException { String src = srcParent + getSeparator(srcParent) + srcName; String tgt = tgtParent + getSeparator(tgtParent) + tgtName; @@ -1556,25 +1536,20 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer boolean isArchive = ArchiveHandlerManager.getInstance().isRegisteredArchive(tgt); if (isVirtual || isArchive) { - return moveByCopy(srcParent, srcName, tgtParent, tgtName, monitor); + moveByCopy(srcParent, srcName, tgtParent, tgtName, monitor); } else { - boolean movedOk = false; try { - movedOk = rename("", src, tgt, monitor); //$NON-NLS-1$ + rename("", src, tgt, monitor); //$NON-NLS-1$ } catch (SystemMessageException e) { - return moveByCopy(srcParent, srcName, tgtParent, tgtName, monitor); + moveByCopy(srcParent, srcName, tgtParent, tgtName, monitor); } // movedOk should never be false otherwise the last DataElement status was null - if (!movedOk) - { - movedOk = moveByCopy(srcParent, srcName, tgtParent, tgtName, monitor); - } - return movedOk; + moveByCopy(srcParent, srcName, tgtParent, tgtName, monitor); } /* @@ -1669,7 +1644,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer } } - public boolean copy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException + public void copy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException { DataStore ds = getDataStore(); String srcRemotePath = srcParent + getSeparator(srcParent) + srcName; @@ -1722,7 +1697,6 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer monitor.setCanceled(true); } } - return true; } else { throw new SystemMessageException(new SimpleSystemMessage(Activator.PLUGIN_ID, @@ -1732,7 +1706,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer } } - public boolean copyBatch(String[] srcParents, String[] srcNames, String tgtParent, IProgressMonitor monitor) throws SystemMessageException + public void copyBatch(String[] srcParents, String[] srcNames, String tgtParent, IProgressMonitor monitor) throws SystemMessageException { DataStore ds = getDataStore(); @@ -1788,18 +1762,14 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer //InterruptedException is used to report user cancellation, so no need to log //This should be reviewed (use OperationCanceledException) with bug #190750 } - return true; } else { // no copy batch descriptor so need to fall back to single command approach - boolean result = true; - for (int i = 0; i < srcParents.length && result; i++){ + for (int i = 0; i < srcParents.length; i++){ String parent = srcParents[i]; String name = srcNames[i]; - result = copy(parent, name, tgtParent, name, monitor); + copy(parent, name, tgtParent, name, monitor); } - return result; - } } @@ -1875,17 +1845,18 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer } - public IHostFile[] listMultiple(String[] remoteParents, - String[] fileFilters, int[] fileTypes, IProgressMonitor monitor) + public void listMultiple(String[] remoteParents, + String[] fileFilters, int[] fileTypes, List hostFiles, IProgressMonitor monitor) throws SystemMessageException { String[] queryStrings = getQueryStrings(fileTypes); - return fetchMulti(remoteParents, fileFilters, queryStrings, monitor); + IHostFile[] result = fetchMulti(remoteParents, fileFilters, queryStrings, monitor); + hostFiles.addAll(Arrays.asList(result)); } - public IHostFile[] listMultiple(String[] remoteParents, - String[] fileFilters, int fileType, IProgressMonitor monitor) + public void listMultiple(String[] remoteParents, + String[] fileFilters, int fileType, List hostFiles, IProgressMonitor monitor) throws SystemMessageException { String queryString = getQueryString(fileType); @@ -1897,7 +1868,8 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer queryStrings[i] = queryString; } - return fetchMulti(remoteParents, fileFilters, queryStrings, monitor); + IHostFile[] result = fetchMulti(remoteParents, fileFilters, queryStrings, monitor); + hostFiles.addAll(Arrays.asList(result)); } protected String[] getPathsFor(String[] remoteParents, String[] remoteFiles) @@ -2051,7 +2023,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer return true; } - public boolean setLastModified(String parent, String name, + public void setLastModified(String parent, String name, long timestamp, IProgressMonitor monitor) throws SystemMessageException { String remotePath = parent + getSeparator(parent) + name; @@ -2065,7 +2037,6 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer // first modify the source attribute to temporarily be the date field de.setAttribute(DE.A_SOURCE, timestamp + ""); //$NON-NLS-1$ ds.command(setCmd, de, true); - return true; } } throw new SystemMessageException(new SimpleSystemMessage(Activator.PLUGIN_ID, @@ -2074,7 +2045,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer CommonMessages.MSG_ERROR_UNEXPECTED)); } - public boolean setReadOnly(String parent, String name, + public void setReadOnly(String parent, String name, boolean readOnly, IProgressMonitor monitor) throws SystemMessageException { String remotePath = parent + getSeparator(parent) + name; @@ -2096,7 +2067,6 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer { throw new RemoteFileIOException(e); } - return true; } } throw new SystemMessageException(new SimpleSystemMessage(Activator.PLUGIN_ID, diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/internal/services/files/ftp/FTPService.java b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/internal/services/files/ftp/FTPService.java index d4f945eeb97..741ae8bef1c 100644 --- a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/internal/services/files/ftp/FTPService.java +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/internal/services/files/ftp/FTPService.java @@ -99,6 +99,7 @@ import org.apache.commons.net.ftp.FTPClientConfig; import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPReply; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.rse.core.model.IPropertySet; @@ -109,6 +110,7 @@ import org.eclipse.rse.services.clientserver.FileTypeMatcher; import org.eclipse.rse.services.clientserver.IMatcher; import org.eclipse.rse.services.clientserver.NamePatternMatcher; import org.eclipse.rse.services.clientserver.PathUtility; +import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.services.files.AbstractFileService; @@ -756,9 +758,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil * (non-Javadoc) * @see org.eclipse.rse.services.files.IFileService#upload(org.eclipse.core.runtime.IProgressMonitor, java.io.File, java.lang.String, java.lang.String, boolean, java.lang.String, java.lang.String) */ - public boolean upload(File localFile, String remoteParent, String remoteFile, boolean isBinary, String srcEncoding, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException + public void upload(File localFile, String remoteParent, String remoteFile, boolean isBinary, String srcEncoding, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException { - boolean retValue = true; remoteParent = checkEncoding(remoteParent); remoteFile = checkEncoding(remoteFile); @@ -779,7 +780,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil { try { - retValue = internalUpload(localFile, remoteParent, remoteFile, isBinary, srcEncoding, hostEncoding, progressMonitor); + internalUpload(localFile, remoteParent, remoteFile, isBinary, srcEncoding, hostEncoding, progressMonitor); } finally { _commandMutex.release(); @@ -792,17 +793,14 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil } finally { progressMonitor.end(); } - - return retValue; } /* * (non-Javadoc) * @see org.eclipse.rse.services.files.IFileService#upload(org.eclipse.core.runtime.IProgressMonitor, java.io.InputStream, java.lang.String, java.lang.String, boolean, java.lang.String) */ - public boolean upload(InputStream stream, String remoteParent, String remoteFile, boolean isBinary, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException + public void upload(InputStream stream, String remoteParent, String remoteFile, boolean isBinary, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException { - boolean retValue = true; remoteParent = checkEncoding(remoteParent); remoteFile = checkEncoding(remoteFile); @@ -818,31 +816,24 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil while( (readCount = bis.read(buffer)) > 0) { bos.write(buffer, 0, readCount); - if (monitor!=null){ + if (monitor!=null) { if (monitor.isCanceled()) { - retValue = false; break; } - } + } } bos.close(); - - if(retValue == true){ - retValue = upload(tempFile, remoteParent, remoteFile, isBinary, null, hostEncoding, monitor); - } + upload(tempFile, remoteParent, remoteFile, isBinary, null, hostEncoding, monitor); } catch (Exception e) { throw new RemoteFileIOException(e); } - return retValue; - } - private boolean internalUpload(File localFile, String remoteParent, String remoteFile, boolean isBinary, String srcEncoding, String hostEncoding, MyProgressMonitor progressMonitor) throws IOException, RemoteFileIOException + private void internalUpload(File localFile, String remoteParent, String remoteFile, boolean isBinary, String srcEncoding, String hostEncoding, MyProgressMonitor progressMonitor) throws IOException, RemoteFileIOException, SystemMessageException { - boolean retValue = true; InputStream input = null; OutputStream output = null; @@ -867,22 +858,17 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil output.write(buffer, 0, readCount); progressMonitor.count(readCount); if (progressMonitor.isCanceled()) { - retValue = false; - break; + throw new RemoteFileCancelledException(); } } - if (retValue) { - output.flush(); - } + output.flush(); output.close(); output = null; ftpClient.completePendingCommand(); } else { throw new RemoteFileIOException(new Exception(ftpClient.getReplyString())); } - if(retValue==false) { - ftpClient.deleteFile(remoteFile); - } + ftpClient.deleteFile(remoteFile); }finally{ try { @@ -891,8 +877,6 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil if (output!=null) output.close(); } } - - return retValue; } @@ -900,9 +884,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil * (non-Javadoc) * @see org.eclipse.rse.services.files.IFileService#download(org.eclipse.core.runtime.IProgressMonitor, java.lang.String, java.lang.String, java.io.File, boolean, java.lang.String) */ - public boolean download(String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException + public void download(String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException { - boolean retValue = true; if (monitor!=null){ if (monitor.isCanceled()) { @@ -919,7 +902,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil { try { - retValue = internalDownload(remoteParent, remoteFile, localFile, isBinary, hostEncoding, progressMonitor); + internalDownload(remoteParent, remoteFile, localFile, isBinary, hostEncoding, progressMonitor); } finally { @@ -934,14 +917,10 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil progressMonitor.end(); } - - return retValue; } - private boolean internalDownload(String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding, MyProgressMonitor progressMonitor) throws SystemMessageException, IOException + private void internalDownload(String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding, MyProgressMonitor progressMonitor) throws SystemMessageException, IOException { - boolean retValue = true; - InputStream input = null; OutputStream output = null; @@ -968,17 +947,20 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil output = new FileOutputStream(localFile); byte[] buffer = new byte[4096]; int readCount; + boolean ok = true; while((readCount = input.read(buffer)) > 0) { output.write(buffer, 0, readCount); progressMonitor.count(readCount); if (progressMonitor.isCanceled()) { - retValue = false; + ok = false; break; } } - if (retValue) output.flush(); + if (ok) { + output.flush(); + } input.close(); input = null; ftpClient.completePendingCommand(); @@ -996,8 +978,6 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil if (output!=null) output.close(); } } - - return retValue; } @@ -1040,8 +1020,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil /* (non-Javadoc) * @see org.eclipse.rse.services.files.IFileService#delete(org.eclipse.core.runtime.IProgressMonitor, java.lang.String, java.lang.String) */ - public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException { - boolean hasSucceeded = false; + public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException { remoteParent = checkEncoding(remoteParent); fileName = checkEncoding(fileName); @@ -1053,7 +1032,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil if (_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) { try { FTPClient ftpClient = getFTPClient(); - hasSucceeded = internalDelete(ftpClient, remoteParent, fileName, file.isFile(), progressMonitor); + internalDelete(ftpClient, remoteParent, fileName, file.isFile(), progressMonitor); } catch (IOException e) { @@ -1066,11 +1045,9 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil } finally { progressMonitor.end(); } - // Can only return true since !hasSucceeded always leads to Exception - return hasSucceeded; } - private boolean 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 { if(monitor.isCanceled()) @@ -1079,64 +1056,54 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil } clearCache(parentPath); - boolean hasSucceeded = FTPReply.isPositiveCompletion(ftpClient.cwd(parentPath)); + FTPReply.isPositiveCompletion(ftpClient.cwd(parentPath)); monitor.worked(1); - if(hasSucceeded) + if(isFile) { - if(isFile) - { - hasSucceeded = ftpClient.deleteFile(fileName); - monitor.worked(1); - } - else - { - hasSucceeded = ftpClient.removeDirectory(fileName); - monitor.worked(1); - } + ftpClient.deleteFile(fileName); + monitor.worked(1); + } + else + { + 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$ + 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); } - else //folder recursively + + //remove empty folder + ftpClient.changeWorkingDirectory(parentPath); + boolean hasSucceeded = ftpClient.removeDirectory(fileName); + if (!hasSucceeded) { - 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; - } - hasSucceeded = 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$ - } + 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; - } /* (non-Javadoc) * @see org.eclipse.rse.services.files.IFileService#rename(org.eclipse.core.runtime.IProgressMonitor, java.lang.String, java.lang.String, java.lang.String) */ - public boolean rename(String remoteParent, String oldName, String newName, IProgressMonitor monitor) throws SystemMessageException { - boolean success = false; + public void rename(String remoteParent, String oldName, String newName, IProgressMonitor monitor) throws SystemMessageException { remoteParent = checkEncoding(remoteParent); oldName = checkEncoding(oldName); newName = checkEncoding(newName); @@ -1152,7 +1119,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil throw new RemoteFileIOException(new Exception(ftpClient.getReplyString())); } - success = ftpClient.rename(oldName, newName); + boolean success = ftpClient.rename(oldName, newName); if(!success) { @@ -1165,26 +1132,19 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil _commandMutex.release(); } } - - return success; } /* (non-Javadoc) * @see org.eclipse.rse.services.files.IFileService#rename(org.eclipse.core.runtime.IProgressMonitor, java.lang.String, java.lang.String, java.lang.String, org.eclipse.rse.services.files.IHostFile) */ - public boolean rename(String remoteParent, String oldName, String newName, IHostFile oldFile, IProgressMonitor monitor) { - boolean hasSucceeded = false; - + public void rename(String remoteParent, String oldName, String newName, IHostFile oldFile, IProgressMonitor monitor) { oldFile.renameTo(newName); - - return hasSucceeded; } /* (non-Javadoc) * @see org.eclipse.rse.services.files.IFileService#move(org.eclipse.core.runtime.IProgressMonitor, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ - public boolean move(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException{ - boolean success = false; + public void move(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException{ srcParent = checkEncoding(srcParent); srcName = checkEncoding(srcName); tgtParent = checkEncoding(tgtParent); @@ -1200,7 +1160,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil clearCache(srcParent); clearCache(tgtParent); - success = ftpClient.rename(source, target); + boolean success = ftpClient.rename(source, target); if(!success) { @@ -1214,7 +1174,6 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil } } - return success; } /* (non-Javadoc) @@ -1261,10 +1220,9 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil try { File tempFile = File.createTempFile("ftp", "temp"); //$NON-NLS-1$ //$NON-NLS-2$ tempFile.deleteOnExit(); - boolean success = upload(tempFile, remoteParent, fileName, _isBinaryFileType, null, null, monitor); - - if(!success) - { + try { + upload(tempFile, remoteParent, fileName, _isBinaryFileType, null, null, monitor); + } catch (SystemMessageException e) { throw new RemoteFileIOException(new Exception(getFTPClient().getReplyString())); } } @@ -1279,10 +1237,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil * (non-Javadoc) * @see org.eclipse.rse.services.files.IFileService#copy(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) */ - public boolean copy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException + public void copy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException { - boolean success = false; - srcParent = checkEncoding(srcParent); srcName = checkEncoding(srcName); tgtParent = checkEncoding(tgtParent); @@ -1302,7 +1258,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) { try { - success = internalCopy(getFTPClient(), srcParent, srcName, tgtParent, tgtName, remoteHostFile.isDirectory(), progressMonitor); + internalCopy(getFTPClient(), srcParent, srcName, tgtParent, tgtName, remoteHostFile.isDirectory(), progressMonitor); } catch(IOException e) { @@ -1312,26 +1268,22 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil _commandMutex.release(); } } - - return success; } - private boolean internalCopy(FTPClient ftpClient, String srcParent, String srcName, String tgtParent, String tgtName, boolean isDirectory, MyProgressMonitor monitor) throws SystemMessageException, IOException + private void internalCopy(FTPClient ftpClient, String srcParent, String srcName, String tgtParent, String tgtName, boolean isDirectory, MyProgressMonitor monitor) throws SystemMessageException, IOException { if (monitor.isCanceled()) { throw new RemoteFileCancelledException(); } - boolean success = false; - if(isDirectory) { //create folder // TODO what happens if the destination folder already exists? // Success=true or false? - success = ftpClient.makeDirectory(concat(tgtParent,tgtName)); + ftpClient.makeDirectory(concat(tgtParent,tgtName)); //copy contents String newSrcParentPath = concat(srcParent,srcName); @@ -1346,7 +1298,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil continue; } // TODO should we bail out in case a single file fails? - success = internalCopy(ftpClient, newSrcParentPath, curName, newTgtParentPath, curName, fileNames[i].isDirectory(), monitor); + internalCopy(ftpClient, newSrcParentPath, curName, newTgtParentPath, curName, fileNames[i].isDirectory(), monitor); } } @@ -1363,33 +1315,21 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil //Use binary raw transfer since the file will be uploaded again try { - success = internalDownload(srcParent, srcName, tempFile, true, null, monitor); - if (success) { - success = internalUpload(tempFile, tgtParent, tgtName, true, null, null, monitor); - } + internalDownload(srcParent, srcName, tempFile, true, null, monitor); + internalUpload(tempFile, tgtParent, tgtName, true, null, null, monitor); } finally { tempFile.delete(); } } - return success; - } - public boolean copyBatch(String[] srcParents, String[] srcNames, String tgtParent, IProgressMonitor monitor) throws SystemMessageException + public void copyBatch(String[] srcParents, String[] srcNames, String tgtParent, IProgressMonitor monitor) throws SystemMessageException { - boolean hasSucceeded = false; - for(int i=0; i "+fullPathNew+" failed: "+e.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -962,12 +951,11 @@ public class SftpFileService extends AbstractFileService implements ISshService, fDirChannelMutex.release(); } } - return ok; } - public boolean rename(String remoteParent, String oldName, String newName, IHostFile oldFile, IProgressMonitor monitor) throws SystemMessageException { + public void rename(String remoteParent, String oldName, String newName, IHostFile oldFile, IProgressMonitor monitor) throws SystemMessageException { // TODO dont know how to update - return rename(remoteParent, oldName, newName, monitor); + rename(remoteParent, oldName, newName, monitor); } private boolean progressWorked(IProgressMonitor monitor, int work) { @@ -1035,7 +1023,7 @@ public class SftpFileService extends AbstractFileService implements ISshService, return result; } - public boolean move(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException + public void move(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException { // move is not supported by sftp directly. Use the ssh shell instead. // TODO check if newer versions of sftp support move directly @@ -1044,32 +1032,28 @@ public class SftpFileService extends AbstractFileService implements ISshService, Activator.trace("SftpFileService.move "+srcName); //$NON-NLS-1$ String fullPathOld = PathUtility.enQuoteUnix(recode(concat(srcParent, srcName))); String fullPathNew = PathUtility.enQuoteUnix(recodeSafe(concat(tgtParent, tgtName))); - int rv = runCommand("mv "+fullPathOld+' '+fullPathNew, monitor); //$NON-NLS-1$ - return (rv==0); + runCommand("mv "+fullPathOld+' '+fullPathNew, monitor); //$NON-NLS-1$ } - public boolean copy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException { + public void copy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException { // copy is not supported by sftp directly. Use the ssh shell instead. // TODO check if newer versions of sftp support copy directly // TODO Interpret some error messages like "command not found" (use (x)copy instead of cp on windows) Activator.trace("SftpFileService.copy "+srcName); //$NON-NLS-1$ String fullPathOld = PathUtility.enQuoteUnix(recode(concat(srcParent, srcName))); String fullPathNew = PathUtility.enQuoteUnix(recodeSafe(concat(tgtParent, tgtName))); - int rv = runCommand("cp -Rp "+fullPathOld+' '+fullPathNew, monitor); //$NON-NLS-1$ - return (rv==0); + runCommand("cp -Rp "+fullPathOld+' '+fullPathNew, monitor); //$NON-NLS-1$ } - public boolean copyBatch(String[] srcParents, String[] srcNames, String tgtParent, IProgressMonitor monitor) throws SystemMessageException + public void copyBatch(String[] srcParents, String[] srcNames, String tgtParent, IProgressMonitor monitor) throws SystemMessageException { Activator.trace("SftpFileService.copyBatch "+srcNames); //$NON-NLS-1$ - boolean ok = true; for (int i = 0; i < srcParents.length; i++) { //TODO check what should happen if one file throws an Exception //should the batch job continue? - ok = ok && copy(srcParents[i], srcNames[i], tgtParent, srcNames[i], monitor); + copy(srcParents[i], srcNames[i], tgtParent, srcNames[i], monitor); } - return ok; } public void initService(IProgressMonitor monitor) { @@ -1095,15 +1079,13 @@ public class SftpFileService extends AbstractFileService implements ISshService, return true; } - public boolean setLastModified(String parent, String name, + public void setLastModified(String parent, String name, long timestamp, IProgressMonitor monitor) throws SystemMessageException { - boolean ok=false; String path = concat(parent, name); if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) { try { getChannel("SftpFileService.setLastModified").setMtime(recode(path), (int)(timestamp/1000)); //$NON-NLS-1$ - ok=true; Activator.trace("SftpFileService.setLastModified ok"); //$NON-NLS-1$ } catch (Exception e) { Activator.trace("SftpFileService.setLastModified "+path+" failed: "+e.toString()); //$NON-NLS-1$ //$NON-NLS-2$ @@ -1112,12 +1094,10 @@ public class SftpFileService extends AbstractFileService implements ISshService, fDirChannelMutex.release(); } } - return ok; - } + } - public boolean setReadOnly(String parent, String name, + public void setReadOnly(String parent, String name, boolean readOnly, IProgressMonitor monitor) throws SystemMessageException { - boolean ok=false; String path = concat(parent, name); if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) { try { @@ -1135,7 +1115,6 @@ public class SftpFileService extends AbstractFileService implements ISshService, getChannel("SftpFileService.setReadOnly").setStat(recode(path), attr); //$NON-NLS-1$ ok=true; Activator.trace("SftpFileService.setReadOnly ok"); //$NON-NLS-1$ } else { - ok=true; Activator.trace("SftpFileService.setReadOnly nothing-to-do"); //$NON-NLS-1$ } } catch (Exception e) { @@ -1145,7 +1124,6 @@ public class SftpFileService extends AbstractFileService implements ISshService, fDirChannelMutex.release(); } } - return ok; } /** diff --git a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/AbstractFileService.java b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/AbstractFileService.java index 8d53e372c17..97c6ebc39c0 100644 --- a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/AbstractFileService.java +++ b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/AbstractFileService.java @@ -64,38 +64,34 @@ public abstract class AbstractFileService extends AbstractService implements IFi return internalFetch(remoteParent, fileFilter, fileType, monitor); } - public IHostFile[] listMultiple(String[] remoteParents, - String[] fileFilters, int fileTypes[], IProgressMonitor monitor) + public void listMultiple(String[] remoteParents, + String[] fileFilters, int fileTypes[], List hostFiles, IProgressMonitor monitor) throws SystemMessageException { - List files = new ArrayList(); for (int i = 0; i < remoteParents.length; i++) { IHostFile[] result = list(remoteParents[i], fileFilters[i], fileTypes[i], monitor); for (int j = 0; j < result.length; j++) { - files.add(result[j]); + hostFiles.add(result[j]); } } - return (IHostFile[])files.toArray(new IHostFile[files.size()]); } - public IHostFile[] listMultiple(String[] remoteParents, - String[] fileFilters, int fileType, IProgressMonitor monitor) + public void listMultiple(String[] remoteParents, + String[] fileFilters, int fileType, List hostFiles, IProgressMonitor monitor) throws SystemMessageException { - List files = new ArrayList(); for (int i = 0; i < remoteParents.length; i++) { IHostFile[] result = list(remoteParents[i], fileFilters[i], fileType, monitor); for (int j = 0; j < result.length; j++) { - files.add(result[j]); + hostFiles.add(result[j]); } } - return (IHostFile[])files.toArray(new IHostFile[files.size()]); } protected boolean isRightType(int fileType, IHostFile node) @@ -128,46 +124,42 @@ public abstract class AbstractFileService extends AbstractService implements IFi } - public boolean deleteBatch(String[] remoteParents, String[] fileNames, IProgressMonitor monitor) throws SystemMessageException + public void deleteBatch(String[] remoteParents, String[] fileNames, IProgressMonitor monitor) throws SystemMessageException { - boolean ok = true; for (int i = 0; i < remoteParents.length; i++) { - ok = ok && delete(remoteParents[i], fileNames[i], monitor); + delete(remoteParents[i], fileNames[i], monitor); } - return ok; } /** * Default implementation - just iterate through each file */ - public boolean downloadMultiple(String[] remoteParents, String[] remoteFiles, + public void downloadMultiple(String[] remoteParents, String[] remoteFiles, File[] localFiles, boolean[] isBinaries, String[] hostEncodings, IProgressMonitor monitor) throws SystemMessageException { - boolean result = true; - for (int i = 0; i < remoteParents.length && result == true; i++) + for (int i = 0; i < remoteParents.length; i++) { String remoteParent = remoteParents[i]; String remoteFile = remoteFiles[i]; File localFile = localFiles[i]; boolean isBinary = isBinaries[i]; String hostEncoding = hostEncodings[i]; - result = download(remoteParent, remoteFile, localFile, isBinary, hostEncoding, monitor); + download(remoteParent, remoteFile, localFile, isBinary, hostEncoding, monitor); } - return result; } /** * Default implementation - just iterate through each file */ - public boolean uploadMultiple(File[] localFiles, String[] remoteParents, + public void uploadMultiple(File[] localFiles, String[] remoteParents, String[] remoteFiles, boolean[] isBinaries, String[] srcEncodings, String[] hostEncodings, IProgressMonitor monitor) throws SystemMessageException { boolean result = true; - for (int i = 0; i < localFiles.length && result == true; i++) + for (int i = 0; i < localFiles.length; i++) { File localFile = localFiles[i]; String remoteParent = remoteParents[i]; @@ -176,9 +168,8 @@ public abstract class AbstractFileService extends AbstractService implements IFi boolean isBinary = isBinaries[i]; String srcEncoding = srcEncodings[i]; String hostEncoding = hostEncodings[i]; - result = upload(localFile, remoteParent, remoteFile, isBinary, srcEncoding, hostEncoding, monitor); + upload(localFile, remoteParent, remoteFile, isBinary, srcEncoding, hostEncoding, monitor); } - return result; } /** diff --git a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/IFileService.java b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/IFileService.java index edc54df2b5a..309f99038b7 100644 --- a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/IFileService.java +++ b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/IFileService.java @@ -31,6 +31,7 @@ package org.eclipse.rse.services.files; import java.io.File; import java.io.InputStream; import java.io.OutputStream; +import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; @@ -69,8 +70,8 @@ public interface IFileService extends IService * return from the query. * * @see IFileService#list(String,String,int,IProgressMonitor) - * @see IFileService#listMultiple(String[],String[],int,IProgressMonitor) - * @see IFileService#listMultiple(String[],String[],int[],IProgressMonitor) + * @see IFileService#listMultiple(String[],String[],int,List,IProgressMonitor) + * @see IFileService#listMultiple(String[],String[],int[],List,IProgressMonitor) * * @since org.eclipse.rse.services 3.0 */ @@ -86,8 +87,8 @@ public interface IFileService extends IService * return from the query. * * @see IFileService#list(String,String,int,IProgressMonitor) - * @see IFileService#listMultiple(String[],String[],int,IProgressMonitor) - * @see IFileService#listMultiple(String[],String[],int[],IProgressMonitor) + * @see IFileService#listMultiple(String[],String[],int,List,IProgressMonitor) + * @see IFileService#listMultiple(String[],String[],int[],List,IProgressMonitor) * * @since org.eclipse.rse.services 3.0 */ @@ -105,8 +106,8 @@ public interface IFileService extends IService * return from the query. * * @see IFileService#list(String,String,int,IProgressMonitor) - * @see IFileService#listMultiple(String[],String[],int,IProgressMonitor) - * @see IFileService#listMultiple(String[],String[],int[],IProgressMonitor) + * @see IFileService#listMultiple(String[],String[],int,List,IProgressMonitor) + * @see IFileService#listMultiple(String[],String[],int[],List,IProgressMonitor) * * @since org.eclipse.rse.services 3.0 */ @@ -151,11 +152,10 @@ public interface IFileService extends IService * @param isBinary - indicates whether the file is text or binary * @param hostEncoding - the tgt encoding of the file (if text) * @param monitor the monitor for this potentially long running operation - * @return true if the file was uploaded * @throws SystemMessageException if an error occurs. * Typically this would be one of those in the RemoteFileException family. */ - public boolean upload(InputStream stream, String remoteParent, String remoteFile, boolean isBinary, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException; + public void upload(InputStream stream, String remoteParent, String remoteFile, boolean isBinary, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException; /** * Copy a file to the remote file system. The remote target is denoted by a @@ -167,12 +167,11 @@ public interface IFileService extends IService * @param srcEncoding - the src encoding of the file (if text) * @param hostEncoding - the tgt encoding of the file (if text) * @param monitor the monitor for this potentially long running operation - * @return true if the file was uploaded * @throws SystemMessageException if an error occurs. * Typically this would be one of those in the * {@link RemoteFileException} family. */ - public boolean upload(File localFile, String remoteParent, String remoteFile, boolean isBinary, String srcEncoding, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException; + public void upload(File localFile, String remoteParent, String remoteFile, boolean isBinary, String srcEncoding, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException; /** @@ -189,14 +188,13 @@ public interface IFileService extends IService * @param srcEncodings - the src encodings of the files (if text) * @param hostEncodings - the tgt encodings of the files (if text) * @param monitor the monitor for this potentially long running operation - * @return true if the files were uploaded * @throws SystemMessageException if an error occurs. * Typically this would be one of those in the * {@link RemoteFileException} family. * * @since org.eclipse.rse.services 3.0 */ - public boolean uploadMultiple(File[] localFiles, String[] remoteParents, String[] remoteFiles, boolean[] isBinary, String[] srcEncodings, String[] hostEncodings, IProgressMonitor monitor) throws SystemMessageException; + public void uploadMultiple(File[] localFiles, String[] remoteParents, String[] remoteFiles, boolean[] isBinary, String[] srcEncodings, String[] hostEncodings, IProgressMonitor monitor) throws SystemMessageException; /** @@ -208,12 +206,11 @@ public interface IFileService extends IService * @param isBinary - indicates whether the file is text on binary * @param hostEncoding - the encoding on the host (if text) * @param monitor the monitor for this potentially long running operation - * @return true if the file was copied from the remote system. * @throws SystemMessageException if an error occurs. * Typically this would be one of those in the * {@link RemoteFileException} family. */ - public boolean download(String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException; + public void download(String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException; /** * Copy files from the remote file system to the local system. @@ -230,13 +227,12 @@ public interface IFileService extends IService * @param isBinary - indicates whether the files are text on binary * @param hostEncodings - the encodings on the host (if text) * @param monitor the monitor for this potentially long running operation - * @return true if the files were copied from the remote system. * @throws SystemMessageException if an error occurs. Typically this would * be one of those in the {@link RemoteFileException} family. * * @since org.eclipse.rse.services 3.0 */ - public boolean downloadMultiple(String[] remoteParents, String[] remoteFiles, File[] localFiles, boolean[] isBinary, String[] hostEncodings, IProgressMonitor monitor) throws SystemMessageException; + public void downloadMultiple(String[] remoteParents, String[] remoteFiles, File[] localFiles, boolean[] isBinary, String[] hostEncodings, IProgressMonitor monitor) throws SystemMessageException; @@ -317,15 +313,14 @@ public interface IFileService extends IService * some other type. For each remoteParent, there must be a * corresponding fileType. For the default list of available file * types see IFileServiceContants + * @param hostFiles a list to which the found {@link IHostFile} objects will be appended * @param monitor the monitor for this potentially long running operation - * @return the collective list of host files that reside in each of the - * remoteParents with it's corresponding filter. * @throws SystemMessageException if an error occurs. Typically this would * be one of those in the RemoteFileException family. * * @since org.eclipse.rse.services 3.0 */ - public IHostFile[] listMultiple(String[] remoteParents, String[] fileFilters, int[] fileTypes, IProgressMonitor monitor) throws SystemMessageException; + public void listMultiple(String[] remoteParents, String[] fileFilters, int[] fileTypes, List hostFiles, IProgressMonitor monitor) throws SystemMessageException; /** * List the contents of multiple remote folders. @@ -345,15 +340,14 @@ public interface IFileService extends IService * other type. All results will be of the specified type. For the * default list of available file types see * IFileServiceContants + * @param hostFiles a list to which the found {@link IHostFile} objects will be appended * @param monitor the monitor for this potentially long running operation - * @return the collective list of host files that reside in each of the - * remoteParents with it's corresponding filter. * @throws SystemMessageException if an error occurs. Typically this would * be one of those in the RemoteFileException family. * * @since org.eclipse.rse.services 3.0 */ - public IHostFile[] listMultiple(String[] remoteParents, String[] fileFilters, int fileType, IProgressMonitor monitor) throws SystemMessageException; + public void listMultiple(String[] remoteParents, String[] fileFilters, int fileType, List hostFiles, IProgressMonitor monitor) throws SystemMessageException; /** @@ -413,11 +407,10 @@ public interface IFileService extends IService * @param remoteParent the folder containing the file to delete * @param fileName the name of the file or folder to delete * @param monitor the progress monitor - * @return true if successful * @throws SystemMessageException if an error occurs. Typically this would * be one of those in the RemoteFileException family. */ - public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException; + public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException; /** * Delete a set of files or folders on the host. Should throw an exception @@ -433,12 +426,10 @@ public interface IFileService extends IService * @param remoteParents the array of folders containing the files to delete * @param fileNames the names of the files or folders to delete * @param monitor the progress monitor - * @return true if all delete operations are successful, - * false otherwise. * @throws SystemMessageException if an error occurs. Typically this would * be one of those in the RemoteFileException family. */ - public boolean deleteBatch(String[] remoteParents, String[] fileNames, IProgressMonitor monitor) throws SystemMessageException; + public void deleteBatch(String[] remoteParents, String[] fileNames, IProgressMonitor monitor) throws SystemMessageException; /** * Rename a file or folder on the host. @@ -447,11 +438,10 @@ public interface IFileService extends IService * @param oldName the old name of the file or folder to rename * @param newName the new name for the file * @param monitor the progress monitor - * @return true if successful * @throws SystemMessageException if an error occurs. Typically this would * be one of those in the RemoteFileException family. */ - public boolean rename(String remoteParent, String oldName, String newName, IProgressMonitor monitor) throws SystemMessageException; + public void rename(String remoteParent, String oldName, String newName, IProgressMonitor monitor) throws SystemMessageException; /** * Rename a file or folder on the host. @@ -461,11 +451,10 @@ public interface IFileService extends IService * @param newName the new name for the file * @param oldFile the file to update with the change * @param monitor the progress monitor - * @return true if successful * @throws SystemMessageException if an error occurs. Typically this would * be one of those in the RemoteFileException family. */ - public boolean rename(String remoteParent, String oldName, String newName, IHostFile oldFile, IProgressMonitor monitor) throws SystemMessageException; + public void rename(String remoteParent, String oldName, String newName, IHostFile oldFile, IProgressMonitor monitor) throws SystemMessageException; /** * Move the file or folder specified to a different remote path. @@ -475,11 +464,10 @@ public interface IFileService extends IService * @param tgtParent the destination folder for the move * @param tgtName the name of the moved file or folder * @param monitor the progress monitor - * @return true if the file was moved * @throws SystemMessageException if an error occurs. Typically this would * be one of those in the RemoteFileException family. */ - public boolean move(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException; + public void move(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException; /** * Copy the file or folder to the specified destination. @@ -489,11 +477,10 @@ public interface IFileService extends IService * @param tgtParent the destination folder for the copy * @param tgtName the name of the copied file or folder * @param monitor the progress monitor - * @return true if the file was copied successfully * @throws SystemMessageException if an error occurs. Typically this would * be one of those in the RemoteFileException family. */ - public boolean copy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException; + public void copy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException; /** * Copy a set of files or folders to the specified destination. @@ -506,12 +493,10 @@ public interface IFileService extends IService * @param srcNames the names of the files or folders to copy * @param tgtParent the destination folder for the copy * @param monitor the progress monitor - * @return true if all files were copied, false - * or exception otherwise. * @throws SystemMessageException if an error occurs. Typically this would * be one of those in the RemoteFileException family. */ - public boolean copyBatch(String[] srcParents, String[] srcNames, String tgtParent, IProgressMonitor monitor) throws SystemMessageException; + public void copyBatch(String[] srcParents, String[] srcNames, String tgtParent, IProgressMonitor monitor) throws SystemMessageException; /** * Indicates whether the file system is case sensitive. @@ -536,11 +521,9 @@ public interface IFileService extends IService * @param timestamp the new timestamp in milliseconds from January 1, 1970, * 00:00:00 UTC. * @param monitor the progress monitor - * @return true if the file timestamp was changed successfully - * * @see IHostFile#getModifiedDate() */ - public boolean setLastModified(String parent, String name, long timestamp, IProgressMonitor monitor) throws SystemMessageException; + public void setLastModified(String parent, String name, long timestamp, IProgressMonitor monitor) throws SystemMessageException; /** * Set the read-only permission of the specified file or folder. @@ -550,10 +533,8 @@ public interface IFileService extends IService * @param readOnly indicates whether to make the file read-only or * read-write * @param monitor the progress monitor - * @return true if the read-only permission was changed successfully, or the - * permission already was as desired */ - public boolean setReadOnly(String parent, String name, boolean readOnly, IProgressMonitor monitor) throws SystemMessageException; + public void setReadOnly(String parent, String name, boolean readOnly, IProgressMonitor monitor) throws SystemMessageException; /** * Gets the remote encoding. diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java index 8ef569645c3..33ea38ef750 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java @@ -407,7 +407,10 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe parentPaths[i] = parents[i].getAbsolutePath(); } - IHostFile[] results = getFileService().listMultiple(parentPaths, fileNameFilters, fileTypes, monitor); + List hostFiles = new ArrayList(10); + getFileService().listMultiple(parentPaths, fileNameFilters, fileTypes, hostFiles, monitor); + IHostFile[] results = new IHostFile[hostFiles.size()]; + hostFiles.toArray(results); RemoteFileContext context = getDefaultContext(); IRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, null, results); @@ -457,7 +460,10 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe parentPaths[i] = parents[i].getAbsolutePath(); } - IHostFile[] results = getFileService().listMultiple(parentPaths, fileNameFilters, fileType, monitor); + List hostFiles = new ArrayList(10); + getFileService().listMultiple(parentPaths, fileNameFilters, fileType, hostFiles, monitor); + IHostFile[] results = new IHostFile[hostFiles.size()]; + hostFiles.toArray(results); RemoteFileContext context = getDefaultContext(); IRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, null, results); @@ -789,7 +795,8 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe public boolean copy(IRemoteFile sourceFolderOrFile, IRemoteFile targetFolder, String newName, IProgressMonitor monitor) throws SystemMessageException { IFileService service = getFileService(); - return service.copy(sourceFolderOrFile.getParentPath(), sourceFolderOrFile.getName(), targetFolder.getAbsolutePath(), newName, monitor); + service.copy(sourceFolderOrFile.getParentPath(), sourceFolderOrFile.getName(), targetFolder.getAbsolutePath(), newName, monitor); + return true; } public boolean copyBatch(IRemoteFile[] sourceFolderOrFiles, IRemoteFile targetFolder, IProgressMonitor monitor) throws SystemMessageException @@ -803,7 +810,8 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe sourceParents[i] = sourceFolderOrFiles[i].getParentPath(); sourceNames[i] = sourceFolderOrFiles[i].getName(); } - return service.copyBatch(sourceParents, sourceNames, targetFolder.getAbsolutePath(), monitor); + service.copyBatch(sourceParents, sourceNames, targetFolder.getAbsolutePath(), monitor); + return true; } public IRemoteFile getParentFolder(IRemoteFile folderOrFile, IProgressMonitor monitor) @@ -846,9 +854,9 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe IFileService service = getFileService(); String parent = folderOrFile.getParentPath(); String name = folderOrFile.getName(); - boolean result = service.delete(parent, name, monitor); + service.delete(parent, name, monitor); folderOrFile.markStale(true); - return result; + return true; } public boolean deleteBatch(IRemoteFile[] folderOrFiles, IProgressMonitor monitor) throws SystemMessageException @@ -865,7 +873,8 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe removeCachedRemoteFile(folderOrFiles[i]); } IFileService service = getFileService(); - return service.deleteBatch(parents, names, monitor); + service.deleteBatch(parents, names, monitor); + return true; } public boolean rename(IRemoteFile folderOrFile, String newName, IProgressMonitor monitor) throws SystemMessageException @@ -875,9 +884,9 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe String srcParent = folderOrFile.getParentPath(); String oldName = folderOrFile.getName(); String newPath = srcParent + folderOrFile.getSeparator() + newName; - boolean result = service.rename(srcParent, oldName, newName, monitor); + service.rename(srcParent, oldName, newName, monitor); folderOrFile.getHostFile().renameTo(newPath); - return result; + return true; } public boolean move(IRemoteFile sourceFolderOrFile, IRemoteFile targetFolder, String newName, IProgressMonitor monitor) throws SystemMessageException @@ -887,24 +896,26 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe String srcName = sourceFolderOrFile.getName(); String tgtParent = targetFolder.getAbsolutePath(); removeCachedRemoteFile(sourceFolderOrFile); - boolean result = service.move(srcParent, srcName, tgtParent, newName, monitor); + service.move(srcParent, srcName, tgtParent, newName, monitor); sourceFolderOrFile.markStale(true); targetFolder.markStale(true); - return result; + return true; } public boolean setLastModified(IRemoteFile folderOrFile, long newDate, IProgressMonitor monitor) throws SystemMessageException { String name = folderOrFile.getName(); String parent = folderOrFile.getParentPath(); - return _hostFileService.setLastModified(parent, name, newDate, monitor); + _hostFileService.setLastModified(parent, name, newDate, monitor); + return true; } public boolean setReadOnly(IRemoteFile folderOrFile, boolean readOnly, IProgressMonitor monitor) throws SystemMessageException { String name = folderOrFile.getName(); String parent = folderOrFile.getParentPath(); - return _hostFileService.setReadOnly(parent, name, readOnly, monitor); + _hostFileService.setReadOnly(parent, name, readOnly, monitor); + return true; } public ILanguageUtilityFactory getLanguageUtilityFactory()