From c21361107430d181e3911c1a1546d49aef1e33b6 Mon Sep 17 00:00:00 2001 From: Radoslav Gerganov Date: Fri, 23 May 2008 08:59:40 +0000 Subject: [PATCH] [230919] IFileService.delete() should not return a boolean --- .../dstore/files/DStoreFileService.java | 5 +++-- .../internal/services/files/ftp/FTPService.java | 9 +++++---- .../services/local/files/LocalFileService.java | 17 +++++++++++------ .../services/ssh/files/SftpFileService.java | 11 +++++++---- .../rse/services/files/IFileService.java | 9 ++++----- .../services/wince/files/WinCEFileService.java | 8 ++++++-- 6 files changed, 36 insertions(+), 23 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 7781fe2512f..54f90479a26 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 @@ -44,6 +44,7 @@ * David McKnight (IBM) - [227406][api][dstore] need apis for getting buffer size in IDataStoreProvider * David McKnight (IBM) - [229610] [api] File transfers should use workspace text file encoding * David McKnight (IBM) - [221211] [api][breaking][files] need batch operations to indicate which operations were successful + * Radoslav Gerganov (ProSyst) - [230919] IFileService.delete() should not return a boolean *******************************************************************************/ package org.eclipse.rse.internal.services.dstore.files; @@ -1351,7 +1352,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); @@ -1374,7 +1375,7 @@ 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; + return; } String msgTxt = NLS.bind(ServiceResources.FILEMSG_DELETE_FILE_FAILED, FileSystemMessageUtil.getSourceLocation(status)); String msgDetails = ServiceResources.FILEMSG_DELETE_FILE_FAILED_DETAILS; 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 025a0f6d251..d632bc258ab 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 @@ -73,6 +73,7 @@ * David McKnight (IBM) - [216252] [api][nls] Resource Strings specific to subsystems should be moved from rse.ui into files.ui / shells.ui / processes.ui where possible * Javier Montalvo Orus (Symbian) - [212382] additional "initCommands" slot for ftpListingParsers extension point * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable + * Radoslav Gerganov (ProSyst) - [230919] IFileService.delete() should not return a boolean ********************************************************************************/ package org.eclipse.rse.internal.services.files.ftp; @@ -111,6 +112,7 @@ 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.SystemElementNotFoundException; import org.eclipse.rse.services.clientserver.messages.SystemLockTimeoutException; import org.eclipse.rse.services.clientserver.messages.SystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessageException; @@ -1024,7 +1026,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 { + public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException { remoteParent = checkEncoding(remoteParent); fileName = checkEncoding(fileName); @@ -1043,12 +1045,12 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil catch (IOException e) { if (!file.exists()) - return false; + throw new SystemElementNotFoundException(file.getAbsolutePath(), "delete"); //$NON-NLS-1$ throw new RemoteFileIOException(e); } catch (SystemMessageException e) { if (!file.exists()) - return false; + throw new SystemElementNotFoundException(file.getAbsolutePath(), "delete"); //$NON-NLS-1$ throw e; } finally { @@ -1060,7 +1062,6 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil } finally { progressMonitor.end(); } - return true; } private void internalDelete(FTPClient ftpClient, String parentPath, String fileName, boolean isFile, MyProgressMonitor monitor) diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java index 37639eeb074..cf0137600f7 100644 --- a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java @@ -37,6 +37,7 @@ * David McKnight (IBM) - [220547] [api][breaking] SimpleSystemMessage needs to specify a message id and some messages should be shared * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable * David McKnight (IBM) - [231211] Local xml file not opened when workspace encoding is different from local system encoding + * Radoslav Gerganov (ProSyst) - [230919] IFileService.delete() should not return a boolean *******************************************************************************/ package org.eclipse.rse.internal.services.local.files; @@ -82,6 +83,7 @@ import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; import org.eclipse.rse.services.clientserver.messages.CommonMessages; import org.eclipse.rse.services.clientserver.messages.ICommonMessageIds; import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage; +import org.eclipse.rse.services.clientserver.messages.SystemElementNotFoundException; import org.eclipse.rse.services.clientserver.messages.SystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.services.clientserver.messages.SystemOperationCancelledException; @@ -1016,7 +1018,7 @@ public class LocalFileService extends AbstractFileService implements ILocalServi return new LocalVirtualHostFile(child); } - public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException + public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException { if (fileName.endsWith(ArchiveHandlerManager.VIRTUAL_SEPARATOR)) { @@ -1045,12 +1047,15 @@ public class LocalFileService extends AbstractFileService implements ILocalServi { result = fileToDelete.delete(); } - if (!result && fileToDelete.exists()) { - // Deletion failed without specification why... likely a Security - // problem? - throw new RemoteFileSecurityException(null); + if (!result) { + if (fileToDelete.exists()) { + // Deletion failed without specification why... likely a Security + // problem? + throw new RemoteFileSecurityException(null); + } else { + throw new SystemElementNotFoundException(fileToDelete.getAbsolutePath(), "delete"); //$NON-NLS-1$ + } } - return result; } public void deleteBatch(String[] remoteParents, String[] fileNames, IProgressMonitor monitor) throws SystemMessageException diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java index 1b9334366f9..568fc587e7a 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java @@ -26,6 +26,7 @@ * Martin Oberhuber (Wind River) - [224799] Fix JSch encoding problems with Arabic filenames * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable * Martin Oberhuber (Wind River) - [170910] Adopt RSE ITerminalService API for SSH + * Radoslav Gerganov (ProSyst) - [230919] IFileService.delete() should not return a boolean *******************************************************************************/ package org.eclipse.rse.internal.services.ssh.files; @@ -68,6 +69,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.SystemElementNotFoundException; import org.eclipse.rse.services.clientserver.messages.SystemLockTimeoutException; import org.eclipse.rse.services.clientserver.messages.SystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessageException; @@ -891,7 +893,7 @@ public class SftpFileService extends AbstractFileService implements ISshService, return result; } - public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException + public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException { String fullPath = concat(remoteParent, fileName); Activator.trace("SftpFileService.delete.waitForLock"); //$NON-NLS-1$ @@ -905,14 +907,16 @@ public class SftpFileService extends AbstractFileService implements ISshService, //bug 154419: test for dangling symbolic link if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { //simply try to delete --> if it really doesnt exist, this will throw an exception + //FIXME either throw SystemElementNotFoundException here OR add check for + //SSH_FX_NO_SUCH_FILE in makeSystemMessageException() and throw SENFE there getChannel("SftpFileService.delete.rm").rm(fullPathRecoded); //$NON-NLS-1$ } else { throw e; } } if (attrs==null) { - //doesn't exist, nothing to do - return false; + //doesn't exist, throw SystemElementNotFoundException + throw new SystemElementNotFoundException(fullPath, "delete"); //$NON-NLS-1$ } else if (attrs.isDir()) { try { getChannel("SftpFileService.delete.rmdir").rmdir(fullPathRecoded); //$NON-NLS-1$ @@ -942,7 +946,6 @@ public class SftpFileService extends AbstractFileService implements ISshService, } else { throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } - return true; } public void rename(String remoteParent, String oldName, String newName, IProgressMonitor monitor) throws SystemMessageException 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 ebcbf3db85f..f7fd0dcb415 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 @@ -25,6 +25,7 @@ * Martin Oberhuber (Wind River) - [cleanup] Fix API since tags * David Dykstal (IBM) - [221211] clarifying javadoc on batch operations * David Dykstal (IBM) - [221211] fix IFileService API for batch operations + * Radoslav Gerganov (ProSyst) - [230919] IFileService.delete() should not return a boolean *******************************************************************************/ package org.eclipse.rse.services.files; @@ -410,15 +411,13 @@ 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 the requested element was successfully - * deleted, or false if the element had not existed in the - * first place so the operation was a silent no-op. * @throws SystemMessageException if an error occurs or the user canceled - * the operation. + * the operation. SystemElementNotFoundException is thrown if the remote + * file doesn't exist. * * @since org.eclipse.rse.services 3.0 */ - 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 diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/WinCEFileService.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/WinCEFileService.java index dae3004b5d6..5c3d2ae7102 100644 --- a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/WinCEFileService.java +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/WinCEFileService.java @@ -13,6 +13,7 @@ * Radoslav Gerganov (ProSyst) - [230850] [WinCE] Implement setLastModified and setReadOnly in WinCEFileService * Radoslav Gerganov (ProSyst) - [231425] [WinCE] Use the progress monitors in WinCEFileService * Radoslav Gerganov (ProSyst) - [230856] [WinCE] Improve the error handling in WinCEFileService + * Radoslav Gerganov (ProSyst) - [230919] IFileService.delete() should not return a boolean *******************************************************************************/ package org.eclipse.rse.internal.services.wince.files; @@ -36,6 +37,7 @@ import org.eclipse.rse.internal.subsystems.files.wince.Activator; 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.messages.SystemElementNotFoundException; import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.services.clientserver.messages.SystemOperationCancelledException; import org.eclipse.rse.services.clientserver.messages.SystemUnexpectedErrorException; @@ -196,13 +198,16 @@ public class WinCEFileService extends AbstractFileService implements IWinCEServi } } - public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException { + public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException { String fullPath = concat(remoteParent, fileName); IRapiSession session = sessionProvider.getSession(); if (monitor == null) { monitor = new NullProgressMonitor(); } try { + if (!exist(session, fullPath)) { + throw new SystemElementNotFoundException(fullPath, "delete"); //$NON-NLS-1$ + } if (isDirectory(session, fullPath)) { // recursive delete if it is a directory RapiFindData[] allFiles = session.findAllFiles(concat(fullPath, "*"), Rapi.FAF_NAME); //$NON-NLS-1$ @@ -221,7 +226,6 @@ public class WinCEFileService extends AbstractFileService implements IWinCEServi } catch (RapiException e) { throw new RemoteFileIOException(e); } - return true; } public void download(String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding,