mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-06 00:25:25 +02:00
[209827] fix: Update DStore command implementation to enable cancelation of archive operations
This commit is contained in:
parent
7d080e18cd
commit
9b89ffb3f8
13 changed files with 1680 additions and 927 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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$
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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$
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue