mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 17:35:35 +02:00
[221211] IFileService API for batch operations IFileService.delete() returns boolean false for silent no-op
This commit is contained in:
parent
81f5537a9c
commit
2699735729
6 changed files with 45 additions and 22 deletions
|
@ -1351,7 +1351,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
|
|||
|
||||
}
|
||||
|
||||
public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException
|
||||
public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException
|
||||
{
|
||||
String remotePath = remoteParent + getSeparator(remoteParent) + fileName;
|
||||
DataElement de = getElementFor(remotePath);
|
||||
|
@ -1374,7 +1374,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;
|
||||
return true;
|
||||
}
|
||||
String msgTxt = NLS.bind(ServiceResources.FILEMSG_DELETE_FILE_FAILED, FileSystemMessageUtil.getSourceLocation(status));
|
||||
String msgDetails = ServiceResources.FILEMSG_DELETE_FILE_FAILED_DETAILS;
|
||||
|
|
|
@ -1024,7 +1024,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 void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException {
|
||||
public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException {
|
||||
remoteParent = checkEncoding(remoteParent);
|
||||
fileName = checkEncoding(fileName);
|
||||
|
||||
|
@ -1035,13 +1035,22 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
|
|||
|
||||
if (_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) {
|
||||
try {
|
||||
//Try to delete even if it looked like the file doesn't exist,
|
||||
//since existence might have been cached and be out-of-date
|
||||
FTPClient ftpClient = getFTPClient();
|
||||
internalDelete(ftpClient, remoteParent, fileName, file.isFile(), progressMonitor);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
if (!file.exists())
|
||||
return false;
|
||||
throw new RemoteFileIOException(e);
|
||||
}
|
||||
catch (SystemMessageException e) {
|
||||
if (!file.exists())
|
||||
return false;
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
_commandMutex.release();
|
||||
}
|
||||
|
@ -1051,6 +1060,7 @@ 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)
|
||||
|
|
|
@ -1015,7 +1015,7 @@ public class LocalFileService extends AbstractFileService implements ILocalServi
|
|||
return new LocalVirtualHostFile(child);
|
||||
}
|
||||
|
||||
public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException
|
||||
public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException
|
||||
{
|
||||
if (fileName.endsWith(ArchiveHandlerManager.VIRTUAL_SEPARATOR))
|
||||
{
|
||||
|
@ -1026,23 +1026,30 @@ public class LocalFileService extends AbstractFileService implements ILocalServi
|
|||
{
|
||||
remoteParent = remoteParent + ArchiveHandlerManager.VIRTUAL_SEPARATOR;
|
||||
}
|
||||
boolean result = true;
|
||||
File fileToDelete = new File(remoteParent, fileName);
|
||||
if (ArchiveHandlerManager.isVirtual(fileToDelete.getAbsolutePath()))
|
||||
{
|
||||
deleteFromArchive(fileToDelete, monitor);
|
||||
result = deleteFromArchive(fileToDelete, monitor);
|
||||
}
|
||||
else if (ArchiveHandlerManager.getInstance().isArchive(fileToDelete))
|
||||
{
|
||||
deleteArchive(fileToDelete);
|
||||
result = deleteArchive(fileToDelete);
|
||||
}
|
||||
if (fileToDelete.isDirectory())
|
||||
{
|
||||
deleteContents(fileToDelete, monitor);
|
||||
result = deleteContents(fileToDelete, monitor);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileToDelete.delete();
|
||||
result = fileToDelete.delete();
|
||||
}
|
||||
if (!result && fileToDelete.exists()) {
|
||||
// Deletion failed without specification why... likely a Security
|
||||
// problem?
|
||||
throw new RemoteFileSecurityException(null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void deleteBatch(String[] remoteParents, String[] fileNames, IProgressMonitor monitor) throws SystemMessageException
|
||||
|
@ -1099,9 +1106,9 @@ public class LocalFileService extends AbstractFileService implements ILocalServi
|
|||
CheckArchiveOperationStatusThread checkArchiveOperationStatusThread = new CheckArchiveOperationStatusThread(archiveOperationMonitor, monitor);
|
||||
checkArchiveOperationStatusThread.start();
|
||||
}
|
||||
boolean returnValue = handler.delete(child.fullName, archiveOperationMonitor);
|
||||
if (!returnValue)
|
||||
{
|
||||
try {
|
||||
return handler.delete(child.fullName, archiveOperationMonitor);
|
||||
} catch (SystemMessageException e) {
|
||||
if (monitor != null && monitor.isCanceled())
|
||||
{
|
||||
//This operation has been cancelled by the user.
|
||||
|
@ -1109,12 +1116,12 @@ public class LocalFileService extends AbstractFileService implements ILocalServi
|
|||
}
|
||||
// SystemPlugin.logError("LocalFileSubSystemImpl.deleteFromArchive(): Archive Handler's delete method returned false. Couldn't delete virtual object.");
|
||||
String msgTxt = NLS.bind(LocalServiceResources.FILEMSG_DELETE_VIRTUAL_FAILED, destination);
|
||||
String msgDetails = LocalServiceResources.FILEMSG_DELETE_VIRTUAL_FAILED_DETAILS;
|
||||
//String msgDetails = LocalServiceResources.FILEMSG_DELETE_VIRTUAL_FAILED_DETAILS;
|
||||
throw new SystemMessageException(new SimpleSystemMessage(Activator.PLUGIN_ID,
|
||||
ILocalMessageIds.FILEMSG_DELETE_VIRTUAL_FAILED,
|
||||
IStatus.ERROR, msgTxt, msgDetails));
|
||||
IStatus.ERROR,
|
||||
msgTxt, e));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean deleteArchive(File file)
|
||||
|
|
|
@ -891,7 +891,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
|||
return result;
|
||||
}
|
||||
|
||||
public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException
|
||||
public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException
|
||||
{
|
||||
String fullPath = concat(remoteParent, fileName);
|
||||
Activator.trace("SftpFileService.delete.waitForLock"); //$NON-NLS-1$
|
||||
|
@ -912,6 +912,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
|||
}
|
||||
if (attrs==null) {
|
||||
//doesn't exist, nothing to do
|
||||
return false;
|
||||
} else if (attrs.isDir()) {
|
||||
try {
|
||||
getChannel("SftpFileService.delete.rmdir").rmdir(fullPathRecoded); //$NON-NLS-1$
|
||||
|
@ -941,6 +942,7 @@ 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
|
||||
|
|
|
@ -406,16 +406,19 @@ public interface IFileService extends IService
|
|||
|
||||
/**
|
||||
* Delete a file or folder on the host.
|
||||
*
|
||||
*
|
||||
* @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
|
||||
* @throws SystemMessageException if an error occurs. Typically this would
|
||||
* be one of those in the RemoteFileException family.
|
||||
*
|
||||
* @return <code>true</code> if the requested element was successfully
|
||||
* deleted, or <code>false</code> 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.
|
||||
*
|
||||
* @since org.eclipse.rse.services 3.0
|
||||
*/
|
||||
public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException;
|
||||
public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException;
|
||||
|
||||
/**
|
||||
* Delete a set of files or folders on the host. Should throw an exception
|
||||
|
|
|
@ -189,14 +189,14 @@ public class WinCEFileService extends AbstractFileService implements IWinCEServi
|
|||
}
|
||||
}
|
||||
|
||||
public void delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException {
|
||||
public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException {
|
||||
String fullPath = concat(remoteParent, fileName);
|
||||
IRapiSession session = sessionProvider.getSession();
|
||||
try {
|
||||
if (isDirectory(session, fullPath)) {
|
||||
// recursive delete if it is a directory
|
||||
RapiFindData[] allFiles = session.findAllFiles(concat(fullPath, "*"), Rapi.FAF_NAME); //$NON-NLS-1$
|
||||
for (int i = 0 ; i < allFiles.length ; i++) {
|
||||
for (int i = 0; i < allFiles.length; i++) {
|
||||
delete(fullPath, allFiles[i].fileName, monitor);
|
||||
}
|
||||
session.removeDirectory(fullPath);
|
||||
|
@ -208,6 +208,7 @@ public class WinCEFileService extends AbstractFileService implements IWinCEServi
|
|||
//FIXME error handling
|
||||
throw new RemoteFileException(e.getMessage(), e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void download(String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding,
|
||||
|
|
Loading…
Add table
Reference in a new issue