diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemMoveRemoteFileAction.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemMoveRemoteFileAction.java index 2fb7e64e2eb..a0300c5e058 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemMoveRemoteFileAction.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemMoveRemoteFileAction.java @@ -18,6 +18,7 @@ * Kevin Doyle (IBM) - [160769] Move Resource dialog allows user to continue on invalid destination * Kevin Doyle (IBM) - [199324] [nls] Move dialog SystemMessages should be added/updated * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations ********************************************************************************/ package org.eclipse.rse.internal.files.ui.actions; @@ -56,6 +57,7 @@ public class SystemMoveRemoteFileAction extends SystemCopyRemoteFileAction private SystemMessage targetDescendsFromSrcMsg = null; private SystemMessage invalidFilterMsg = null; protected Vector movedFiles = new Vector(); + protected Vector movedFileNames = new Vector(); private class MoveRemoteFileJob extends WorkspaceJob { @@ -97,6 +99,7 @@ public class SystemMoveRemoteFileAction extends SystemCopyRemoteFileAction copiedOk = doCopy(targetContainer, oldObject, newName, monitor); newNames[idx] = newName; monitor.worked(1); + movedFileNames.add(oldName); //remember the old name, in case we need it later. } monitor.done(); } @@ -104,16 +107,16 @@ public class SystemMoveRemoteFileAction extends SystemCopyRemoteFileAction { copiedOk = false; //If this operation is canceled, need to display a proper message to the user. - if (monitor.isCanceled() && movedFiles.size() > 0) + if (monitor.isCanceled() && movedFileNames.size() > 0) { //Get the moved file names - String movedFileName = ((IRemoteFile)movedFiles.get(0)).getName(); - for (int i=1; i<(movedFiles.size()); i++) + String movedFileNamesList = (String)(movedFileNames.get(0)); + for (int i=1; i<(movedFileNames.size()); i++) { - movedFileName = movedFileName + "\n" + ((IRemoteFile)movedFiles.get(i)).getName(); //$NON-NLS-1$ + movedFileNamesList = movedFileNamesList + "\n" + (String)(movedFileNames.get(i)); //$NON-NLS-1$ } SystemMessage thisMessage = RSEUIPlugin.getPluginMessage(ISystemMessages.FILEMSG_MOVE_INTERRUPTED); - thisMessage.makeSubstitution(movedFileName); + thisMessage.makeSubstitution(movedFileNamesList); SystemMessageDialog.displayErrorMessage(shell, thisMessage); status = Status.CANCEL_STATUS; } diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java index 410af69f5f6..4ebee5e5523 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java @@ -39,6 +39,7 @@ * Rupen Mardirossian (IBM) - [208435] added constructor to nested RenameRunnable class to take in names that are previously used as a parameter for multiple renaming instances * David McKnight (IBM) - [209660] need to check if remote encoding has changed before using cached file * Xuan Chen (IBM) - [160775] [api] [breaking] [nl] rename (at least within a zip) blocks UI thread + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations ********************************************************************************/ package org.eclipse.rse.internal.files.ui.view; @@ -2075,7 +2076,7 @@ public class SystemViewRemoteFileAdapter IRemoteFile thisCopiedFile = null; try { - thisCopiedFile = targetFS.getRemoteFileObject(targetFolder, srcFileOrFolders[i].getName(), monitor); + thisCopiedFile = targetFS.getRemoteFileObject(targetFolder, srcFileOrFolders[i].getName(), null); } catch (SystemMessageException thsiException) { @@ -2103,6 +2104,10 @@ public class SystemViewRemoteFileAdapter thisMessage.makeSubstitution(copiedFileNames); SystemMessageDialog.displayErrorMessage(shell, thisMessage); } + else + { + SystemMessageDialog.displayMessage(e); + } } else { diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java index bffd6895886..b9a6c6c3ec5 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java @@ -26,14 +26,13 @@ * Xuan Chen (IBM) - [202949] [archives] copy a folder from one connection to an archive file in a different connection does not work * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread * David McKnight (IBM) - [196624] dstore miner IDs should be String constants rather than dynamic lookup + * * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations *******************************************************************************/ package org.eclipse.rse.dstore.universal.miners; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.ServerSocket; -import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -44,14 +43,19 @@ import org.eclipse.dstore.core.model.DataElement; import org.eclipse.dstore.core.model.DataStoreResources; import org.eclipse.rse.internal.dstore.universal.miners.filesystem.ArchiveQueryThread; import org.eclipse.rse.internal.dstore.universal.miners.filesystem.ClassFileParser; +import org.eclipse.rse.internal.dstore.universal.miners.filesystem.CopyBatchThread; +import org.eclipse.rse.internal.dstore.universal.miners.filesystem.CopySingleThread; +import org.eclipse.rse.internal.dstore.universal.miners.filesystem.CreateFileThread; +import org.eclipse.rse.internal.dstore.universal.miners.filesystem.CreateFolderThread; +import org.eclipse.rse.internal.dstore.universal.miners.filesystem.DeleteThread; import org.eclipse.rse.internal.dstore.universal.miners.filesystem.FileClassifier; import org.eclipse.rse.internal.dstore.universal.miners.filesystem.FileDescriptors; import org.eclipse.rse.internal.dstore.universal.miners.filesystem.FileQueryThread; +import org.eclipse.rse.internal.dstore.universal.miners.filesystem.RenameThread; import org.eclipse.rse.internal.dstore.universal.miners.filesystem.UniversalDownloadHandler; import org.eclipse.rse.internal.dstore.universal.miners.filesystem.UniversalSearchHandler; import org.eclipse.rse.services.clientserver.IClientServerConstants; import org.eclipse.rse.services.clientserver.IServiceConstants; -import org.eclipse.rse.services.clientserver.PathUtility; import org.eclipse.rse.services.clientserver.SystemFileClassifier; import org.eclipse.rse.services.clientserver.SystemSearchString; import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; @@ -210,358 +214,18 @@ public class UniversalFileSystemMiner extends Miner { private DataElement handleCopyBatch(DataElement targetFolder, DataElement theElement, DataElement status) { - String targetType = targetFolder.getType(); - File tgtFolder = getFileFor(targetFolder); - int numOfSources = theElement.getNestedSize() - 2; - if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) - { - // if target is virtual or an archive, insert into an archive - AbsoluteVirtualPath vpath = getAbsoluteVirtualPath(targetFolder); - ISystemArchiveHandler handler = getArchiveHandlerFor(vpath.getContainingArchiveString()); - boolean result = true; - - if (handler == null) - { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - return statusDone(status); - } + CopyBatchThread copyBatchThread = new CopyBatchThread(targetFolder, theElement, this, _isWindows, status); + copyBatchThread.start(); - List nonDirectoryArrayList = new ArrayList(); - List nonDirectoryNamesArrayList = new ArrayList(); - - String virtualContainer = ""; //$NON-NLS-1$ - - if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) - { - virtualContainer = vpath.getVirtualPart(); - } - - for (int i = 0; i < numOfSources; i++) - { - DataElement sourceFile = getCommandArgument(theElement, i+1); - String srcType = sourceFile.getType(); - String srcName = sourceFile.getName(); - File srcFile; - - if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) - || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) - { - srcFile = getFileFor(sourceFile); - } - else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) - { - AbsoluteVirtualPath svpath = getAbsoluteVirtualPath(sourceFile); - ISystemArchiveHandler shandler = getArchiveHandlerFor(svpath.getContainingArchiveString()); - - if (shandler == null) - { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - return statusDone(status); - } - - VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart(), null); - srcFile = child.getExtractedFile(); - } - else { - //invalid source type - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - return statusDone(status); - } - - //If this source file object is directory, we will call ISystemArchiveHandler#add(File ...) method to - //it and all its descendants into the archive file. - //If this source file object is not a directory, we will add it into a list, and then - //call ISystemArchiveHandler#add(File[] ...) to add them in batch. - if (srcFile.isDirectory()) - { - result = handler.add(srcFile, virtualContainer, srcName, null); - if (!result) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - return statusDone(status); - } - } - else - { - nonDirectoryArrayList.add(srcFile); - nonDirectoryNamesArrayList.add(srcName); - } - } - - if (nonDirectoryArrayList.size() > 0) - { - File[] resultFiles = (File[])nonDirectoryArrayList.toArray(new File[nonDirectoryArrayList.size()]); - String[] resultNames = (String[])nonDirectoryNamesArrayList.toArray(new String[nonDirectoryNamesArrayList.size()]); - //we need to add those files into the archive file as well. - result = handler.add(resultFiles, virtualContainer, resultNames, null); - } - - if (result) - { - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - } - else - { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - } - return statusDone(status); - } - else // target is a regular folder - { - boolean folderCopy = false; - String source = ""; //$NON-NLS-1$ - String tgt = enQuote(tgtFolder.getAbsolutePath()); - - int numOfNonVirtualSources = 0; - for (int i = 0; i < numOfSources; i++) - { - DataElement sourceFile = getCommandArgument(theElement, i+1); - String srcType = sourceFile.getType(); - - if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) - { - // extract from an archive to folder - AbsoluteVirtualPath svpath = getAbsoluteVirtualPath(sourceFile); - ISystemArchiveHandler shandler = getArchiveHandlerFor(svpath.getContainingArchiveString()); - - if (shandler == null) - { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - return statusDone(status); - } - - VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart(), null); - - File parentDir = getFileFor(targetFolder); - File destination = new File(parentDir, sourceFile.getName()); - - if (child.isDirectory) - { - shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination, null); - } - else - { - shandler.extractVirtualFile(svpath.getVirtualPart(), destination, null); - } - } - else // source is regular file or folder - { - File srcFile = getFileFor(sourceFile); - folderCopy = folderCopy || srcFile.isDirectory(); - String src = srcFile.getAbsolutePath(); - - // handle special characters in source and target strings - src = enQuote(src); - - // handle window case separately, since xcopy command could not handler - // multiple source names - if (_isWindows) - { - tgt = tgtFolder.getAbsolutePath() + File.separatorChar + srcFile.getName(); - // Both unix and windows need src quoted, so it's already done - doCopyCommand(src, enQuote(tgt), folderCopy, status); - if (status.getAttribute(DE.A_SOURCE) == IServiceConstants.FAILED) - { - break; - } - continue; - } - if (numOfNonVirtualSources == 0) - { - source += src; - } - else - { - source = source + " " + src; //$NON-NLS-1$ - } - numOfNonVirtualSources++; - } - } // end for loop iterating through sources - - if (numOfNonVirtualSources > 0) - { - doCopyCommand(source, tgt, folderCopy, status); - } - } // end if/then/else (target is regular folder) - return statusDone(status); + updateCancellableThreads(status.getParent(), copyBatchThread); + + return status; } - protected void doCopyCommand(String source, String tgt, boolean folderCopy, DataElement status) - { - String command = null; - if (_isWindows) { - - if (folderCopy) { - command = "xcopy " + source //$NON-NLS-1$ - + " " + tgt //$NON-NLS-1$ - + " /S /E /K /Q /H /I /Y"; //$NON-NLS-1$ - } - else { - String unquotedTgt = tgt.substring(1, tgt.length() - 1); - - File targetFile = new File(unquotedTgt); - if (!targetFile.exists()) - { - // create file so as to avoid ambiguity - try - { - targetFile.createNewFile(); - } - catch (Exception e) - { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - status.setAttribute(DE.A_VALUE, e.getMessage()); - return; - } - } - command = "xcopy " + source + " " + tgt + " /Y /K /Q /H"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - } - else { - if (folderCopy) { - command = "cp -Rp " + source + " " + tgt; //$NON-NLS-1$ //$NON-NLS-2$ - } - else { - command = "cp -p " + source + " " + tgt; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - // run copy command - try - { - Runtime runtime = Runtime.getRuntime(); - Process p = null; - - if (_isWindows) - { - String theShell = "cmd /C "; //$NON-NLS-1$ - p = runtime.exec(theShell + command); - } - else - { - String theShell = "sh"; //$NON-NLS-1$ - String args[] = new String[3]; - args[0] = theShell; - args[1] = "-c"; //$NON-NLS-1$ - args[2] = command; - - p = runtime.exec(args); - } - - // ensure there is a process - if (p != null) { - - // wait for process to finish - p.waitFor(); - - // get the exit value of the process - int result = p.exitValue(); - - // if the exit value is not 0, then the process did not terminate normally - if (result != 0) { - - // get the error stream - InputStream errStream = p.getErrorStream(); - - // error buffer - StringBuffer errBuf = new StringBuffer(); - - byte[] bytes = null; - - int numOfBytesRead = 0; - - int available = errStream.available(); - - // read error stream and store in error buffer - while (available > 0) { - - bytes = new byte[available]; - - numOfBytesRead = errStream.read(bytes); - - if (numOfBytesRead > -1) { - errBuf.append(new String(bytes, 0, numOfBytesRead)); - } - else { - break; - } - - available = errStream.available(); - } - - String err = errBuf.toString(); - - // omit new line if there is one at the end because datastore does not - // handle new line in the attributes - // TODO: what to do if newline occurs in the middle of the string? - String newLine = System.getProperty("line.separator"); //$NON-NLS-1$ - - if (newLine != null && err.endsWith(newLine)) { - err = err.substring(0, err.length() - newLine.length()); - } - - // if there is something in error buffer - // there was something in the error stream of the process - if (err.length() > 0) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - status.setAttribute(DE.A_VALUE, err); - } - // otherwise, nothing in the error stream - // but we know process did not exit normally, so we indicate an unexpected error - else { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - status.setAttribute(DE.A_VALUE, IServiceConstants.UNEXPECTED_ERROR); - } - } - // otherwise if exit value is 0, process terminated normally - else { - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - } - } - // no process, so something is wrong - else { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - status.setAttribute(DE.A_VALUE, IServiceConstants.UNEXPECTED_ERROR); - } - } - catch (Exception e) - { - UniversalServerUtilities.logError(CLASSNAME, "Exception is handleCopy", e); //$NON-NLS-1$ - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - status.setAttribute(DE.A_VALUE, e.getMessage()); - } - } - /** - * Delete directory and its children. - * - */ - public void deleteDir(File fileObj, DataElement status) { - try { - File list[] = fileObj.listFiles(); - for (int i = 0; i < list.length; ++i) { - if (list[i].isFile()) { - if (!(list[i].delete())) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - UniversalServerUtilities.logWarning(CLASSNAME, - "Deletion of dir failed"); //$NON-NLS-1$ - } - } else { - deleteDir(list[i], status); - if (!(list[i].delete())) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - UniversalServerUtilities.logWarning(CLASSNAME, - "Deletion of dir failed"); //$NON-NLS-1$ - } - } - } - } catch (Exception e) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXCEPTION); - status.setAttribute(DE.A_VALUE, e.getLocalizedMessage()); - UniversalServerUtilities.logError(CLASSNAME, - "Deletion of dir failed", e); //$NON-NLS-1$ - } - } + /** * Method to do a search. @@ -632,10 +296,11 @@ public class UniversalFileSystemMiner extends Miner { public DataElement handleCancel(DataElement subject, DataElement status) { ICancellableHandler thread = (ICancellableHandler) _cancellableThreads .get(subject); - + System.out.println("Inside handleCancel(), and the thread is " + thread); if (thread != null) { if (!thread.isDone()) { + System.out.println("Inside handleCancel(), and will call thread.cancel"); thread.cancel(); } } @@ -749,6 +414,7 @@ public class UniversalFileSystemMiner extends Miner { _dataStore.trace(e); } // save find thread in hashmap for retrieval during cancel + System.out.println("put thread into the _cancellableThreads hashmap. " + thread.getClass()); _cancellableThreads.put(command, thread); } @@ -909,163 +575,35 @@ public class UniversalFileSystemMiner extends Miner { * Method to Delete a file or folder. */ public DataElement handleDelete(DataElement subject, DataElement status, boolean refreshDataStore) { - String type = subject.getType(); - if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) - || type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { - return handleDeleteFromArchive(subject, status); - } + DeleteThread deleteThread = new DeleteThread(subject, this, _dataStore, false, status); + deleteThread.start(); - File deleteObj = new File(subject.getAttribute(DE.A_VALUE) - + File.separatorChar + subject.getName()); - DataElement deObj = null; - if (!deleteObj.exists()) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_DOES_NOT_EXIST + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ - UniversalServerUtilities.logError(CLASSNAME, - "The object to delete does not exist", null); //$NON-NLS-1$ - } else { - try { - if (deleteObj.isFile()) { - if (deleteObj.delete() == false) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ - } else { - // delete was successful and delete the object from the - // datastore - deObj = _dataStore.find(subject, DE.A_NAME, subject - .getName(), 1); - _dataStore.deleteObject(subject, deObj); - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ - } - _dataStore.refresh(subject); - } else if (deleteObj.isDirectory()) { // it is directory and - // need to delete the - // entire directory + - // children - deleteDir(deleteObj, status); - if (deleteObj.delete() == false) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ - UniversalServerUtilities.logError(CLASSNAME, - "Deletion of dir fialed", null); //$NON-NLS-1$ - } else { - _dataStore.deleteObjects(subject); - DataElement parent = subject.getParent(); - _dataStore.deleteObject(parent, subject); - _dataStore.refresh(parent); - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ - } - } else { - UniversalServerUtilities - .logError( - CLASSNAME, - "The object to delete is neither a File or Folder! in handleDelete", //$NON-NLS-1$ - null); - } - } catch (Exception e) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXCEPTION + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ - status.setAttribute(DE.A_VALUE, e.getLocalizedMessage()); - UniversalServerUtilities.logError(CLASSNAME, - "Delete of the object failed", e); //$NON-NLS-1$ - } - } - _dataStore.refresh(subject); - return statusDone(status); + updateCancellableThreads(status.getParent(), deleteThread); + + return status; } private DataElement handleDeleteBatch(DataElement theElement, DataElement status) { - DataElement substatus = _dataStore.createObject(null, "status", "substatus"); //$NON-NLS-1$ //$NON-NLS-2$ - int numOfSources = theElement.getNestedSize() - 2; - for (int i = 0; i < numOfSources; i++) - { - DataElement subject = getCommandArgument(theElement, i+1); - handleDelete(subject, substatus, false); - /* - if (!substatus.getSource().startsWith(IServiceConstants.SUCCESS)) - { - status.setAttribute(DE.A_SOURCE, substatus.getSource()); - return statusDone(status); - } - */ - } - status.setAttribute(DE.A_SOURCE, substatus.getSource()); - return statusDone(status); + DeleteThread deleteThread = new DeleteThread(theElement, this, _dataStore, true, status); + deleteThread.start(); + + updateCancellableThreads(status.getParent(), deleteThread); + + return status; } /** * Method to Rename a file or folder. */ public DataElement handleRename(DataElement subject, DataElement status) { - File fileoldname = new File(subject.getAttribute(DE.A_VALUE) - + File.separatorChar + subject.getName()); - File filerename = new File(subject.getAttribute(DE.A_SOURCE)); + + RenameThread renameThread = new RenameThread(subject, this, _dataStore, status); + renameThread.start(); - // System.out.println(ArchiveHandlerManager.isVirtual(fileoldname - // .getAbsolutePath())); - if (ArchiveHandlerManager.isVirtual(fileoldname.getAbsolutePath())) { - AbsoluteVirtualPath oldAbsPath = new AbsoluteVirtualPath( - fileoldname.getAbsolutePath()); - AbsoluteVirtualPath newAbsPath = new AbsoluteVirtualPath(filerename - .getAbsolutePath()); - ISystemArchiveHandler handler = _archiveHandlerManager - .getRegisteredHandler(new File(oldAbsPath - .getContainingArchiveString())); - boolean success = !(handler == null) - && handler.fullRename(oldAbsPath.getVirtualPart(), - newAbsPath.getVirtualPart(), null); - if (success && handler != null) { - subject.setAttribute(DE.A_NAME, filerename.getName()); - subject.setAttribute(DE.A_SOURCE, setProperties(handler - .getVirtualFile(newAbsPath.getVirtualPart(), null))); - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - _dataStore.update(subject); - } else { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - } - _dataStore.refresh(subject); - return statusDone(status); - } - if (filerename.exists()) - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXIST); - else { - try { - boolean done = fileoldname.renameTo(filerename); - if (done) { - subject.setAttribute(DE.A_NAME, filerename.getName()); - subject - .setAttribute(DE.A_SOURCE, - setProperties(filerename)); - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - - if (filerename.isDirectory()) { - // update children's properties - updateChildProperties(subject, filerename); - } - _dataStore.update(subject); - } else - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - } catch (Exception e) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - UniversalServerUtilities.logError(CLASSNAME, - "handleRename failed", e); //$NON-NLS-1$ - } - } - _dataStore.refresh(subject); - return statusDone(status); - } - - // DKM: during folder rename we need to recursively update all the parent - // paths - private void updateChildProperties(DataElement subject, File filerename) { - - int nestedSize = subject.getNestedSize(); - for (int i = 0; i < nestedSize; i++) { - DataElement child = subject.get(i); - child.setAttribute(DE.A_VALUE, filerename.getAbsolutePath()); - - if (child.getNestedSize() > 0) { - File childFile = new File(filerename, child.getName()); - updateChildProperties(child, childFile); - } - } + updateCancellableThreads(status.getParent(), renameThread); + + return status; } /** @@ -1073,74 +611,13 @@ public class UniversalFileSystemMiner extends Miner { */ public DataElement handleCreateFile(DataElement subject, DataElement status, String queryType) { - boolean wasFilter = queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR); - if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) { - return handleCreateVirtualFile(subject, status, queryType); - } + + CreateFileThread createFileThread = new CreateFileThread(subject, queryType, this, _dataStore, status); + createFileThread.start(); - File filename = null; - if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { - if (subject.getName().indexOf( - ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0) { - subject.setAttribute(DE.A_TYPE, - IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR); - return handleCreateVirtualFile(subject, status, queryType); - } else { - filename = new File(subject.getValue()); - subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR); - subject.setAttribute(DE.A_SOURCE, setProperties(filename)); - } - } else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR)) - filename = new File(subject.getAttribute(DE.A_VALUE) - + File.separatorChar + subject.getName()); - else - UniversalServerUtilities.logError(CLASSNAME, - "Invalid query type to handleCreateFile", null); //$NON-NLS-1$ - - if (filename != null) - { - if (filename.exists()) - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXIST); - else { - try { - boolean done = filename.createNewFile(); - if (ArchiveHandlerManager.getInstance().isArchive(filename)) { - done = ArchiveHandlerManager.getInstance() - .createEmptyArchive(filename); - if (done) - subject.setAttribute(DE.A_TYPE, - IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR); - } else { - if (done) - { - subject.setAttribute(DE.A_TYPE, - IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR); - } - } - subject.setAttribute(DE.A_SOURCE, setProperties(filename)); - if (done) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - if (wasFilter) { - String fullName = subject.getValue(); - String name = fullName.substring(fullName - .lastIndexOf(File.separatorChar) + 1, fullName - .length()); - String path = fullName.substring(0, fullName - .lastIndexOf(File.separatorChar)); - subject.setAttribute(DE.A_NAME, name); - subject.setAttribute(DE.A_VALUE, path); - } - } else - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - } catch (Exception e) { - UniversalServerUtilities.logError(CLASSNAME, - "handleCreateFile failed", e); //$NON-NLS-1$ - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - } - } - } - _dataStore.refresh(subject); - return statusDone(status); + updateCancellableThreads(status.getParent(), createFileThread); + + return status; } /** @@ -1148,65 +625,12 @@ public class UniversalFileSystemMiner extends Miner { */ public DataElement handleCreateFolder(DataElement subject, DataElement status, String queryType) { - if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { - return handleCreateVirtualFolder(subject, status, queryType); - } + CreateFolderThread createFolderThread = new CreateFolderThread(subject, queryType, this, _dataStore, status); + createFolderThread.start(); - File filename = null; - if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) - { - if (subject.getName().indexOf( - ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0) - { - subject.setAttribute(DE.A_TYPE, - IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR); - return handleCreateVirtualFolder(subject, status, queryType); - } - else - { - filename = new File(subject.getValue()); - subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR); - subject.setAttribute(DE.A_SOURCE, setProperties(filename)); - } - } - else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR)) - { - filename = new File(subject.getValue()); - } - else - UniversalServerUtilities.logError(CLASSNAME, - "Invalid query type to handleCreateFolder", null); //$NON-NLS-1$ - - if (filename != null) - { - if (filename.exists()) - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXIST); - else - { - try { - boolean done = filename.mkdirs(); - if (done) - { - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - subject.setAttribute(DE.A_SOURCE, setProperties(filename)); - subject.setAttribute(DE.A_TYPE,IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR); - subject.setAttribute(DE.A_NAME, filename.getName()); - subject.setAttribute(DE.A_VALUE, filename.getParentFile().getAbsolutePath()); - } - else - { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - } - - } catch (Exception e) { - UniversalServerUtilities.logError(CLASSNAME, - "handleCreateFolder failed", e); //$NON-NLS-1$ - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - } - } - } - _dataStore.refresh(subject); - return statusDone(status); + updateCancellableThreads(status.getParent(), createFolderThread); + + return status; } /** @@ -2009,8 +1433,10 @@ public class UniversalFileSystemMiner extends Miner { createCommandDescriptor(UniversalFilter, "GetOSType", IUniversalDataStoreConstants.C_GET_OSTYPE); //$NON-NLS-1$ createCommandDescriptor(UniversalFilter, "Exists", IUniversalDataStoreConstants.C_QUERY_EXISTS); //$NON-NLS-1$ createCommandDescriptor(UniversalFilter, "GetRemoteObject", IUniversalDataStoreConstants.C_QUERY_GET_REMOTE_OBJECT); //$NON-NLS-1$ - createCommandDescriptor(UniversalFilter, "CreateNewFile", IUniversalDataStoreConstants.C_CREATE_FILE); //$NON-NLS-1$ - createCommandDescriptor(UniversalFilter, "CreateNewFolder", IUniversalDataStoreConstants.C_CREATE_FOLDER); //$NON-NLS-1$ + DataElement createNewFileFromFilterDescriptor = createCommandDescriptor(UniversalFilter, "CreateNewFile", IUniversalDataStoreConstants.C_CREATE_FILE); //$NON-NLS-1$ + _dataStore.createReference(cancellable, createNewFileFromFilterDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + DataElement createNewFolderFromFilterDescriptor = createCommandDescriptor(UniversalFilter, "CreateNewFolder", IUniversalDataStoreConstants.C_CREATE_FOLDER); //$NON-NLS-1$ + _dataStore.createReference(cancellable, createNewFolderFromFilterDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); createCommandDescriptor(UniversalFilter, "SetLastModified", IUniversalDataStoreConstants.C_SET_LASTMODIFIED); //$NON-NLS-1$ @@ -2030,11 +1456,21 @@ public class UniversalFileSystemMiner extends Miner { createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "GetAdvanceProperty", IUniversalDataStoreConstants.C_QUERY_ADVANCE_PROPERTY); //$NON-NLS-1$ createCommandDescriptor(tempnode, "Filter", IUniversalDataStoreConstants.C_CREATE_TEMP); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFileObject, "Delete", IUniversalDataStoreConstants.C_DELETE); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFileObject, "DeleteBatch", IUniversalDataStoreConstants.C_DELETE_BATCH); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFileObject, "CreateNewFile", IUniversalDataStoreConstants.C_CREATE_FILE); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFileObject, "CreateNewFolder", IUniversalDataStoreConstants.C_CREATE_FOLDER); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFileObject, "Rename", IUniversalDataStoreConstants.C_RENAME); //$NON-NLS-1$ + //create deleteDescriptor and make it cancelable + DataElement deleteFileDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFileObject, "Delete", IUniversalDataStoreConstants.C_DELETE); //$NON-NLS-1$ + _dataStore.createReference(cancellable, deleteFileDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + //create deleteBatchDescriptor and make it cancelable + DataElement deleteBatchFileDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFileObject, "DeleteBatch", IUniversalDataStoreConstants.C_DELETE_BATCH); //$NON-NLS-1$ + _dataStore.createReference(cancellable, deleteBatchFileDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + //create createNewFileDescriptor and make it cancelable + DataElement createNewFileDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFileObject, "CreateNewFile", IUniversalDataStoreConstants.C_CREATE_FILE); //$NON-NLS-1$ + _dataStore.createReference(cancellable, createNewFileDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + //create createNewFolderDescriptor and make it cancelable + DataElement createNewFolderDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFileObject, "CreateNewFolder", IUniversalDataStoreConstants.C_CREATE_FOLDER); //$NON-NLS-1$ + _dataStore.createReference(cancellable, createNewFolderDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + //create renameDescriptor and make it cancelable + DataElement renameFileDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFileObject, "Rename", IUniversalDataStoreConstants.C_RENAME); //$NON-NLS-1$ + _dataStore.createReference(cancellable, renameFileDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); createCommandDescriptor(FileDescriptors._deUniversalFileObject, "SetReadOnly", IUniversalDataStoreConstants.C_SET_READONLY); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFileObject, "SetLastModified", IUniversalDataStoreConstants.C_SET_LASTMODIFIED); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetAdvanceProperty", IUniversalDataStoreConstants.C_QUERY_ADVANCE_PROPERTY); //$NON-NLS-1$ @@ -2042,13 +1478,22 @@ public class UniversalFileSystemMiner extends Miner { createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetcanWriteProperty", IUniversalDataStoreConstants.C_QUERY_CAN_WRITE_PROPERTY); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFileObject, "Exists", IUniversalDataStoreConstants.C_QUERY_EXISTS); //$NON-NLS-1$ - - createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Delete", IUniversalDataStoreConstants.C_DELETE); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "DeleteBatch", IUniversalDataStoreConstants.C_DELETE_BATCH); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Rename", IUniversalDataStoreConstants.C_RENAME); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Copy", IUniversalDataStoreConstants.C_COPY); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "CopyBatch", IUniversalDataStoreConstants.C_COPY_BATCH); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "CreateNewFolder", IUniversalDataStoreConstants.C_CREATE_FOLDER); //$NON-NLS-1$ + + //create deleteDescriptor and make it cancelable + DataElement deleteFolderDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Delete", IUniversalDataStoreConstants.C_DELETE); //$NON-NLS-1$ + _dataStore.createReference(cancellable, deleteFolderDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + //create deleteBatchDescriptor and make it cancelable + DataElement deleteBatchFolderDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "DeleteBatch", IUniversalDataStoreConstants.C_DELETE_BATCH); //$NON-NLS-1$ + _dataStore.createReference(cancellable, deleteBatchFolderDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + //create renameDescriptor and make it cancelable + DataElement renameFolderDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Rename", IUniversalDataStoreConstants.C_RENAME); //$NON-NLS-1$ + _dataStore.createReference(cancellable, renameFolderDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + //create copyDescriptor and make it cancelable + DataElement copyFolderDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Copy", IUniversalDataStoreConstants.C_COPY); //$NON-NLS-1$ + _dataStore.createReference(cancellable, copyFolderDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + //create copyFolderBatchDescriptor and make it cancelable + DataElement copyBatchFolderDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "CopyBatch", IUniversalDataStoreConstants.C_COPY_BATCH); //$NON-NLS-1$ + _dataStore.createReference(cancellable, copyBatchFolderDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "SetReadOnly", IUniversalDataStoreConstants.C_SET_READONLY); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "SetLastModified", IUniversalDataStoreConstants.C_SET_LASTMODIFIED); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "GetBasicProperty", IUniversalDataStoreConstants.C_QUERY_BASIC_PROPERTY); //$NON-NLS-1$ @@ -2057,8 +1502,12 @@ public class UniversalFileSystemMiner extends Miner { createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetFileClassifications", IUniversalDataStoreConstants.C_QUERY_FILE_CLASSIFICATIONS); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "GetFolderClassifications", IUniversalDataStoreConstants.C_QUERY_FILE_CLASSIFICATION); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Exists", IUniversalDataStoreConstants.C_QUERY_EXISTS); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "CreateNewFile", IUniversalDataStoreConstants.C_CREATE_FILE); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "CreateNewFolder", IUniversalDataStoreConstants.C_CREATE_FOLDER); //$NON-NLS-1$ + //create createFolderDescriptor and make it cancelable + DataElement createNewFileInFolderDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "CreateNewFile", IUniversalDataStoreConstants.C_CREATE_FILE); //$NON-NLS-1$ + _dataStore.createReference(cancellable, createNewFileInFolderDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + //create createFolderDescriptor and make it cancelable + DataElement createNewFolderInFolderDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "CreateNewFolder", IUniversalDataStoreConstants.C_CREATE_FOLDER); //$NON-NLS-1$ + _dataStore.createReference(cancellable, createNewFolderInFolderDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "GetOSType", IUniversalDataStoreConstants.C_GET_OSTYPE); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetOSType", IUniversalDataStoreConstants.C_GET_OSTYPE); //$NON-NLS-1$ @@ -2087,7 +1536,7 @@ public class UniversalFileSystemMiner extends Miner { IUniversalDataStoreConstants.C_QUERY_QUALIFIED_CLASSNAME); } - private AbsoluteVirtualPath getAbsoluteVirtualPath(DataElement subject) { + public AbsoluteVirtualPath getAbsoluteVirtualPath(DataElement subject) { StringBuffer path = new StringBuffer(subject.getAttribute(DE.A_VALUE)); if (ArchiveHandlerManager.getInstance().isArchive( new File(path.toString()))) { @@ -2104,39 +1553,7 @@ public class UniversalFileSystemMiner extends Miner { return vp; } - public DataElement handleDeleteFromArchive(DataElement subject, - DataElement status) { - String type = subject.getType(); - DataElement deObj = null; - AbsoluteVirtualPath vpath = getAbsoluteVirtualPath(subject); - if (vpath != null) { - ISystemArchiveHandler handler = _archiveHandlerManager - .getRegisteredHandler(new File(vpath - .getContainingArchiveString())); - if (handler == null || !handler.delete(vpath.getVirtualPart(), null)) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED + "|" + vpath.toString()); //$NON-NLS-1$ - _dataStore.refresh(subject); - return statusDone(status); - } - - if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) { - deObj = _dataStore.find(subject, DE.A_NAME, subject.getName(), - 1); - _dataStore.deleteObject(subject, deObj); - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - } else if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { - _dataStore.deleteObjects(subject); - DataElement parent = subject.getParent(); - _dataStore.deleteObject(parent, subject); - _dataStore.refresh(parent); - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - } - } - - _dataStore.refresh(subject); - return statusDone(status); - } public DataElement handleQueryAllArchive(DataElement subject, DataElement attributes, DataElement status, boolean caseSensitive, boolean foldersOnly) @@ -2156,230 +1573,15 @@ public class UniversalFileSystemMiner extends Miner { return _archiveHandlerManager.getRegisteredHandler(file); } - public DataElement handleCreateVirtualFile(DataElement subject, - DataElement status, String type) { - - AbsoluteVirtualPath vpath = null; - if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { - vpath = getAbsoluteVirtualPath(subject.getValue()); - } else { - vpath = getAbsoluteVirtualPath(subject); - } - ISystemArchiveHandler handler = getArchiveHandlerFor(vpath - .getContainingArchiveString()); - if (handler == null) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - return statusDone(status); - } -// VirtualChild child = handler.getVirtualFile(vpath.getVirtualPart()); - handler.getVirtualFile(vpath.getVirtualPart(), null); - handler.createFile(vpath.getVirtualPart(), null); - - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { - String fullName = subject.getValue(); - String name = fullName.substring(fullName - .lastIndexOf(File.separatorChar) + 1, fullName.length()); - String path = fullName.substring(0, fullName - .lastIndexOf(File.separatorChar)); - subject.setAttribute(DE.A_NAME, name); - subject.setAttribute(DE.A_VALUE, path); - subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR); - } - _dataStore.refresh(subject); - return statusDone(status); - } - - public DataElement handleCreateVirtualFolder(DataElement subject, - DataElement status, String type) { - - AbsoluteVirtualPath vpath = null; - if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { - vpath = getAbsoluteVirtualPath(subject.getValue()); - } else { - vpath = getAbsoluteVirtualPath(subject); - } - ISystemArchiveHandler handler = getArchiveHandlerFor(vpath - .getContainingArchiveString()); - if (handler == null) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - return statusDone(status); - } -// VirtualChild child = handler.getVirtualFile(vpath.getVirtualPart()); - handler.getVirtualFile(vpath.getVirtualPart(), null); - handler.createFolder(vpath.getVirtualPart(), null); - - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { - String fullName = subject.getValue(); - String name = fullName.substring(fullName - .lastIndexOf(File.separatorChar) + 1, fullName.length()); - String path = fullName.substring(0, fullName - .lastIndexOf(File.separatorChar)); - subject.setAttribute(DE.A_NAME, name); - subject.setAttribute(DE.A_VALUE, path); - subject - .setAttribute(DE.A_TYPE, - IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR); - } - _dataStore.refresh(subject); - return statusDone(status); - } - - private File getFileFor(DataElement element) { - File result = null; - String type = element.getType(); - if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { - result = new File(element.getName()); - } else if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) - || type.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) - || type.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) { - StringBuffer buf = new StringBuffer(element - .getAttribute(DE.A_VALUE)); - buf.append(File.separatorChar); - buf.append(element.getName()); - result = new File(buf.toString()); - } - - return result; - } public DataElement handleCopy(DataElement targetFolder, DataElement sourceFile, DataElement nameObj, DataElement status) { - String newName = nameObj.getName(); - String targetType = targetFolder.getType(); - String srcType = sourceFile.getType(); - //In the case of super transfer, the source file is a virtual file/folder inside the temporary zip file, and its type information is set to - //default UNIVERSAL_FILTER_DESCRIPTOR since its information never been cached before. - //We need to find out its real type first before going to different if statement. - File srcFile = null; - VirtualChild child = null; - if (IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR == srcType) - { - if (ArchiveHandlerManager.isVirtual(sourceFile.getValue())) - { - String goodFullName = ArchiveHandlerManager.cleanUpVirtualPath(sourceFile.getValue()); - child = _archiveHandlerManager.getVirtualObject(goodFullName); - if (child.exists()) - { - if (child.isDirectory) - { - srcType = IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR; - } else - { - srcType = IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR; - } - } - } - } + CopySingleThread copySingleThread = new CopySingleThread(targetFolder, sourceFile, nameObj, this, _isWindows, status); + copySingleThread.start(); + + updateCancellableThreads(status.getParent(), copySingleThread); - if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { - - // insert into an archive - AbsoluteVirtualPath vpath = getAbsoluteVirtualPath(targetFolder); - ISystemArchiveHandler handler = getArchiveHandlerFor(vpath.getContainingArchiveString()); - - if (handler == null) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - return statusDone(status); - } - - if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) - || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) { - - srcFile = getFileFor(sourceFile); - } - else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { - ISystemArchiveHandler shandler = null; - if (null == child) - { - AbsoluteVirtualPath svpath = getAbsoluteVirtualPath(sourceFile); - shandler = getArchiveHandlerFor(svpath.getContainingArchiveString()); - - if (shandler == null) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - return statusDone(status); - } - child = shandler.getVirtualFile(svpath.getVirtualPart(), null); - } - else - { - //If child is not null, it means the sourceFile is a type of UNIVERSAL_FILTER_DESCRIPTOR, and has already been handled - shandler = child.getHandler(); - } - srcFile = child.getExtractedFile(); - } - - String virtualContainer = ""; //$NON-NLS-1$ - - if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { - virtualContainer = vpath.getVirtualPart(); - } - - boolean result = handler.add(srcFile, virtualContainer, newName, null); - - if (result) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - } - else { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - } - } - else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { - ISystemArchiveHandler shandler = null; - AbsoluteVirtualPath svpath = null; - if (null == child) - { - svpath = getAbsoluteVirtualPath(sourceFile); - shandler = getArchiveHandlerFor(svpath.getContainingArchiveString()); - - if (shandler == null) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - return statusDone(status); - } - child = shandler.getVirtualFile(svpath.getVirtualPart(), null); - } - else - { - //If child is not null, it means the sourceFile is a type of UNIVERSAL_FILTER_DESCRIPTOR, and has already been handled - shandler = child.getHandler(); - svpath = getAbsoluteVirtualPath(sourceFile.getValue()); - } - - File parentDir = getFileFor(targetFolder); - File destination = new File(parentDir, newName); - - if (child.isDirectory) { - shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination, null); - } - else { - shandler.extractVirtualFile(svpath.getVirtualPart(), destination, null); - } - } - else { - File tgtFolder = getFileFor(targetFolder); - srcFile = getFileFor(sourceFile); - - // regular copy - boolean folderCopy = srcFile.isDirectory(); - String src = srcFile.getAbsolutePath(); - String tgt = tgtFolder.getAbsolutePath() + File.separatorChar + newName; - File tgtFile = new File(tgt); - - if (tgtFile.exists() && tgtFile.isDirectory()) - { - //For Windows, we need to use xcopy command, which require the new directory - //name be part of the target. - if (newName.equals(srcFile.getName()) && !_isWindows) - { - tgt = tgtFolder.getAbsolutePath(); - } - } - - doCopyCommand(enQuote(src), enQuote(tgt), folderCopy, status); - } - - return statusDone(status); + return status; } /** @@ -2479,21 +1681,6 @@ public class UniversalFileSystemMiner extends Miner { return setProperties(fileObj, false); } - - - /** - * Quote a file name such that it is valid in a shell - * @param s file name to quote - * @return quoted file name - */ - protected String enQuote(String s) - { - if(_isWindows) { - return '"' + s + '"'; - } else { - return PathUtility.enQuoteUnix(s); - } - } public String getVersion() { diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopyBatchThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopyBatchThread.java new file mode 100644 index 00000000000..01fa19456d6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopyBatchThread.java @@ -0,0 +1,255 @@ +/******************************************************************************** + * Copyright (c) 2007 IBM Corporation. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight. + * + * Contributors: + * {Name} (company) - description of contribution. + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations + ********************************************************************************/ +package org.eclipse.rse.internal.dstore.universal.miners.filesystem; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.SystemOperationMonitor; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; +import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; + +public class CopyBatchThread extends CopyThread { + + + public CopyBatchThread(DataElement targetFolder, DataElement theElement, UniversalFileSystemMiner miner, boolean isWindows, DataElement status) + { + super(targetFolder, theElement, miner, isWindows, status); + } + + public void run() + { + handleCopyBatch(); + _isDone = true; + } + + private DataElement handleCopyBatch() + { + String targetType = targetFolder.getType(); + File tgtFolder = getFileFor(targetFolder); + int numOfSources = theElement.getNestedSize() - 2; + systemOperationMonitor = new SystemOperationMonitor(); + + if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + { + // if target is virtual or an archive, insert into an archive + AbsoluteVirtualPath vpath = miner.getAbsoluteVirtualPath(targetFolder); + ISystemArchiveHandler handler = miner.getArchiveHandlerFor(vpath.getContainingArchiveString()); + boolean result = true; + + if (handler == null) + { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + return miner.statusDone(status); + } + + List nonDirectoryArrayList = new ArrayList(); + List nonDirectoryNamesArrayList = new ArrayList(); + + String virtualContainer = ""; //$NON-NLS-1$ + + if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + { + virtualContainer = vpath.getVirtualPart(); + } + + for (int i = 0; i < numOfSources; i++) + { + if (isCancelled()) + { + return miner.statusCancelled(status); + } + DataElement sourceFile = miner.getCommandArgument(theElement, i+1); + String srcType = sourceFile.getType(); + String srcName = sourceFile.getName(); + File srcFile; + + if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) + || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) + { + srcFile = getFileFor(sourceFile); + } + else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + { + AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile); + ISystemArchiveHandler shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); + + if (shandler == null) + { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + return miner.statusDone(status); + } + + VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart(), systemOperationMonitor); + srcFile = child.getExtractedFile(); + } + else { + //invalid source type + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + return miner.statusDone(status); + } + + //If this source file object is directory, we will call ISystemArchiveHandler#add(File ...) method to + //it and all its descendants into the archive file. + //If this source file object is not a directory, we will add it into a list, and then + //call ISystemArchiveHandler#add(File[] ...) to add them in batch. + if (srcFile.isDirectory()) + { + result = handler.add(srcFile, virtualContainer, srcName, systemOperationMonitor); + if (!result) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + if (isCancelled()) + { + return miner.statusCancelled(status); + } + else + { + return miner.statusDone(status); + } + } + } + else + { + nonDirectoryArrayList.add(srcFile); + nonDirectoryNamesArrayList.add(srcName); + } + } + + if (nonDirectoryArrayList.size() > 0) + { + File[] resultFiles = (File[])nonDirectoryArrayList.toArray(new File[nonDirectoryArrayList.size()]); + String[] resultNames = (String[])nonDirectoryNamesArrayList.toArray(new String[nonDirectoryNamesArrayList.size()]); + //we need to add those files into the archive file as well. + result = handler.add(resultFiles, virtualContainer, resultNames, systemOperationMonitor); + } + + if (result) + { + status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + } + else + { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + } + if (isCancelled()) + { + return miner.statusCancelled(status); + } + else + { + return miner.statusDone(status); + } + } + else // target is a regular folder + { + boolean folderCopy = false; + String source = ""; //$NON-NLS-1$ + String tgt = enQuote(tgtFolder.getAbsolutePath()); + + int numOfNonVirtualSources = 0; + for (int i = 0; i < numOfSources; i++) + { + if (isCancelled()) + { + return miner.statusCancelled(status); + } + DataElement sourceFile = miner.getCommandArgument(theElement, i+1); + String srcType = sourceFile.getType(); + + if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + { + // extract from an archive to folder + AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile); + ISystemArchiveHandler shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); + + if (shandler == null) + { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + return miner.statusDone(status); + } + + VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart(), systemOperationMonitor); + + File parentDir = getFileFor(targetFolder); + File destination = new File(parentDir, sourceFile.getName()); + + if (child.isDirectory) + { + shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination, systemOperationMonitor); + } + else + { + shandler.extractVirtualFile(svpath.getVirtualPart(), destination, systemOperationMonitor); + } + } + else // source is regular file or folder + { + File srcFile = getFileFor(sourceFile); + folderCopy = folderCopy || srcFile.isDirectory(); + String src = srcFile.getAbsolutePath(); + + // handle special characters in source and target strings + src = enQuote(src); + + // handle window case separately, since xcopy command could not handler + // multiple source names + if (isWindows) + { + tgt = tgtFolder.getAbsolutePath() + File.separatorChar + srcFile.getName(); + // Both unix and windows need src quoted, so it's already done + doCopyCommand(src, enQuote(tgt), folderCopy, status); + if (status.getAttribute(DE.A_SOURCE) == IServiceConstants.FAILED) + { + break; + } + continue; + } + if (numOfNonVirtualSources == 0) + { + source += src; + } + else + { + source = source + " " + src; //$NON-NLS-1$ + } + numOfNonVirtualSources++; + } + } // end for loop iterating through sources + + if (numOfNonVirtualSources > 0) + { + doCopyCommand(source, tgt, folderCopy, status); + } + } // end if/then/else (target is regular folder) + if (isCancelled()) + { + return miner.statusCancelled(status); + } + else + { + return miner.statusDone(status); + } + } + + + +} diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopySingleThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopySingleThread.java new file mode 100644 index 00000000000..bd8d4022a2b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopySingleThread.java @@ -0,0 +1,191 @@ +/******************************************************************************** + * Copyright (c) 2007 IBM Corporation. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight. + * + * Contributors: + * {Name} (company) - description of contribution. + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations + ********************************************************************************/ +package org.eclipse.rse.internal.dstore.universal.miners.filesystem; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.SystemOperationMonitor; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; +import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; + +public class CopySingleThread extends CopyThread { + + private DataElement nameObj; + + + public CopySingleThread(DataElement targetFolder, DataElement theElement, DataElement nameObj, UniversalFileSystemMiner miner, boolean isWindows, DataElement status) + { + super(targetFolder, theElement, miner, isWindows, status); + this.nameObj = nameObj; + } + + public void run() + { + handleCopy(); + _isDone = true; + } + + private DataElement handleCopy() + { + DataElement sourceFile = theElement; + String newName = nameObj.getName(); + String targetType = targetFolder.getType(); + String srcType = sourceFile.getType(); + //In the case of super transfer, the source file is a virtual file/folder inside the temporary zip file, and its type information is set to + //default UNIVERSAL_FILTER_DESCRIPTOR since its information never been cached before. + //We need to find out its real type first before going to different if statement. + File srcFile = null; + VirtualChild child = null; + systemOperationMonitor = new SystemOperationMonitor(); + if (IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR == srcType) + { + if (ArchiveHandlerManager.isVirtual(sourceFile.getValue())) + { + String goodFullName = ArchiveHandlerManager.cleanUpVirtualPath(sourceFile.getValue()); + child = ArchiveHandlerManager.getInstance().getVirtualObject(goodFullName); + if (child.exists()) + { + if (child.isDirectory) + { + srcType = IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR; + } else + { + srcType = IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR; + } + } + } + } + + if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + + // insert into an archive + AbsoluteVirtualPath vpath = miner.getAbsoluteVirtualPath(targetFolder); + ISystemArchiveHandler handler = miner.getArchiveHandlerFor(vpath.getContainingArchiveString()); + + if (handler == null) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + return miner.statusDone(status); + } + + if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) + || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) { + + srcFile = getFileFor(sourceFile); + } + else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + ISystemArchiveHandler shandler = null; + if (null == child) + { + AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile); + shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); + + if (shandler == null) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + return miner.statusDone(status); + } + child = shandler.getVirtualFile(svpath.getVirtualPart(), systemOperationMonitor); + } + else + { + //If child is not null, it means the sourceFile is a type of UNIVERSAL_FILTER_DESCRIPTOR, and has already been handled + shandler = child.getHandler(); + } + srcFile = child.getExtractedFile(); + } + + String virtualContainer = ""; //$NON-NLS-1$ + + if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + virtualContainer = vpath.getVirtualPart(); + } + + boolean result = handler.add(srcFile, virtualContainer, newName, systemOperationMonitor); + + if (result) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + } + else { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + } + } + else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + ISystemArchiveHandler shandler = null; + AbsoluteVirtualPath svpath = null; + if (null == child) + { + svpath = miner.getAbsoluteVirtualPath(sourceFile); + shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); + + if (shandler == null) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + return miner.statusDone(status); + } + child = shandler.getVirtualFile(svpath.getVirtualPart(), systemOperationMonitor); + } + else + { + //If child is not null, it means the sourceFile is a type of UNIVERSAL_FILTER_DESCRIPTOR, and has already been handled + shandler = child.getHandler(); + svpath = miner.getAbsoluteVirtualPath(sourceFile.getValue()); + } + + File parentDir = getFileFor(targetFolder); + File destination = new File(parentDir, newName); + + if (child.isDirectory) { + shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination, systemOperationMonitor); + } + else { + shandler.extractVirtualFile(svpath.getVirtualPart(), destination, systemOperationMonitor); + } + } + else { + File tgtFolder = getFileFor(targetFolder); + srcFile = getFileFor(sourceFile); + + // regular copy + boolean folderCopy = srcFile.isDirectory(); + String src = srcFile.getAbsolutePath(); + String tgt = tgtFolder.getAbsolutePath() + File.separatorChar + newName; + File tgtFile = new File(tgt); + + if (tgtFile.exists() && tgtFile.isDirectory()) + { + //For Windows, we need to use xcopy command, which require the new directory + //name be part of the target. + if (newName.equals(srcFile.getName()) && !isWindows) + { + tgt = tgtFolder.getAbsolutePath(); + } + } + + doCopyCommand(enQuote(src), enQuote(tgt), folderCopy, status); + } + + return miner.statusDone(status); + } + + + +} diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopyThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopyThread.java new file mode 100644 index 00000000000..970067775a1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopyThread.java @@ -0,0 +1,250 @@ +/******************************************************************************** + * Copyright (c) 2007 IBM Corporation. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight. + * + * Contributors: + * {Name} (company) - description of contribution. + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations + ********************************************************************************/ +package org.eclipse.rse.internal.dstore.universal.miners.filesystem; + +import java.io.File; +import java.io.InputStream; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; +import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.PathUtility; +import org.eclipse.rse.services.clientserver.SystemOperationMonitor; + +public class CopyThread extends Thread implements ICancellableHandler { + + protected DataElement targetFolder; + protected DataElement theElement; + protected DataElement status; + protected UniversalFileSystemMiner miner; + protected boolean isWindows; + + protected boolean _isCancelled = false; + protected boolean _isDone = false; + protected SystemOperationMonitor systemOperationMonitor = null; + + public static final String CLASSNAME = "CopyThread"; //$NON-NLS-1$ + + + public CopyThread(DataElement targetFolder, DataElement theElement, UniversalFileSystemMiner miner, boolean isWindows, DataElement status) + { + this.targetFolder = targetFolder; + this.theElement = theElement; + this.miner = miner; + this.status = status; + this.isWindows = isWindows; + } + + protected File getFileFor(DataElement element) { + File result = null; + String type = element.getType(); + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { + result = new File(element.getName()); + } else if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) + || type.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) + || type.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) { + StringBuffer buf = new StringBuffer(element + .getAttribute(DE.A_VALUE)); + buf.append(File.separatorChar); + buf.append(element.getName()); + result = new File(buf.toString()); + } + + return result; + } + + /** + * Quote a file name such that it is valid in a shell + * @param s file name to quote + * @return quoted file name + */ + protected String enQuote(String s) + { + if(isWindows) { + return '"' + s + '"'; + } else { + return PathUtility.enQuoteUnix(s); + } + } + + protected void doCopyCommand(String source, String tgt, boolean folderCopy, DataElement status) + { + String command = null; + if (isWindows) { + + if (folderCopy) { + command = "xcopy " + source //$NON-NLS-1$ + + " " + tgt //$NON-NLS-1$ + + " /S /E /K /Q /H /I /Y"; //$NON-NLS-1$ + } + else { + String unquotedTgt = tgt.substring(1, tgt.length() - 1); + + File targetFile = new File(unquotedTgt); + if (!targetFile.exists()) + { + // create file so as to avoid ambiguity + try + { + targetFile.createNewFile(); + } + catch (Exception e) + { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + status.setAttribute(DE.A_VALUE, e.getMessage()); + return; + } + } + command = "xcopy " + source + " " + tgt + " /Y /K /Q /H"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + } + else { + if (folderCopy) { + command = "cp -Rp " + source + " " + tgt; //$NON-NLS-1$ //$NON-NLS-2$ + } + else { + command = "cp -p " + source + " " + tgt; //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + // run copy command + try + { + Runtime runtime = Runtime.getRuntime(); + Process p = null; + + if (isWindows) + { + String theShell = "cmd /C "; //$NON-NLS-1$ + p = runtime.exec(theShell + command); + } + else + { + String theShell = "sh"; //$NON-NLS-1$ + String args[] = new String[3]; + args[0] = theShell; + args[1] = "-c"; //$NON-NLS-1$ + args[2] = command; + + p = runtime.exec(args); + } + + // ensure there is a process + if (p != null) { + + // wait for process to finish + p.waitFor(); + + // get the exit value of the process + int result = p.exitValue(); + + // if the exit value is not 0, then the process did not terminate normally + if (result != 0) { + + // get the error stream + InputStream errStream = p.getErrorStream(); + + // error buffer + StringBuffer errBuf = new StringBuffer(); + + byte[] bytes = null; + + int numOfBytesRead = 0; + + int available = errStream.available(); + + // read error stream and store in error buffer + while (available > 0) { + + bytes = new byte[available]; + + numOfBytesRead = errStream.read(bytes); + + if (numOfBytesRead > -1) { + errBuf.append(new String(bytes, 0, numOfBytesRead)); + } + else { + break; + } + + available = errStream.available(); + } + + String err = errBuf.toString(); + + // omit new line if there is one at the end because datastore does not + // handle new line in the attributes + // TODO: what to do if newline occurs in the middle of the string? + String newLine = System.getProperty("line.separator"); //$NON-NLS-1$ + + if (newLine != null && err.endsWith(newLine)) { + err = err.substring(0, err.length() - newLine.length()); + } + + // if there is something in error buffer + // there was something in the error stream of the process + if (err.length() > 0) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + status.setAttribute(DE.A_VALUE, err); + } + // otherwise, nothing in the error stream + // but we know process did not exit normally, so we indicate an unexpected error + else { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + status.setAttribute(DE.A_VALUE, IServiceConstants.UNEXPECTED_ERROR); + } + } + // otherwise if exit value is 0, process terminated normally + else { + status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + } + } + // no process, so something is wrong + else { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + status.setAttribute(DE.A_VALUE, IServiceConstants.UNEXPECTED_ERROR); + } + } + catch (Exception e) + { + UniversalServerUtilities.logError(CLASSNAME, "Exception is handleCopy", e); //$NON-NLS-1$ + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + status.setAttribute(DE.A_VALUE, e.getMessage()); + } + } + + + public void cancel() { + _isCancelled = true; + System.out.println("Inside cancel() of thread " + CLASSNAME); + if (null != systemOperationMonitor) + { + systemOperationMonitor.setCanceled(true); + } + } + + public boolean isCancelled() { + return _isCancelled; + } + + public boolean isDone() { + return _isDone; + } + +} diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFileThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFileThread.java new file mode 100644 index 00000000000..6fab3c1d780 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFileThread.java @@ -0,0 +1,186 @@ +/******************************************************************************** + * Copyright (c) 2007 IBM Corporation. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight. + * + * Contributors: + * {Name} (company) - description of contribution. + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations + ********************************************************************************/ +package org.eclipse.rse.internal.dstore.universal.miners.filesystem; + +import java.io.File; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; +import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.SystemOperationMonitor; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; + +public class CreateFileThread extends Thread implements ICancellableHandler { + + protected DataElement _subject; + protected DataElement _status; + private DataStore _dataStore; + protected UniversalFileSystemMiner _miner; + protected String _queryType; + + protected boolean _isCancelled = false; + protected boolean _isDone = false; + protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); + + public static final String CLASSNAME = "CreateFileThread"; //$NON-NLS-1$ + + + public CreateFileThread(DataElement theElement, String queryType, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status) + { + this._subject = theElement; + this._miner = miner; + this._dataStore = dataStore; + this._status = status; + this._queryType = queryType; + } + + + + + public void cancel() { + _isCancelled = true; + if (null != systemOperationMonitor) + { + systemOperationMonitor.setCanceled(true); + } + } + + public boolean isCancelled() { + return _isCancelled; + } + + public boolean isDone() { + return _isDone; + } + + public void run() + { + handleCreateFile(); + _isDone = true; + } + + private DataElement handleCreateFile() + { + boolean wasFilter = _queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR); + if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) { + return handleCreateVirtualFile(_subject, _status, _queryType); + } + + File filename = null; + if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { + if (_subject.getName().indexOf( + ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0) { + _subject.setAttribute(DE.A_TYPE, + IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR); + return handleCreateVirtualFile(_subject, _status, _queryType); + } else { + filename = new File(_subject.getValue()); + _subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR); + _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(filename)); + } + } else if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR)) + filename = new File(_subject.getAttribute(DE.A_VALUE) + + File.separatorChar + _subject.getName()); + else + UniversalServerUtilities.logError(CLASSNAME, + "Invalid query type to handleCreateFile", null); //$NON-NLS-1$ + + if (filename != null) + { + if (filename.exists()) + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXIST); + else { + try { + boolean done = filename.createNewFile(); + if (ArchiveHandlerManager.getInstance().isArchive(filename)) { + done = ArchiveHandlerManager.getInstance() + .createEmptyArchive(filename); + if (done) + _subject.setAttribute(DE.A_TYPE, + IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR); + } else { + if (done) + { + _subject.setAttribute(DE.A_TYPE, + IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR); + } + } + _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(filename)); + if (done) { + _status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + if (wasFilter) { + String fullName = _subject.getValue(); + String name = fullName.substring(fullName + .lastIndexOf(File.separatorChar) + 1, fullName + .length()); + String path = fullName.substring(0, fullName + .lastIndexOf(File.separatorChar)); + _subject.setAttribute(DE.A_NAME, name); + _subject.setAttribute(DE.A_VALUE, path); + } + } else + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + } catch (Exception e) { + UniversalServerUtilities.logError(CLASSNAME, + "handleCreateFile failed", e); //$NON-NLS-1$ + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + } + } + } + _dataStore.refresh(_subject); + return _miner.statusDone(_status); + } + + public DataElement handleCreateVirtualFile(DataElement subject, + DataElement status, String type) { + + AbsoluteVirtualPath vpath = null; + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { + vpath = _miner.getAbsoluteVirtualPath(subject.getValue()); + } else { + vpath = _miner.getAbsoluteVirtualPath(subject); + } + ISystemArchiveHandler handler = _miner.getArchiveHandlerFor(vpath + .getContainingArchiveString()); + if (handler == null) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + return _miner.statusDone(status); + } +// VirtualChild child = handler.getVirtualFile(vpath.getVirtualPart()); + handler.getVirtualFile(vpath.getVirtualPart(), systemOperationMonitor); + handler.createFile(vpath.getVirtualPart(), systemOperationMonitor); + + status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { + String fullName = subject.getValue(); + String name = fullName.substring(fullName + .lastIndexOf(File.separatorChar) + 1, fullName.length()); + String path = fullName.substring(0, fullName + .lastIndexOf(File.separatorChar)); + subject.setAttribute(DE.A_NAME, name); + subject.setAttribute(DE.A_VALUE, path); + subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR); + } + _dataStore.refresh(subject); + return _miner.statusDone(status); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFolderThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFolderThread.java new file mode 100644 index 00000000000..ccb0136e47e --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFolderThread.java @@ -0,0 +1,179 @@ +/******************************************************************************** + * Copyright (c) 2007 IBM Corporation. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight. + * + * Contributors: + * {Name} (company) - description of contribution. + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations + ********************************************************************************/ +package org.eclipse.rse.internal.dstore.universal.miners.filesystem; + +import java.io.File; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; +import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.SystemOperationMonitor; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; + +public class CreateFolderThread extends Thread implements ICancellableHandler { + + protected DataElement _subject; + protected DataElement _status; + private DataStore _dataStore; + protected UniversalFileSystemMiner _miner; + protected String _queryType; + + protected boolean _isCancelled = false; + protected boolean _isDone = false; + protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); + + public static final String CLASSNAME = "CreateFileThread"; //$NON-NLS-1$ + + + public CreateFolderThread(DataElement theElement, String queryType, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status) + { + this._subject = theElement; + this._miner = miner; + this._dataStore = dataStore; + this._status = status; + this._queryType = queryType; + } + + + + + public void cancel() { + _isCancelled = true; + if (null != systemOperationMonitor) + { + systemOperationMonitor.setCanceled(true); + } + } + + public boolean isCancelled() { + return _isCancelled; + } + + public boolean isDone() { + return _isDone; + } + + public void run() + { + handleCreateFile(); + _isDone = true; + } + + private DataElement handleCreateFile() + { + if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + return handleCreateVirtualFolder(_subject, _status, _queryType); + } + + File filename = null; + if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) + { + if (_subject.getName().indexOf( + ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0) + { + _subject.setAttribute(DE.A_TYPE, + IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR); + return handleCreateVirtualFolder(_subject, _status, _queryType); + } + else + { + filename = new File(_subject.getValue()); + _subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR); + _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(filename)); + } + } + else if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR)) + { + filename = new File(_subject.getValue()); + } + else + UniversalServerUtilities.logError(CLASSNAME, + "Invalid query type to handleCreateFolder", null); //$NON-NLS-1$ + + if (filename != null) + { + if (filename.exists()) + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXIST); + else + { + try { + boolean done = filename.mkdirs(); + if (done) + { + _status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(filename)); + _subject.setAttribute(DE.A_TYPE,IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR); + _subject.setAttribute(DE.A_NAME, filename.getName()); + _subject.setAttribute(DE.A_VALUE, filename.getParentFile().getAbsolutePath()); + } + else + { + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + } + + } catch (Exception e) { + UniversalServerUtilities.logError(CLASSNAME, + "handleCreateFolder failed", e); //$NON-NLS-1$ + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + } + } + } + _dataStore.refresh(_subject); + return _miner.statusDone(_status); + } + + public DataElement handleCreateVirtualFolder(DataElement subject, + DataElement status, String type) { + + AbsoluteVirtualPath vpath = null; + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { + vpath = _miner.getAbsoluteVirtualPath(subject.getValue()); + } else { + vpath = _miner.getAbsoluteVirtualPath(subject); + } + ISystemArchiveHandler handler = _miner.getArchiveHandlerFor(vpath + .getContainingArchiveString()); + if (handler == null) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + return _miner.statusDone(status); + } +// VirtualChild child = handler.getVirtualFile(vpath.getVirtualPart()); + handler.getVirtualFile(vpath.getVirtualPart(), systemOperationMonitor); + handler.createFolder(vpath.getVirtualPart(), systemOperationMonitor); + + status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { + String fullName = subject.getValue(); + String name = fullName.substring(fullName + .lastIndexOf(File.separatorChar) + 1, fullName.length()); + String path = fullName.substring(0, fullName + .lastIndexOf(File.separatorChar)); + subject.setAttribute(DE.A_NAME, name); + subject.setAttribute(DE.A_VALUE, path); + subject + .setAttribute(DE.A_TYPE, + IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR); + } + _dataStore.refresh(subject); + return _miner.statusDone(status); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/DeleteThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/DeleteThread.java new file mode 100644 index 00000000000..e08a68d2ed3 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/DeleteThread.java @@ -0,0 +1,243 @@ +/******************************************************************************** + * Copyright (c) 2007 IBM Corporation. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight. + * + * Contributors: + * {Name} (company) - description of contribution. + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations + ********************************************************************************/ +package org.eclipse.rse.internal.dstore.universal.miners.filesystem; + +import java.io.File; +import java.io.InputStream; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; +import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.PathUtility; +import org.eclipse.rse.services.clientserver.SystemOperationMonitor; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; + +public class DeleteThread extends Thread implements ICancellableHandler { + + protected DataElement _theElement; + protected DataElement _status; + private DataStore _dataStore; + protected UniversalFileSystemMiner _miner; + protected boolean _batch; + + protected boolean _isCancelled = false; + protected boolean _isDone = false; + protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); + + public static final String CLASSNAME = "DeleteThread"; //$NON-NLS-1$ + + + public DeleteThread(DataElement theElement, UniversalFileSystemMiner miner, DataStore dataStore, boolean batch, DataElement status) + { + this._theElement = theElement; + this._miner = miner; + this._dataStore = dataStore; + this._status = status; + this._batch = batch; + } + + + + + public void cancel() { + _isCancelled = true; + System.out.println("Inside cancel() of thread " + CLASSNAME); + if (null != systemOperationMonitor) + { + systemOperationMonitor.setCanceled(true); + } + } + + public boolean isCancelled() { + return _isCancelled; + } + + public boolean isDone() { + return _isDone; + } + + public void run() + { + if (_batch) + { + handleDeleteBatch(); + } + else + { + handleDelete(_theElement, _status); + } + _isDone = true; + } + + private DataElement handleDeleteBatch() + { + DataElement substatus = _dataStore.createObject(null, "status", "substatus"); //$NON-NLS-1$ //$NON-NLS-2$ + int numOfSources = _theElement.getNestedSize() - 2; + for (int i = 0; i < numOfSources; i++) + { + if (isCancelled()) + { + return _miner.statusCancelled(_status); + } + DataElement subject = _miner.getCommandArgument(_theElement, i+1); + handleDelete(subject, substatus); + /* + if (!substatus.getSource().startsWith(IServiceConstants.SUCCESS)) + { + status.setAttribute(DE.A_SOURCE, substatus.getSource()); + return statusDone(status); + } + */ + } + _status.setAttribute(DE.A_SOURCE, substatus.getSource()); + return _miner.statusDone(_status); + } + private DataElement handleDelete(DataElement subject, DataElement thisStatus) + { + + String type = subject.getType(); + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) + || type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + return handleDeleteFromArchive(subject, thisStatus); + } + + File deleteObj = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + DataElement deObj = null; + if (!deleteObj.exists()) { + thisStatus.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_DOES_NOT_EXIST + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ + UniversalServerUtilities.logError(CLASSNAME, + "The object to delete does not exist", null); //$NON-NLS-1$ + } else { + try { + if (deleteObj.isFile()) { + if (deleteObj.delete() == false) { + thisStatus.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ + } else { + // delete was successful and delete the object from the + // datastore + deObj = _dataStore.find(subject, DE.A_NAME, subject + .getName(), 1); + _dataStore.deleteObject(subject, deObj); + thisStatus.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ + } + _dataStore.refresh(subject); + } else if (deleteObj.isDirectory()) { // it is directory and + // need to delete the + // entire directory + + // children + deleteDir(deleteObj, thisStatus); + if (deleteObj.delete() == false) { + thisStatus.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ + UniversalServerUtilities.logError(CLASSNAME, + "Deletion of dir fialed", null); //$NON-NLS-1$ + } else { + _dataStore.deleteObjects(subject); + DataElement parent = subject.getParent(); + _dataStore.deleteObject(parent, subject); + _dataStore.refresh(parent); + thisStatus.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ + } + } else { + UniversalServerUtilities + .logError( + CLASSNAME, + "The object to delete is neither a File or Folder! in handleDelete", //$NON-NLS-1$ + null); + } + } catch (Exception e) { + thisStatus.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXCEPTION + "|" + deleteObj.getAbsolutePath()); //$NON-NLS-1$ + thisStatus.setAttribute(DE.A_VALUE, e.getLocalizedMessage()); + UniversalServerUtilities.logError(CLASSNAME, + "Delete of the object failed", e); //$NON-NLS-1$ + } + } + _dataStore.refresh(subject); + return _miner.statusDone(_status); + + } + + public DataElement handleDeleteFromArchive(DataElement subject, + DataElement status) { + String type = subject.getType(); + DataElement deObj = null; + + AbsoluteVirtualPath vpath = _miner.getAbsoluteVirtualPath(subject); + if (vpath != null) { + ArchiveHandlerManager archiveHandlerManager = ArchiveHandlerManager.getInstance(); + ISystemArchiveHandler handler = archiveHandlerManager.getRegisteredHandler(new File(vpath.getContainingArchiveString())); + if (handler == null || !handler.delete(vpath.getVirtualPart(), systemOperationMonitor)) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED + "|" + vpath.toString()); //$NON-NLS-1$ + _dataStore.refresh(subject); + return _miner.statusDone(status); + } + + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) { + deObj = _dataStore.find(subject, DE.A_NAME, subject.getName(), + 1); + _dataStore.deleteObject(subject, deObj); + status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + } else if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + _dataStore.deleteObjects(subject); + DataElement parent = subject.getParent(); + _dataStore.deleteObject(parent, subject); + _dataStore.refresh(parent); + status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + } + } + + _dataStore.refresh(subject); + return _miner.statusDone(status); + } + + /** + * Delete directory and its children. + * + */ + public void deleteDir(File fileObj, DataElement status) { + try { + File list[] = fileObj.listFiles(); + for (int i = 0; i < list.length; ++i) { + if (list[i].isFile()) { + if (!(list[i].delete())) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + UniversalServerUtilities.logWarning(CLASSNAME, + "Deletion of dir failed"); //$NON-NLS-1$ + } + } else { + deleteDir(list[i], status); + if (!(list[i].delete())) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + UniversalServerUtilities.logWarning(CLASSNAME, + "Deletion of dir failed"); //$NON-NLS-1$ + } + } + } + } catch (Exception e) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXCEPTION); + status.setAttribute(DE.A_VALUE, e.getLocalizedMessage()); + UniversalServerUtilities.logError(CLASSNAME, + "Deletion of dir failed", e); //$NON-NLS-1$ + } + } + +} diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/RenameThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/RenameThread.java new file mode 100644 index 00000000000..30ab9420ccf --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/RenameThread.java @@ -0,0 +1,159 @@ +/******************************************************************************** + * Copyright (c) 2007 IBM Corporation. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight. + * + * Contributors: + * {Name} (company) - description of contribution. + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations + ********************************************************************************/ +package org.eclipse.rse.internal.dstore.universal.miners.filesystem; + +import java.io.File; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; +import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.SystemOperationMonitor; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; + +public class RenameThread extends Thread implements ICancellableHandler { + + protected DataElement _subject; + protected DataElement _status; + private DataStore _dataStore; + protected UniversalFileSystemMiner _miner; + + protected boolean _isCancelled = false; + protected boolean _isDone = false; + protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); + + public static final String CLASSNAME = "RenameThread"; //$NON-NLS-1$ + + + public RenameThread(DataElement theElement, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status) + { + this._subject = theElement; + this._miner = miner; + this._dataStore = dataStore; + this._status = status; + } + + + + + public void cancel() { + _isCancelled = true; + if (null != systemOperationMonitor) + { + systemOperationMonitor.setCanceled(true); + } + } + + public boolean isCancelled() { + return _isCancelled; + } + + public boolean isDone() { + return _isDone; + } + + public void run() + { + handleRename(); + _isDone = true; + } + + private DataElement handleRename() + { + File fileoldname = new File(_subject.getAttribute(DE.A_VALUE) + + File.separatorChar + _subject.getName()); + File filerename = new File(_subject.getAttribute(DE.A_SOURCE)); + + if (ArchiveHandlerManager.isVirtual(fileoldname.getAbsolutePath())) { + AbsoluteVirtualPath oldAbsPath = new AbsoluteVirtualPath( + fileoldname.getAbsolutePath()); + AbsoluteVirtualPath newAbsPath = new AbsoluteVirtualPath(filerename + .getAbsolutePath()); + ArchiveHandlerManager archiveHandlerManager = ArchiveHandlerManager.getInstance(); + ISystemArchiveHandler handler = archiveHandlerManager + .getRegisteredHandler(new File(oldAbsPath + .getContainingArchiveString())); + boolean success = !(handler == null) + && handler.fullRename(oldAbsPath.getVirtualPart(), + newAbsPath.getVirtualPart(), systemOperationMonitor); + if (success && handler != null) { + _subject.setAttribute(DE.A_NAME, filerename.getName()); + _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(handler + .getVirtualFile(newAbsPath.getVirtualPart(), systemOperationMonitor))); + _status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + _dataStore.update(_subject); + } + else if (systemOperationMonitor.isCanceled()) + { + _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(handler + .getVirtualFile(oldAbsPath.getVirtualPart(), systemOperationMonitor))); + } + else { + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + } + _dataStore.refresh(_subject); + return _miner.statusDone(_status); + } + if (filerename.exists()) + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXIST); + else { + try { + boolean done = fileoldname.renameTo(filerename); + if (done) { + _subject.setAttribute(DE.A_NAME, filerename.getName()); + _subject + .setAttribute(DE.A_SOURCE, + _miner.setProperties(filerename)); + _status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + + if (filerename.isDirectory()) { + // update children's properties + updateChildProperties(_subject, filerename); + } + _dataStore.update(_subject); + } else + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + } catch (Exception e) { + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + UniversalServerUtilities.logError(CLASSNAME, + "handleRename failed", e); //$NON-NLS-1$ + } + } + _dataStore.refresh(_subject); + return _miner.statusDone(_status); + } + + // DKM: during folder rename we need to recursively update all the parent + // paths + private void updateChildProperties(DataElement subject, File filerename) { + + int nestedSize = subject.getNestedSize(); + for (int i = 0; i < nestedSize; i++) { + DataElement child = subject.get(i); + child.setAttribute(DE.A_VALUE, filerename.getAbsolutePath()); + + if (child.getNestedSize() > 0) { + File childFile = new File(filerename, child.getName()); + updateChildProperties(child, childFile); + } + } + } +} \ No newline at end of file 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 efa03ce934e..3181dab3265 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 @@ -31,6 +31,7 @@ * Kevin Doyle (IBM) - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND * David McKnight (IBM) - [196624] dstore miner IDs should be String constants rather than dynamic lookup * David McKnight (IBM) - [209704] added supportsEncodingConversion() + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations ********************************************************************************/ package org.eclipse.rse.internal.services.dstore.files; @@ -1272,6 +1273,13 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer DataElement status = dsStatusCommand(de, IUniversalDataStoreConstants.C_CREATE_FILE, monitor); if (status == null) return null; + + if (null != monitor && monitor.isCanceled()) + { + //This operation has been canceled by the user. + throw new SystemMessageException(getMessage("RSEG1067")); //$NON-NLS-1$ + } + if (FileSystemMessageUtil.getSourceMessage(status).equals(IServiceConstants.SUCCESS)) return new DStoreHostFile(de); else if (FileSystemMessageUtil.getSourceMessage(status).equals(IServiceConstants.FAILED_WITH_EXIST)) @@ -1296,6 +1304,13 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer DataElement status = dsStatusCommand(de, IUniversalDataStoreConstants.C_CREATE_FOLDER, monitor); if (status == null) return null; + + if (null != monitor && monitor.isCanceled()) + { + //This operation has been canceled by the user. + throw new SystemMessageException(getMessage("RSEG1067")); //$NON-NLS-1$ + } + if (FileSystemMessageUtil.getSourceMessage(status).equals(IServiceConstants.SUCCESS)) return new DStoreHostFile(de); else if(FileSystemMessageUtil.getSourceMessage(status).equals(IServiceConstants.FAILED_WITH_EXIST)) @@ -1319,6 +1334,11 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer DataElement de = getElementFor(remotePath); DataElement status = dsStatusCommand(de, IUniversalDataStoreConstants.C_DELETE, monitor); if (status == null) return false; + if (null != monitor && monitor.isCanceled()) + { + //This operation has been canceled by the user. + throw new SystemMessageException(getMessage("RSEG1067")); //$NON-NLS-1$ + } String sourceMsg = FileSystemMessageUtil.getSourceMessage(status); // 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 @@ -1342,6 +1362,11 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer } DataElement status = dsStatusCommand((DataElement) dataElements.get(0), dataElements, IUniversalDataStoreConstants.C_DELETE_BATCH, monitor); if (status == null) return false; + if (null != monitor && monitor.isCanceled()) + { + //This operation has been canceled by the user. + throw new SystemMessageException(getMessage("RSEG1067")); //$NON-NLS-1$ + } String sourceMsg = FileSystemMessageUtil.getSourceMessage(status); // 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 @@ -1373,6 +1398,11 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer DataElement status = dsStatusCommand(de, IUniversalDataStoreConstants.C_RENAME, monitor); if (status == null) return false; + if (null != monitor && monitor.isCanceled()) + { + //This operation has been canceled by the user. + throw new SystemMessageException(getMessage("RSEG1067")); //$NON-NLS-1$ + } if (FileSystemMessageUtil.getSourceMessage(status).equals(IServiceConstants.SUCCESS)) return true; else @@ -1391,11 +1421,30 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer protected boolean moveByCopy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException { + boolean movedOk = false; + if (copy(srcParent, srcName, tgtParent, tgtName, monitor)) - { - return delete(srcParent, srcName, monitor); - } - return false; + { + 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 canceled 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 @@ -1566,7 +1615,16 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer } catch (InterruptedException e) { -// UniversalSystemPlugin.logError(CLASSNAME + " InterruptedException while waiting for command", e); + if (monitor != null && monitor.isCanceled()) + { + //This operation has been canceled by the user. + throw new SystemMessageException(getMessage("RSEG1067")); //$NON-NLS-1$ + } + // cancel monitor if it's still not canceled + if (monitor != null && !monitor.isCanceled()) + { + monitor.setCanceled(true); + } } return true; } @@ -1606,7 +1664,19 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer } catch (InterruptedException e) { -// UniversalSystemPlugin.logError(CLASSNAME + " InterruptedException while waiting for command", e); + if (monitor != null && monitor.isCanceled()) + { + //This operation has been canceled by the user. + throw new SystemMessageException(getMessage("RSEG1067")); //$NON-NLS-1$ + } + // cancel monitor if it's still not canceled + if (monitor != null && !monitor.isCanceled()) + { + monitor.setCanceled(true); + } + + //InterruptedException is used to report user cancellation, so no need to log + //This should be reviewed (use OperationCanceledException) with bug #190750 } return true; } diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/VirtualChild.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/VirtualChild.java index c441968f5ef..52b128cf007 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/VirtualChild.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/VirtualChild.java @@ -14,6 +14,7 @@ * Contributors: * {Name} (company) - description of contribution. * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations *******************************************************************************/ package org.eclipse.rse.services.clientserver.archiveutils; @@ -161,7 +162,14 @@ public final class VirtualChild { */ public void setComment(String value) { - comment = value; + if (null != value) + { + comment = value; + } + else + { + comment = ""; //$NON-NLS-1$ + } } /** @@ -202,7 +210,14 @@ public final class VirtualChild { */ public void setCompressionMethod(String value) { - compressionMethod = value; + if (null != value) + { + compressionMethod = value; + } + else + { + compressionMethod = ""; //$NON-NLS-1$ + } } /** diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/SystemCommonDeleteAction.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/SystemCommonDeleteAction.java index 9008df9db2c..e73e530e58d 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/SystemCommonDeleteAction.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/SystemCommonDeleteAction.java @@ -15,9 +15,11 @@ * Kevin Doyle (IBM) - [188637] Handle the caught exception in DeleteJob.run when file fails to be deleted * Kevin Doyle (IBM) - [196582] ClassCastException when doing copy/paste with Remote Search view open * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations ********************************************************************************/ package org.eclipse.rse.internal.ui.actions; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Vector; @@ -51,7 +53,10 @@ import org.eclipse.rse.ui.model.SystemRemoteElementResourceSet; import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter; import org.eclipse.rse.ui.view.ISystemViewElementAdapter; import org.eclipse.rse.ui.view.SystemAdapterHelpers; +import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; @@ -116,7 +121,8 @@ public class SystemCommonDeleteAction { boolean ok = true; List localDeletedObjects = new Vector(); - List remoteDeletedObjects = new Vector(); + List remoteDeletedObjects = new Vector(); + HashMap objectsToDelete = new HashMap(); // local delete is pretty straight-forward for (int l = 0; l < _localResources.size() && ok; l++) @@ -145,17 +151,18 @@ public class SystemCommonDeleteAction ISystemViewElementAdapter adapter = set.getViewAdapter(); try { - ok = adapter.doDeleteBatch(getShell(), set.getResourceSet(), monitor); - if (ok) + for (int i = 0; i < set.size(); i++) { - for (int i = 0; i < set.size(); i++) - { - remoteDeletedObjects.add(set.get(i)); - } + Object thisObject = set.get(i); + String objectName = adapter.getName(thisObject); + objectsToDelete.put(thisObject, objectName); + remoteDeletedObjects.add(thisObject); } + ok = adapter.doDeleteBatch(getShell(), set.getResourceSet(), monitor); } catch (SystemMessageException e) { + remoteDeletedObjects.clear(); if (monitor.isCanceled() && set.size() > 1) { for (int i = 0; i < set.size(); i++) @@ -172,11 +179,14 @@ public class SystemCommonDeleteAction //Get the moved file names Object thisObject = remoteDeletedObjects.get(0); String deletedFileNames = null; - deletedFileNames = adapter.getName(thisObject); + //We could not use adapter.getName(thisObject) here since in dstore case, this name has + //already been changed to "deleted". So we need to remember the object and name map, and + //find the object name in the map here. + deletedFileNames = (String)objectsToDelete.get(thisObject); for (int i=1; i<(remoteDeletedObjects.size()); i++) { thisObject = remoteDeletedObjects.get(i); - deletedFileNames = deletedFileNames + "\n" + adapter.getName(thisObject); //$NON-NLS-1$ + deletedFileNames = deletedFileNames + "\n" + (String)objectsToDelete.get(thisObject); //$NON-NLS-1$ } SystemMessage thisMessage = RSEUIPlugin.getPluginMessage(ISystemMessages.FILEMSG_DELETE_INTERRUPTED); thisMessage.makeSubstitution(deletedFileNames);