1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-18 13:45:45 +02:00

[199854][api] Improve error reporting for archive handlers

This commit is contained in:
Martin Oberhuber 2008-05-07 03:00:56 +00:00
parent 4d5ee26ab3
commit e869ef164d
18 changed files with 1663 additions and 1616 deletions

View file

@ -12,10 +12,11 @@
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Noriaki Takatsu (IBM) [220126] [dstore][api][breaking] Single process server for multiple clients
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
* Noriaki Takatsu (IBM) [229146] [multithread] changes to stop Miner threads when clients disconnect
* David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed
* Noriaki Takatsu (IBM) [220126] [dstore][api][breaking] Single process server for multiple clients
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
* Noriaki Takatsu (IBM) [229146] [multithread] changes to stop Miner threads when clients disconnect
* David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.dstore.core.miners;
@ -39,7 +40,7 @@ import org.eclipse.dstore.core.server.SystemServiceManager;
* The DataStore framework knows how to load and route commands to miners
* because it interfaces miners through the restricted set of interfaces declared here.
* To add a new miner, developers must extend this class and implement the abstract methods declared here.
*
*
* @noinstantiate This class is not intended to be instantiated by clients. The dstore server infrastructure
* will take care of loading the Miner.
*/
@ -681,7 +682,7 @@ implements ISchemaExtender
*
* @param theCommand an instance of a command containing a tree of arguments
*/
public abstract DataElement handleCommand(DataElement theCommand);
public abstract DataElement handleCommand(DataElement theCommand) throws Exception;
/**

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 IBM Corporation and others.
* Copyright (c) 2006, 2008 IBM Corporation and others.
* 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
@ -7,13 +7,14 @@
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
*
* Contributors:
* {Name} (company) - description of contribution.
* Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.dstore.universal.miners;
@ -43,7 +44,7 @@ import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild;
*/
public class UniversalByteStreamHandler extends ByteStreamHandler
{
public UniversalByteStreamHandler(DataStore dataStore, DataElement log)
{
super(dataStore, log);
@ -53,7 +54,7 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
/**
* Save a file in the specified location. This method is called by the
* DataStore when the communication layer receives a file transfer
* DataStore when the communication layer receives a file transfer
*
* @param remotePath the path where to save the file
* @param buffer the bytes to insert in the file
@ -63,7 +64,7 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
public void receiveBytes(String remotePath, byte[] buffer, int size, boolean binary)
{
boolean isVirtual = ArchiveHandlerManager.isVirtual(remotePath);
if (!isVirtual)
{
super.receiveBytes(remotePath, buffer, size, binary);
@ -79,11 +80,11 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
String virtualFileName = fileName;
ArchiveHandlerManager mgr = ArchiveHandlerManager.getInstance();
VirtualChild child = mgr.getVirtualObject(virtualFileName);
ISystemArchiveHandler handler = child.getHandler();
try
{
VirtualChild child = mgr.getVirtualObject(virtualFileName);
ISystemArchiveHandler handler = child.getHandler();
File file = child.getExtractedFile();
fileName = file.getAbsolutePath();
@ -128,20 +129,12 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
String filePath = virtualFileName.substring(0, virtualIndex);
handler = mgr.getRegisteredHandler(new File(filePath));
}
boolean success = handler != null && handler.add(newFile, child.path, child.name, null);
if (!success)
{
if (status == null) return;
status.setAttribute(DE.A_VALUE, IClientServerConstants.FILEMSG_REMOTE_SAVE_FAILED);
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
_dataStore.refresh(status.getParent());
}
else
{
if (status == null) return;
status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
_dataStore.refresh(status.getParent());
}
if (handler != null)
handler.add(newFile, child.path, child.name, null);
if (status == null)
return;
status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
_dataStore.refresh(status.getParent());
}
catch (IOException e)
{
@ -164,7 +157,7 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
/**
* Append a bytes to a file at a specified location. This method is called by the
* DataStore when the communication layer receives a file transfer append.
* DataStore when the communication layer receives a file transfer append.
*
* @param remotePath the path where to save the file
* @param buffer the bytes to append in the file
@ -173,7 +166,7 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
*/
public void receiveAppendedBytes(String remotePath, byte[] buffer, int size, boolean binary)
{
boolean isVirtual = ArchiveHandlerManager.isVirtual(remotePath);
if (!isVirtual)
{
@ -188,20 +181,15 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
if (fileName != null)
{
String virtualFileName = fileName;
ArchiveHandlerManager mgr = ArchiveHandlerManager.getInstance();
VirtualChild child = mgr.getVirtualObject(virtualFileName);
if (!child.exists())
{
//System.out.println(virtualFileName + " does not exist.");
return;
}
ISystemArchiveHandler handler = child.getHandler();
try
{
boolean success;
ArchiveHandlerManager mgr = ArchiveHandlerManager.getInstance();
VirtualChild child = mgr.getVirtualObject(virtualFileName);
if (!child.exists()) {
// System.out.println(virtualFileName + " does not exist.");
return;
}
ISystemArchiveHandler handler = child.getHandler();
File file = child.getExtractedFile();
fileName = file.getAbsolutePath();
@ -242,7 +230,9 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
String filePath = virtualFileName.substring(0, virtualIndex);
handler = mgr.getRegisteredHandler(new File(filePath));
}
success = handler != null && handler.add(newFile, child.path, child.name, null);
if (handler != null) {
handler.add(newFile, child.path, child.name, null);
}
}
else
@ -308,7 +298,7 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
// remote old file
oldFile.delete();
// rename new file
// rename new file
newFile.renameTo(oldFile);
// write the temp file to the archive
@ -318,25 +308,17 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
String filePath = virtualFileName.substring(0, virtualIndex);
handler = mgr.getRegisteredHandler(new File(filePath));
}
success = handler != null && handler.add(newFile, child.path, child.name, null);
if (handler != null) {
handler.add(newFile, child.path, child.name, null);
}
}
}
if (!success)
{
if (status == null) return;
status.setAttribute(DE.A_VALUE, IClientServerConstants.FILEMSG_REMOTE_SAVE_FAILED);
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
_dataStore.refresh(status.getParent());
}
else
{
if (status == null) return;
status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
_dataStore.refresh(status.getParent());
}
if (status == null)
return;
status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
_dataStore.refresh(status.getParent());
}
catch (IOException e)
catch (Exception e)
{
_dataStore.trace(e);
if (status == null) return;

View file

@ -8,10 +8,11 @@
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight.
*
*
* Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
@ -28,52 +29,52 @@ 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;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
public class CopyBatchThread extends CopyThread {
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()
{
super.run();
handleCopyBatch();
try {
handleCopyBatch();
} catch (SystemMessageException e) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
miner.statusDone(status);
}
_isDone = true;
}
private DataElement handleCopyBatch()
private DataElement handleCopyBatch() throws SystemMessageException
{
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 (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))
if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR))
{
virtualContainer = vpath.getVirtualPart();
}
for (int i = 0; i < numOfSources; i++)
{
if (isCancelled())
@ -86,21 +87,21 @@ public class CopyBatchThread extends CopyThread {
File srcFile;
if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR)
|| srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_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))
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)
if (shandler == null)
{
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
return miner.statusDone(status);
}
VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart(), systemOperationMonitor);
srcFile = child.getExtractedFile();
}
@ -109,15 +110,16 @@ public class CopyBatchThread extends CopyThread {
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
//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) {
try {
handler.add(srcFile, virtualContainer, srcName, systemOperationMonitor);
} catch (SystemMessageException e) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
if (isCancelled())
{
@ -127,6 +129,7 @@ public class CopyBatchThread extends CopyThread {
{
return miner.statusDone(status);
}
}
}
else
@ -135,15 +138,19 @@ public class CopyBatchThread extends CopyThread {
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);
try {
handler.add(resultFiles, virtualContainer, resultNames, systemOperationMonitor);
} catch (SystemMessageException e) {
result = false;
}
}
if (result)
{
status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
@ -176,42 +183,38 @@ public class CopyBatchThread extends CopyThread {
}
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))
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)
{
try {
AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile);
ISystemArchiveHandler shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString());
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);
}
} catch (SystemMessageException e) {
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
// 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)
@ -234,13 +237,13 @@ public class CopyBatchThread extends CopyThread {
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())
{
@ -251,7 +254,7 @@ public class CopyBatchThread extends CopyThread {
return miner.statusDone(status);
}
}
}

View file

@ -8,10 +8,11 @@
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight.
*
*
* Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
@ -27,32 +28,38 @@ 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;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
public class CopySingleThread extends CopyThread {
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()
{
super.run();
handleCopy();
try {
handleCopy();
} catch (SystemMessageException e) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
miner.statusDone(status);
}
_isDone = true;
}
private DataElement handleCopy()
private DataElement handleCopy() throws SystemMessageException
{
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
//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;
@ -64,25 +71,25 @@ public class CopySingleThread extends CopyThread {
{
String goodFullName = ArchiveHandlerManager.cleanUpVirtualPath(sourceFile.getValue());
child = ArchiveHandlerManager.getInstance().getVirtualObject(goodFullName);
if (child.exists())
if (child.exists())
{
if (child.isDirectory)
if (child.isDirectory)
{
srcType = IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR;
} else
} 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);
@ -90,7 +97,7 @@ public class CopySingleThread extends CopyThread {
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)) {
@ -99,7 +106,7 @@ public class CopySingleThread extends CopyThread {
{
AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile);
shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString());
if (shandler == null) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
return miner.statusDone(status);
@ -115,19 +122,12 @@ public class CopySingleThread extends CopyThread {
}
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);
}
handler.add(srcFile, virtualContainer, newName, systemOperationMonitor);
}
else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) {
ISystemArchiveHandler shandler = null;
@ -136,7 +136,7 @@ public class CopySingleThread extends CopyThread {
{
svpath = miner.getAbsoluteVirtualPath(sourceFile);
shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString());
if (shandler == null) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
return miner.statusDone(status);
@ -152,7 +152,7 @@ public class CopySingleThread extends CopyThread {
File parentDir = getFileFor(targetFolder);
File destination = new File(parentDir, newName);
if (child.isDirectory) {
shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination, systemOperationMonitor);
}
@ -169,7 +169,7 @@ public class CopySingleThread extends CopyThread {
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
@ -179,13 +179,13 @@ public class CopySingleThread extends CopyThread {
tgt = tgtFolder.getAbsolutePath();
}
}
doCopyCommand(enQuote(src), enQuote(tgt), folderCopy, status);
}
return miner.statusDone(status);
}
}

View file

@ -8,10 +8,11 @@
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight.
*
*
* Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
@ -20,6 +21,7 @@ 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.dstore.core.server.SecuredThread;
import org.eclipse.rse.dstore.universal.miners.ICancellableHandler;
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner;
@ -29,7 +31,7 @@ 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.dstore.core.server.SecuredThread;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
public class CreateFileThread extends SecuredThread implements ICancellableHandler {
@ -37,14 +39,14 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl
protected DataElement _status;
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)
{
super(dataStore);
@ -53,9 +55,9 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl
this._status = status;
this._queryType = queryType;
}
public void cancel() {
_isCancelled = true;
@ -72,16 +74,20 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl
public boolean isDone() {
return _isDone;
}
public void run()
{
super.run();
handleCreateFile();
try {
handleCreateFile();
} catch (SystemMessageException e) {
_status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
_miner.statusDone(_status);
}
_isDone = true;
}
private DataElement handleCreateFile()
private DataElement handleCreateFile() throws SystemMessageException
{
boolean wasFilter = _queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR);
if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) {
@ -115,11 +121,9 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl
try {
boolean done = filename.createNewFile();
if (ArchiveHandlerManager.getInstance().isArchive(filename)) {
done = ArchiveHandlerManager.getInstance()
ArchiveHandlerManager.getInstance()
.createEmptyArchive(filename);
if (done)
_subject.setAttribute(DE.A_TYPE,
IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR);
_subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR);
} else {
if (done)
{
@ -152,9 +156,9 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl
_dataStore.refresh(_subject);
return _miner.statusDone(_status);
}
public DataElement handleCreateVirtualFile(DataElement subject,
DataElement status, String type) {
DataElement status, String type) throws SystemMessageException {
AbsoluteVirtualPath vpath = null;
if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) {

View file

@ -8,10 +8,11 @@
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight.
*
*
* Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
@ -20,6 +21,7 @@ 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.dstore.core.server.SecuredThread;
import org.eclipse.rse.dstore.universal.miners.ICancellableHandler;
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner;
@ -29,7 +31,7 @@ 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.dstore.core.server.SecuredThread;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
public class CreateFolderThread extends SecuredThread implements ICancellableHandler {
@ -37,14 +39,14 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan
protected DataElement _status;
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)
{
super(dataStore);
@ -53,9 +55,9 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan
this._status = status;
this._queryType = queryType;
}
public void cancel() {
_isCancelled = true;
@ -72,37 +74,42 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan
public boolean isDone() {
return _isDone;
}
public void run()
{
super.run();
handleCreateFile();
try {
handleCreateFile();
} catch (SystemMessageException e) {
_status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
_miner.statusDone(_status);
}
_isDone = true;
}
private DataElement handleCreateFile()
private DataElement handleCreateFile() throws SystemMessageException
{
if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) {
return handleCreateVirtualFolder(_subject, _status, _queryType);
}
File filename = null;
if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR))
if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR))
{
if (_subject.getName().indexOf(
ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0)
ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0)
{
_subject.setAttribute(DE.A_TYPE,
IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR);
return handleCreateVirtualFolder(_subject, _status, _queryType);
}
else
}
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());
@ -115,23 +122,23 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan
{
if (filename.exists())
_status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXIST);
else
else
{
try {
boolean done = filename.mkdirs();
if (done)
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, _dataStore); //$NON-NLS-1$
@ -142,9 +149,9 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan
_dataStore.refresh(_subject);
return _miner.statusDone(_status);
}
public DataElement handleCreateVirtualFolder(DataElement subject,
DataElement status, String type) {
DataElement status, String type) throws SystemMessageException {
AbsoluteVirtualPath vpath = null;
if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) {

View file

@ -8,10 +8,11 @@
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight.
*
*
* Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
@ -20,6 +21,7 @@ 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.dstore.core.server.SecuredThread;
import org.eclipse.rse.dstore.universal.miners.ICancellableHandler;
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner;
@ -29,7 +31,7 @@ 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.dstore.core.server.SecuredThread;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
public class DeleteThread extends SecuredThread implements ICancellableHandler {
@ -37,14 +39,14 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
protected DataElement _status;
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)
{
super(dataStore);
@ -53,9 +55,9 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
this._status = status;
this._batch = batch;
}
public void cancel() {
_isCancelled = true;
@ -72,22 +74,24 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
public boolean isDone() {
return _isDone;
}
public void run()
{
super.run();
if (_batch)
{
handleDeleteBatch();
}
else
{
handleDelete(_theElement, _status);
try {
if (_batch) {
handleDeleteBatch();
} else {
handleDelete(_theElement, _status);
}
} catch (SystemMessageException e) {
_status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
_miner.statusDone(_status);
}
_isDone = true;
}
private DataElement handleDeleteBatch()
private DataElement handleDeleteBatch() throws SystemMessageException
{
DataElement substatus = _dataStore.createObject(null, "status", "substatus"); //$NON-NLS-1$ //$NON-NLS-2$
int numOfSources = _theElement.getNestedSize() - 2;
@ -100,7 +104,7 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
DataElement subject = _miner.getCommandArgument(_theElement, i+1);
handleDelete(subject, substatus);
/*
if (!substatus.getSource().startsWith(IServiceConstants.SUCCESS))
if (!substatus.getSource().startsWith(IServiceConstants.SUCCESS))
{
status.setAttribute(DE.A_SOURCE, substatus.getSource());
return statusDone(status);
@ -110,7 +114,7 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
_status.setAttribute(DE.A_SOURCE, substatus.getSource());
return _miner.statusDone(_status);
}
private DataElement handleDelete(DataElement subject, DataElement thisStatus)
private DataElement handleDelete(DataElement subject, DataElement thisStatus) throws SystemMessageException
{
String type = subject.getType();
@ -172,11 +176,11 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
}
_dataStore.refresh(subject);
return _miner.statusDone(_status);
}
public DataElement handleDeleteFromArchive(DataElement subject,
DataElement status) {
DataElement status) throws SystemMessageException {
String type = subject.getType();
DataElement deObj = null;
@ -207,10 +211,10 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
_dataStore.refresh(subject);
return _miner.statusDone(status);
}
/**
* Delete directory and its children.
*
*
*/
public void deleteDir(File fileObj, DataElement status) {
try {
@ -238,5 +242,5 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
"Deletion of dir failed", e, _dataStore); //$NON-NLS-1$
}
}
}

View file

@ -7,15 +7,16 @@
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
*
* Contributors:
* Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name
* Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name
* Martin Oberhuber (Wind River) - [186640] Fix case sensitive issue comparing z/OS
* Xuan Chen (IBM) - [191280] [dstore] Expand fails for folder "/folk" with 3361 children
* Xuan Chen (IBM) - [191280] [dstore] Expand fails for folder "/folk" with 3361 children
* Xuan Chen (IBM) - [215863]] NPE when Expanding Empty Zip File
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
@ -82,10 +83,10 @@ public class FileClassifier extends Thread
}
public static final String symbolicLinkStr = "symbolic link to"; //$NON-NLS-1$
public static final String fileSep = System.getProperty("file.separator"); //$NON-NLS-1$
public static final String defaultType = "file"; //$NON-NLS-1$
public static final String STR_SYMBOLIC_LINK = "symbolic link"; //$NON-NLS-1$
public static final String STR_SHARED_OBJECT="shared object"; //$NON-NLS-1$
public static final String STR_OBJECT_MODULE="object module"; //$NON-NLS-1$
@ -100,7 +101,7 @@ public class FileClassifier extends Thread
public static final String STR_DOT_SO_DOT=".so."; //$NON-NLS-1$
public static final String STR_DIRECTORY="diectory"; //$NON-NLS-1$
private DataElement _subject;
private DataStore _dataStore;
@ -112,7 +113,7 @@ public class FileClassifier extends Thread
private List _fileMap;
private boolean _classifyChildren = true;
private boolean _classifyFilter = false;
private boolean _canResolveLinks = false;
@ -120,9 +121,9 @@ public class FileClassifier extends Thread
private boolean _classifyVirtual = false;
private boolean _systemSupportsClassify = true;
private boolean _systemSupportsClassFilesOnly = false;
private List _lines;
public FileClassifier(DataElement subject)
@ -144,7 +145,7 @@ public class FileClassifier extends Thread
else if (osName.equals("z/os")) { //$NON-NLS-1$
_systemSupportsClassFilesOnly = true;
}
_systemShell = "sh"; //$NON-NLS-1$
_canResolveLinks = osName.startsWith("linux"); //$NON-NLS-1$
@ -165,7 +166,7 @@ public class FileClassifier extends Thread
{
_classifyVirtual = false;
}
_classifyFilter = objType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR);
// if the subject is a file or a virtual file (i.e. not a directory or
@ -221,7 +222,7 @@ public class FileClassifier extends Thread
/**
* Gets the data element for the given name from the name to data element
* mapping.
*
*
* @param name
* the name.
* @return the data element corresponding to that name.
@ -274,12 +275,12 @@ public class FileClassifier extends Thread
{
filePath = _subject.getValue();
}
// if we have to classify children
if (_classifyChildren)
{
// if it's not a classification of virtual files
if (!_classifyVirtual)
@ -315,7 +316,7 @@ public class FileClassifier extends Thread
classifiedProperties.append(type);
classifiedProperties.append(')');
_subject.setAttribute(DE.A_SOURCE, classifiedProperties.toString());
}
catch (Exception e)
{
@ -328,7 +329,7 @@ public class FileClassifier extends Thread
/**
* Classifies from the given line of classification output.
*
*
* @param parentFile the parent file.
* @param line the line of output to parse.
* @param specialEncoding a special encoding, if there is one.
@ -339,7 +340,7 @@ public class FileClassifier extends Thread
{
// this string should be contained in an output line that indicates a
// symbolic link
// default type
String type = defaultType;
@ -361,7 +362,7 @@ public class FileClassifier extends Thread
String parentPath = parentFile.getAbsolutePath();
// get file separator
// if parent path does not end with separator, then add it
if (!parentPath.endsWith(fileSep))
@ -416,18 +417,18 @@ public class FileClassifier extends Thread
}
return type;
}
// if the system supports only classifying *.class files, then return generic type "file".
if (_systemSupportsClassFilesOnly) {
return type;
}
/* DKM - let the client have the raw type instead of doing this for it
*
*
boolean matchesLib = (fulltype.indexOf(STR_SHARED_OBJECT) > -1) || (fulltype.indexOf(STR_OBJECT_MODULE) > -1) || (fulltype.indexOf(STR_ARCHIVE) > -1);
boolean matchesExe = (fulltype.indexOf(STR_EXECUTABLE) > -1);
boolean matchesScript = (fulltype.indexOf(STR_SCRIPT) > -1);
// shared
if (matchesLib && (name.endsWith(STR_DOT_A) || name.endsWith(STR_DOT_SO) || name.indexOf(STR_DOT_SO_DOT) > 0))
{
@ -529,7 +530,7 @@ public class FileClassifier extends Thread
/**
* Classify a file. It classifies the file by running "sh -c file
* <filename>".
*
*
* @param aFile the file to classify.
* @return the classification.
*/
@ -597,8 +598,8 @@ public class FileClassifier extends Thread
{
encoding = System.getProperty("file.encoding"); //$NON-NLS-1$
}
try
{
byte[] readBytes = new byte[1024];
@ -615,14 +616,14 @@ public class FileClassifier extends Thread
{
return _lines;
}
// get the output using the encoding
try
{
String fullOutput = new String(readBytes, 0, numRead, encoding);
// if output is not null, we assume the encoding was correct and
// process the output
// tokenize the output so that we can get each line of
@ -636,7 +637,7 @@ public class FileClassifier extends Thread
String lastLine = (String)_lines.remove(_lines.size() -1);
tokens[0] = lastLine + tokens[0];
}
for (int i = 0; i< tokens.length; i++)
{
_lines.add(tokens[i]);
@ -647,23 +648,23 @@ public class FileClassifier extends Thread
{
e.printStackTrace();
}
available = stream.available();
available = stream.available();
}
}
catch (Exception e)
{
e.printStackTrace();
}
return _lines;
}
protected String readLine(DataInputStream stream, String encoding) throws Exception
{
if (_lines.size() == 0)
{
_lines = readLines(stream, encoding);
_lines = readLines(stream, encoding);
}
if (_lines == null)
{
@ -678,7 +679,7 @@ public class FileClassifier extends Thread
/**
* Classifies the children of a given file.
*
*
* @param parentFile the parent file.
* @param files the files to classify. Specify "*" to classify all files.
* @param resolveLinks resolve links if possible.
@ -864,7 +865,7 @@ public class FileClassifier extends Thread
if (linkIndex != -1)
{
int cutOffIndex = linkIndex + textToCheck.length();
StringBuffer typeBuf = new StringBuffer();
typeBuf.append('(');
typeBuf.append(type);
@ -941,8 +942,8 @@ public class FileClassifier extends Thread
/**
* Classify virtual children.
*
* @param parentPath the full path of the parent file.
*
* @param parentPath the full path of the parent file.
* The path could represent an archive or a virtual folder.
*/
protected void classifyVirtualChildren(String parentPath)
@ -1035,14 +1036,14 @@ public class FileClassifier extends Thread
StringBuffer currentProperties = new StringBuffer(element.getAttribute(DE.A_SOURCE));
currentProperties.append('|');
currentProperties.append(type);
element.setAttribute(DE.A_SOURCE, currentProperties.toString());
}
}
}
}
}
catch (IOException e)
catch (Exception e)
{
// TODO: log error
}

View file

@ -8,9 +8,10 @@
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight.
*
*
* Contributors:
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
@ -24,22 +25,23 @@ import org.eclipse.rse.dstore.universal.miners.ICancellableHandler;
import org.eclipse.rse.services.clientserver.IServiceConstants;
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
public class QueryThread extends SecuredThread implements ICancellableHandler {
protected DataElement _subject;
protected DataElement _status;
protected boolean _isCancelled = false;
protected boolean _isDone = false;
public QueryThread(DataElement subject, DataElement status)
{
super(subject.getDataStore());
_subject = subject;
_status = status;
}
/**
* Complete status.
*/
@ -48,7 +50,7 @@ public class QueryThread extends SecuredThread implements ICancellableHandler {
_dataStore.refresh(status);
return status;
}
public void cancel() {
_isCancelled = true;
@ -61,7 +63,7 @@ public class QueryThread extends SecuredThread implements ICancellableHandler {
public boolean isDone() {
return _isDone;
}
public String setProperties(File fileObj) {
return setProperties(fileObj, false);
@ -82,14 +84,18 @@ public class QueryThread extends SecuredThread implements ICancellableHandler {
// These extra properties here might cause problems for older clients,
// ie: a IndexOutOfBounds in UniversalFileImpl.
// DKM: defer this until later as it is bad for performacnes..
// DKM: defer this until later as it is bad for performance...
// I think we're doing the full query on an archive by instantiating a
// handler
boolean isArchive = false;//ArchiveHandlerManager.getInstance().isArchive(fileObj);
String comment;
if (isArchive)
comment = ArchiveHandlerManager.getInstance().getComment(fileObj);
try {
comment = ArchiveHandlerManager.getInstance().getComment(fileObj);
} catch (SystemMessageException e) {
comment = " "; //$NON-NLS-1$
}
else
comment = " "; //$NON-NLS-1$
@ -99,8 +105,11 @@ public class QueryThread extends SecuredThread implements ICancellableHandler {
long expandedSize;
if (isArchive)
expandedSize = ArchiveHandlerManager.getInstance().getExpandedSize(
fileObj);
try {
expandedSize = ArchiveHandlerManager.getInstance().getExpandedSize(fileObj);
} catch (SystemMessageException e) {
expandedSize = 0;
}
else
expandedSize = size;
@ -117,7 +126,7 @@ public class QueryThread extends SecuredThread implements ICancellableHandler {
IServiceConstants.TOKEN_SEPARATOR);
buffer.append(compressionRatio).append(IServiceConstants.TOKEN_SEPARATOR).append(
expandedSize);
String buf = buffer.toString();
return buf;

View file

@ -8,10 +8,11 @@
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight.
*
*
* Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
@ -20,6 +21,7 @@ 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.dstore.core.server.SecuredThread;
import org.eclipse.rse.dstore.universal.miners.ICancellableHandler;
import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner;
import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities;
@ -28,21 +30,21 @@ 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.dstore.core.server.SecuredThread;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
public class RenameThread extends SecuredThread implements ICancellableHandler {
protected DataElement _subject;
protected DataElement _status;
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)
{
super(dataStore);
@ -50,8 +52,8 @@ public class RenameThread extends SecuredThread implements ICancellableHandler {
this._miner = miner;
this._status = status;
}
public void cancel() {
_isCancelled = true;
@ -68,15 +70,20 @@ public class RenameThread extends SecuredThread implements ICancellableHandler {
public boolean isDone() {
return _isDone;
}
public void run()
{
super.run();
handleRename();
try {
handleRename();
} catch (SystemMessageException e) {
_status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
_miner.statusDone(_status);
}
_isDone = true;
}
private DataElement handleRename()
private DataElement handleRename() throws SystemMessageException
{
File fileoldname = new File(_subject.getAttribute(DE.A_VALUE)
+ File.separatorChar + _subject.getName());
@ -91,16 +98,14 @@ public class RenameThread extends SecuredThread implements ICancellableHandler {
ISystemArchiveHandler handler = archiveHandlerManager
.getRegisteredHandler(new File(oldAbsPath
.getContainingArchiveString()));
boolean success = !(handler == null)
&& handler.fullRename(oldAbsPath.getVirtualPart(),
newAbsPath.getVirtualPart(), systemOperationMonitor);
if (success && handler != null) {
if (handler != null) {
handler.fullRename(oldAbsPath.getVirtualPart(), newAbsPath.getVirtualPart(), systemOperationMonitor);
_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.isCancelled())
{
_subject.setAttribute(DE.A_SOURCE, _miner.setProperties(handler
@ -140,7 +145,7 @@ public class RenameThread extends SecuredThread implements ICancellableHandler {
_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) {

View file

@ -7,16 +7,17 @@
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
*
* Contributors:
* Michael Berger (IBM) - Bug 147791 - symbolic links can cause circular search.
* David McKnight (IBM) - [190010] cancelling search
* Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread
* David McKnight (IBM) - [214378] canonical path not required - problem is in the client
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
@ -31,6 +32,7 @@ import java.util.HashSet;
import org.eclipse.dstore.core.model.DE;
import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.dstore.core.model.DataStore;
import org.eclipse.dstore.core.server.SecuredThread;
import org.eclipse.dstore.core.util.StringCompare;
import org.eclipse.rse.dstore.universal.miners.ICancellableHandler;
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
@ -41,11 +43,11 @@ import org.eclipse.rse.services.clientserver.SystemSearchString;
import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath;
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.services.clientserver.search.SystemSearchFileNameMatcher;
import org.eclipse.rse.services.clientserver.search.SystemSearchLineMatch;
import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatchLocator;
import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher;
import org.eclipse.dstore.core.server.SecuredThread;
public class UniversalSearchHandler extends SecuredThread implements ICancellableHandler
{
@ -59,19 +61,19 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
protected UniversalFileSystemMiner _miner;
protected DataElement _status;
protected SystemSearchString _searchString;
protected SystemSearchStringMatcher _stringMatcher;
protected boolean _isFileSearch;
protected SystemSearchFileNameMatcher _fileNameMatcher;
protected String _classificationString;
protected DataElement _deGrep;
protected DataElement _deFile;
protected DataElement _deFolder;
protected DataElement _deArchiveFile;
protected DataElement _deVirtualFile;
protected boolean _fsCaseSensitive;
public UniversalSearchHandler(DataStore dataStore, UniversalFileSystemMiner miner, SystemSearchString searchString, boolean fsCaseSensitive, File theFile, DataElement status) {
@ -80,35 +82,35 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
_searchString = searchString;
_fsCaseSensitive = fsCaseSensitive;
_alreadySearched = new HashSet();
_deGrep = _dataStore.findObjectDescriptor("grep"); //$NON-NLS-1$
_deFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR);
_deFolder = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR);
_deArchiveFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR);
_deVirtualFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR);
boolean includeSubfolders = searchString.isIncludeSubfolders();
if (includeSubfolders) {
_depth = -1;
}
else {
_depth = 1;
}
_rootFile = theFile;
_status = status;
_isCancelled = false;
_isDone = false;
_stringMatcher = new SystemSearchStringMatcher(_searchString.getTextString(), _searchString.isCaseSensitive(), _searchString.isTextStringRegex());
// if the search string is empty or if it is an asterisk, then we are doing a file search
// i.e. we do not want to look inside files
_isFileSearch = _stringMatcher.isSearchStringEmpty() || _stringMatcher.isSearchStringAsterisk();
_fileNameMatcher = new SystemSearchFileNameMatcher(_searchString.getFileNamesString(), fsCaseSensitive, _searchString.isFileNamesRegex());
// classification of files to restrict the search to
_classificationString = _searchString.getClassificationString();
}
@ -123,7 +125,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
}
_isDone = true;
if (_isCancelled) {
_miner.statusCancelled(_status);
@ -134,10 +136,10 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
// Otherwise we don't get an event on the client corresponding
// to status refresh. As a result client thinks
// search isn't finished.
// _miner.statusDone(_status);
// _miner.statusDone(_status);
_status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$
_dataStore.refresh(_status, true); // true indicates refresh immediately
}
}
@ -150,10 +152,10 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
}
public void cancel() {
_isCancelled = true;
_isCancelled = true;
}
protected boolean hasSearchedDirectory(File file)
protected boolean hasSearchedDirectory(File file)
{
try
{
@ -166,25 +168,25 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
}
}
protected void internalSearch(File theFile, int depth) {
protected void internalSearch(File theFile, int depth) throws SystemMessageException {
// is it a directory?
boolean isDirectory = theFile.isDirectory();
// is it an archive?
boolean isArchive = ArchiveHandlerManager.getInstance().isArchive(theFile);
String absPath = theFile.getAbsolutePath();
String compareStr = theFile.getName();
// is it a virtual file?
boolean isVirtual = ArchiveHandlerManager.isVirtual(absPath);
// is it a virtual directory?
boolean isVirtualDirectory = false;
// if it is a virtual object, then get a reference to it
if (isVirtual) {
VirtualChild vc = ArchiveHandlerManager.getInstance().getVirtualObject(absPath);
@ -194,38 +196,38 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
// base case for the recursive method call
// if the file is not a directory, an archive or a virtual directory,
// and we get a match with the file name, then we can search for match within the file
if (!isDirectory &&
(!isArchive || _isFileSearch) &&
if (!isDirectory &&
(!isArchive || _isFileSearch) &&
!isVirtualDirectory &&
doesFilePatternMatch(compareStr) &&
doesClassificationMatch(absPath))
doesFilePatternMatch(compareStr) &&
doesClassificationMatch(absPath))
{
DataElement deObj = null;
// if the file is a virtual file, then get matches from the archive handler
if (ArchiveHandlerManager.isVirtual(absPath)) {
VirtualChild vc = ArchiveHandlerManager.getInstance().getVirtualObject(absPath);
if (!vc.isDirectory) {
deObj = _dataStore.createObject(null, _deVirtualFile, compareStr);
// if parent of virtual child is archive, then create it this way
if (vc.path.equals("")) { //$NON-NLS-1$
deObj.setAttribute(DE.A_VALUE, vc.getContainingArchive().getAbsolutePath());
deObj.setAttribute(DE.A_VALUE, vc.getContainingArchive().getAbsolutePath());
}
else {
deObj.setAttribute(DE.A_VALUE, vc.getContainingArchive().getAbsolutePath() +
ArchiveHandlerManager.VIRTUAL_SEPARATOR + vc.path);
}
deObj.setAttribute(DE.A_SOURCE, _miner.setProperties(vc));
SystemSearchLineMatch[] results = null;
// if it's not a file search, call the handler method to search
if (!_isFileSearch) {
results = vc.getHandler().search(vc.fullName, _stringMatcher, null);
// if at least one match found, then send back the remote file with matches
if (results != null && results.length > 0) {
convert(deObj, absPath, results);
@ -236,7 +238,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
// otherwise if it is a file search, return the remote file back with no children
else {
deObj.setParent(_status);
_status.addNestedData(deObj, false);
_status.addNestedData(deObj, false);
}
}
}
@ -248,10 +250,10 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
else {
deObj = _dataStore.createObject(null, _deArchiveFile, compareStr);
}
deObj.setAttribute(DE.A_VALUE, theFile.getParentFile().getAbsolutePath());
deObj.setAttribute(DE.A_SOURCE, _miner.setProperties(theFile));
// if it is a file search, we send the remote file back
// otherwise search within the file and see if there is at least one match
if (_isFileSearch || internalSearchWithinFile(deObj, absPath, theFile)) {
@ -259,21 +261,21 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
_status.addNestedData(deObj, false);
}
}
// do a refresh
//_dataStore.refresh(_status, true);
}
// if the depth is not 0, then we need to recursively search
if (depth != 0) {
// if it is a directory, or an archive, or a virtual directory, then we need to get the
// children and search those
if (isDirectory || ((isArchive || isVirtualDirectory) && _searchString.isIncludeArchives()))
{
if (!hasSearchedDirectory(theFile)) {
try
{
_alreadySearched.add(theFile.getCanonicalFile());
@ -285,34 +287,34 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
}
File[] children = null;
// if the file is an archive or a virtual directory, then get the children from
// the archive handler
if (isArchive || isVirtualDirectory) {
AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absPath);
File archive = new File(avp.getContainingArchiveString());
String virtualPath = avp.getVirtualPart();
VirtualChild[] virtualchildren = null;
try {
virtualchildren = ArchiveHandlerManager.getInstance().getContents(archive, virtualPath);
}
catch (IOException e) {
catch (Exception e) {
UniversalServerUtilities.logError(_miner.getName(), "Error occured trying to get the canonical file", e, _dataStore); //$NON-NLS-1$
}
if (virtualchildren != null) {
children = new File[virtualchildren.length];
for (int i = 0; i < virtualchildren.length; i++) {
AbsoluteVirtualPath newAvp = new AbsoluteVirtualPath(absPath);
newAvp.setVirtualPart(virtualchildren[i].fullName);
children[i] = new File(newAvp.toString());
}
if (virtualchildren.length == 0) {
children = null;
}
@ -322,11 +324,11 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
else {
children = theFile.listFiles();
}
if (children != null) {
for (int i = 0; i < children.length && !_isCancelled; i++) {
File child = children[i];
internalSearch(child, depth - 1);
}
@ -341,24 +343,24 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
if (_isFileSearch) {
return true;
}
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(theFile);
InputStreamReader reader = new InputStreamReader(inputStream);
BufferedReader bufReader = new BufferedReader(reader);
SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, _stringMatcher);
SystemSearchLineMatch[] matches = locator.locateMatches();
boolean foundMatches = ((matches != null) && (matches.length > 0));
if (foundMatches) {
convert(remoteFile, absPath, matches);
}
return foundMatches;
}
catch (Exception e) {
@ -371,14 +373,14 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
protected boolean doesFilePatternMatch(String compareStr) {
return _fileNameMatcher.matches(compareStr);
}
/**
* Returns whether classification matches.
* @param absolutePath the absolute path of the file for which we want to check classification.
* @return <code>true</code> if the classification matches, <code>false</code> otherwise.
*/
protected boolean doesClassificationMatch(String absolutePath) {
if (_classificationString == null || _classificationString.equals("")) { //$NON-NLS-1$
return true;
}
@ -387,7 +389,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
return StringCompare.compare(_classificationString, classification, true);
}
}
/**
* Converts from system line matches to data elements that will be sent back.
* @param deObj the element representing the file for which matches have been found.
@ -395,9 +397,9 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
* @param lineMatches an array of line matches, or empty if no matches.
*/
protected void convert(DataElement deObj, String absPath, SystemSearchLineMatch[] lineMatches) {
SystemSearchLineMatch match = null;
for (int i = 0; i < lineMatches.length; i++) {
match = lineMatches[i];
DataElement obj = _dataStore.createObject(deObj, _deGrep, match.getLine(), absPath);

View file

@ -1,17 +1,18 @@
/********************************************************************************
* Copyright (c) 2006 IBM Corporation and others. All rights reserved.
* Copyright (c) 2006, 2008 IBM Corporation and others. 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
* 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, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
*
* Contributors:
* Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name
* Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
********************************************************************************/
package org.eclipse.rse.services.clientserver;
@ -26,13 +27,14 @@ import java.io.UnsupportedEncodingException;
import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath;
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
import org.eclipse.rse.services.clientserver.java.BasicClassFileParser;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
/**
* This singleton class classifies a file on the remote system.
*/
public class SystemFileClassifier {
private static SystemFileClassifier instance;
/**
@ -41,20 +43,20 @@ public class SystemFileClassifier {
private SystemFileClassifier() {
super();
}
/**
* Returns the singleton instance.
* @return the singleton instance.
*/
public static SystemFileClassifier getInstance() {
if (instance == null) {
instance = new SystemFileClassifier();
}
return instance;
}
/**
* Classifies the file with the given absolute path. The absolute path can represent a virtual file.
* By default, returns <code>"file"</code>.
@ -62,10 +64,10 @@ public class SystemFileClassifier {
* @return the classification.
*/
public String classifyFile(String absolutePath) {
// first check if the absolute path is virtual
boolean isVirtual = ArchiveHandlerManager.isVirtual(absolutePath);
// if virtual, classify using archive handler manager
if (isVirtual) {
return classifyVirtual(absolutePath);
@ -75,52 +77,56 @@ public class SystemFileClassifier {
return classifyNonVirtual(absolutePath);
}
}
/**
* Classifies a virtual file with the given path.
* @param absolutePath the absolute path of the virtual file.
* @return the classification.
*/
protected String classifyVirtual(String absolutePath) {
// create an abolute virtual path object
// create an absolute virtual path object
AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absolutePath);
// get the path of the containing archive
String archivePath = avp.getContainingArchiveString();
// get the virtual part of the file path
String virtualPath = avp.getVirtualPart();
// get archive file
File archiveFile = new File(archivePath);
// get classification of virtual file
return ArchiveHandlerManager.getInstance().getClassification(archiveFile, virtualPath);
try {
return ArchiveHandlerManager.getInstance().getClassification(archiveFile, virtualPath);
} catch (SystemMessageException e) {
return "file"; //FIXME check fallback //$NON-NLS-1$
}
}
/**
* Classifies a non-virtual file with the given path.
* @param absolutePath the absolute path of the file.
* @return the classification.
*/
protected String classifyNonVirtual(String absolutePath) {
// default type
String type = "file"; //$NON-NLS-1$
File file = new File(absolutePath);
// check if file exists
if (!file.exists()) {
return type;
}
// find out if we are on Windows
boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("win"); //$NON-NLS-1$ //$NON-NLS-2$
// for Windows, we only detect *.exe and *.dll files
if (isWindows)
if (isWindows)
{
absolutePath = absolutePath.toLowerCase();
// classify *.class file
@ -135,43 +141,43 @@ public class SystemFileClassifier {
else if (absolutePath.endsWith(".dll")) { //$NON-NLS-1$
type = "module"; //$NON-NLS-1$
}
return type;
}
// get specified encoding if any
String encoding = System.getProperty("dstore.stdin.encoding"); //$NON-NLS-1$
// otherwise, default to system encoding
if (encoding == null || encoding.equals("")) { //$NON-NLS-1$
encoding = System.getProperty("file.encoding"); //$NON-NLS-1$
}
// create command "sh -c file <absolutePath>"
String args[] = new String[3];
args[0] = "sh"; //$NON-NLS-1$
args[1] = "-c"; //$NON-NLS-1$
args[2] = "file " + PathUtility.enQuoteUnix(absolutePath); //$NON-NLS-1$
BufferedReader poutReader = null;
try {
Process childProcess = Runtime.getRuntime().exec(args);
InputStreamReader reader = new InputStreamReader(childProcess.getInputStream(), encoding);
poutReader = new BufferedReader(reader);
// get line of output
String line = poutReader.readLine();
if (line != null) {
line = line.trim();
// classify from line of output
type = getClassification(absolutePath, line);
// close stream
poutReader.close();
// if it a symbolic link, then get the canonical path and classify it as well
if (type.equals("link")) { //$NON-NLS-1$
String canonicalPath = file.getCanonicalPath();
@ -190,37 +196,37 @@ public class SystemFileClassifier {
// TODO: log it
return type;
}
return type;
}
/**
* Classifies from the given line of classification output.
* @param absolutePath the absolute path of the file that was classified.
* @param line the line of output to parse.
* @param line the line of output to parse.
* @return the classification.
*/
protected String getClassification(String absolutePath, String line) {
// default type
String type = "file"; //$NON-NLS-1$
String name = line;
String fulltype = ""; //$NON-NLS-1$
// Look for colon. Name appears before colon. Full type appears after the colon
int colon = line.indexOf(':');
if (colon >= 0) {
name = line.substring(0, colon);
fulltype = line.substring(colon + 1, line.length()).trim();
}
// if it is a *.class file, then we look for main method and qulaified class name
// as part of the classification
if (name.endsWith(".class")) { //$NON-NLS-1$
type = classifyClassFile(absolutePath);
}
// check if it is a shared library
boolean matchesLib = (fulltype.indexOf("shared object") > -1) || //$NON-NLS-1$
(fulltype.indexOf("object module") > -1) || //$NON-NLS-1$
@ -228,22 +234,22 @@ public class SystemFileClassifier {
// check if it is an executable
boolean matchesExe = (fulltype.indexOf("executable") > -1); //$NON-NLS-1$
// check if it is a script
boolean matchesScript = (fulltype.indexOf("script") > -1); //$NON-NLS-1$
// shared library
if (matchesLib) {
// all *.a, *.so and *.so.* files are of type "module"
if (name.endsWith(".a") || name.endsWith(".so") || (name.indexOf(".so.") > 0)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
type = "module"; //$NON-NLS-1$
}
}
// a script file
else if (matchesScript) {
// an executable script file
if (matchesExe) {
type = "executable(script)"; //$NON-NLS-1$
@ -253,74 +259,74 @@ public class SystemFileClassifier {
type = "script"; //$NON-NLS-1$
}
}
// binary executable
else if (matchesExe) {
type = "executable(binary)"; //$NON-NLS-1$
}
// on iSeries we look for "OS/400 object" as a type
else if (fulltype.indexOf("OS/400 object") > -1) { //$NON-NLS-1$
type = "OS/400 object"; //$NON-NLS-1$
}
// finally, if the full type contains the symbolic link string, then type is simply "link"
else if (fulltype.startsWith("symbolic link to")) { //$NON-NLS-1$
type = "link"; //$NON-NLS-1$
}
return type;
return type;
}
/**
* Classifies a class file.
* @param absolutePath the absolute path of the class file.
* @return the classification.
*/
protected String classifyClassFile(String absolutePath) {
// default type
String type = "file"; //$NON-NLS-1$
// input stream to file
FileInputStream stream = null;
// class file parser
BasicClassFileParser parser = null;
boolean isExecutable = false;
try {
stream = new FileInputStream(absolutePath);
// use class file parser to parse the class file
parser = new BasicClassFileParser(stream);
parser.parse();
// query if it is executable, i.e. whether it has main method
isExecutable = parser.isExecutable();
}
catch (IOException e) {
// TODO: log it
// we assume not executable
isExecutable = false;
return type;
}
// if it is executable, then also get qualified class name
if (isExecutable) {
type = "executable(java"; //$NON-NLS-1$
String qualifiedClassName = parser.getQualifiedClassName();
if (qualifiedClassName != null) {
type = type + ":" + qualifiedClassName; //$NON-NLS-1$
}
type = type + ")"; //$NON-NLS-1$
}
return type;
}
}

View file

@ -10,13 +10,14 @@
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
*
* Contributors:
* Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors
* 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
* Xuan Chen (IBM) - [218491] ArchiveHandlerManager#cleanUpVirtualPath is messing up the file separators (with updated fix)
* Johnson Ma (Wind River) - [195402] [api] add tar.gz archive support
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.services.clientserver.archiveutils;
@ -27,6 +28,11 @@ import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;
import org.eclipse.rse.internal.services.Activator;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.services.clientserver.messages.SystemOperationFailedException;
import org.eclipse.rse.services.clientserver.messages.SystemUnsupportedOperationException;
/**
* This class manages all the Archive Handlers that correspond to the archive file that the system
* would like to deal with. It contains methods for registering handlers with file types, as well as
@ -46,14 +52,14 @@ public class ArchiveHandlerManager
/**
* Folder separator used in virtual paths inside the archive, i.e. after the
* VIRTUAL_SEPARATOR.
*
*
* @since org.eclipse.rse.services 3.0
*/
public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$
/**
* Character used to separate file extension from file name. This is used in
* order to recognize file patterns that should be treated as archives.
*
*
* @since org.eclipse.rse.services 3.0
*/
public static final String EXTENSION_SEPARATOR = "."; //$NON-NLS-1$
@ -82,36 +88,51 @@ public class ArchiveHandlerManager
}
/**
* Returns the children of an object in the virtual file system.
* Returns the children of an object in the virtual file system. Throws
* SystemMessageException instead of IOException since RSE 3.0.
*
* @param file The archive in whose virtual file system the children reside.
* @param virtualpath The parent virtual object whose children this method is to return. To
* get the top level virtualchildren in the archive, set virtualpath to "" or null.
* @return An array of VirtualChild objects representing the children of the virtual object
* in <code>file</code> referred to by <code>virtualpath</code>. If no class implementing
* ISystemArchiveHandler can be found that corresponds to file, then this method returns null.
* If the virtual object has no children, this method also returns null.
* @throws IOException if there was a problem getting the registered handler for the
* file. This usually means the archive is corrupted.
* @param virtualpath The parent virtual object whose children this method
* is to return. To get the top level virtual children in the archive,
* set virtual path to "" or null.
* @return An array of VirtualChild objects representing the children of the
* virtual object in <code>file</code> referred to by
* <code>virtual path</code>. If no class implementing ISystemArchiveHandler
* can be found that corresponds to file, then this method returns null. If
* the virtual object has no children, this method also returns null.
* @throws SystemMessageException in case of an error, e.g. there was a
* problem getting the registered handler for the file. This usually
* means the archive is corrupted.
* @since 3.0
*/
public VirtualChild[] getContents(File file, String virtualpath) throws IOException
public VirtualChild[] getContents(File file, String virtualpath) throws SystemMessageException
{
if (virtualpath == null) virtualpath = ""; //$NON-NLS-1$
ISystemArchiveHandler handler = getRegisteredHandler(file);
if (handler == null || !handler.exists()) throw new IOException();
if (handler == null || !handler.exists()) {
throw new SystemUnsupportedOperationException(Activator.PLUGIN_ID, "No handler for " + file); //$NON-NLS-1$
}
return handler.getVirtualChildren(virtualpath, null);
}
/**
* Returns the children of an object in the virtual file system that are folders.
* Returns the children of an object in the virtual file system that are
* folders.
*
* @param file The archive in whose virtual file system the children reside.
* @param virtualpath The parent virtual object whose children this method is to return. To
* get the top level virtualchildren in the archive, set virtualpath to "" or null.
* @return An array of VirtualChild objects representing the children of the virtual object
* in <code>file</code> referred to by <code>virtualpath</code> that are themselves folders.
* If no class implementing ISystemArchiveHandler can be found that corresponds to file, then
* this method returns null. If the virtual object has no children, this method also returns null.
* @param virtualpath The parent virtual object whose children this method
* is to return. To get the top level virtual children in the archive,
* set virtual path to "" or null.
* @return An array of VirtualChild objects representing the children of the
* virtual object in <code>file</code> referred to by
* <code>virtualpath</code> that are themselves folders. If no class
* implementing ISystemArchiveHandler can be found that corresponds to
* file, then this method returns null. If the virtual object has no
* children, this method also returns null.
* @throws SystemMessageException in case of an error
* @since 3.0
*/
public VirtualChild[] getFolderContents(File file, String virtualpath)
public VirtualChild[] getFolderContents(File file, String virtualpath) throws SystemMessageException
{
if (virtualpath == null) virtualpath = ""; //$NON-NLS-1$
ISystemArchiveHandler handler = getRegisteredHandler(file);
@ -222,14 +243,18 @@ public class ArchiveHandlerManager
}
/**
* Given the absolute path to a virtual object, returns that object
* as a VirtualChild.
* @param fullyQualifiedName The absolute path to the object. Usually consists
* of the fullyQualifiedName of the archive, followed by the virtual path separator
* (defined in ArchiveHandlerManager.VIRTUAL_SEPARATOR) followed by the virtual path to
* the object within the archive's virtual file system.
* Given the absolute path to a virtual object, returns that object as a
* VirtualChild.
*
* @param fullyQualifiedName The absolute path to the object. Usually
* consists of the fullyQualifiedName of the archive, followed by the
* virtual path separator (defined in
* ArchiveHandlerManager.VIRTUAL_SEPARATOR) followed by the virtual
* path to the object within the archive's virtual file system.
* @throws SystemMessageException in case of an error
* @since 3.0
*/
public VirtualChild getVirtualObject(String fullyQualifiedName)
public VirtualChild getVirtualObject(String fullyQualifiedName) throws SystemMessageException
{
String cleanName = cleanUpVirtualPath(fullyQualifiedName);
AbsoluteVirtualPath avp = new AbsoluteVirtualPath(cleanName);
@ -243,11 +268,15 @@ public class ArchiveHandlerManager
}
/**
* Returns the registered handler for the File <code>file</code>. If
* no handler exists for that file yet, create it. If the extension of
* Returns the registered handler for the File <code>file</code>. If no
* handler exists for that file yet, create it. If the extension of
* <code>file</code> is not registered, then returns null.
*
* @throws SystemMessageException in case of an error instantiating the
* handler
* @since 3.0
*/
public ISystemArchiveHandler getRegisteredHandler(File file)
public ISystemArchiveHandler getRegisteredHandler(File file) throws SystemMessageException
{
ISystemArchiveHandler handler = null;
if (_handlers.containsKey(file))
@ -279,17 +308,11 @@ public class ArchiveHandlerManager
catch (InvocationTargetException e)
{
//Throwable target = e.getCause();
System.out.println(e.getMessage());
e.printStackTrace();
System.out.println("Could not instantiate handler for " + file.getName()); //$NON-NLS-1$
return null;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "instantiate handler for " + file.getName(), e); //$NON-NLS-1$
}
catch (Exception e)
{
System.out.println(e.getMessage());
System.out.println("Could not instantiate handler for " + file.getName()); //$NON-NLS-1$
return null;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "instantiate handler for " + file.getName(), e); //$NON-NLS-1$
}
_handlers.put(file, handler);
return handler;
@ -475,28 +498,30 @@ public class ArchiveHandlerManager
_handlers.clear();
}
public boolean createEmptyArchive(File newFile)
/**
* Create an empty archive
*
* @throws SystemMessageException in case of an error
*/
public void createEmptyArchive(File newFile) throws SystemMessageException
{
if (!isRegisteredArchive(newFile.getName()))
{
System.out.println("Could not create new archive."); //$NON-NLS-1$
System.out.println(newFile + " is not a registered type of archive."); //$NON-NLS-1$
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive, because " //$NON-NLS-1$
+ newFile + " is not a registered type of archive."); //$NON-NLS-1$
}
if (newFile.exists())
{
if (!newFile.isFile())
{
System.out.println("Could not create new archive."); //$NON-NLS-1$
System.out.println(newFile + " is not a file."); //$NON-NLS-1$
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive." //$NON-NLS-1$
+ newFile + " is not a file."); //$NON-NLS-1$
}
if (!newFile.delete())
{
System.out.println("Could not create new archive."); //$NON-NLS-1$
System.out.println(newFile + " could not be deleted."); //$NON-NLS-1$
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive." //$NON-NLS-1$
+ newFile + " could not be deleted."); //$NON-NLS-1$
}
}
@ -504,20 +529,17 @@ public class ArchiveHandlerManager
{
if (!newFile.createNewFile())
{
System.out.println("Could not create new archive."); //$NON-NLS-1$
System.out.println(newFile + " could not be created."); //$NON-NLS-1$
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive." //$NON-NLS-1$
+ newFile + " could not be created."); //$NON-NLS-1$
}
}
catch (IOException e)
{
System.out.println("Could not create new archive."); //$NON-NLS-1$
System.out.println(e.getMessage());
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive: " + newFile, e); //$NON-NLS-1$
}
ISystemArchiveHandler handler = getRegisteredHandler(newFile);
return handler.create();
handler.create();
}
/**
@ -535,14 +557,26 @@ public class ArchiveHandlerManager
return extensions;
}
public String getComment(File archive)
/**
* Get archive comment.
*
* @throws SystemMessageException in case of an error
* @since 3.0
*/
public String getComment(File archive) throws SystemMessageException
{
ISystemArchiveHandler handler = getRegisteredHandler(archive);
if (handler == null || !handler.exists()) return ""; //$NON-NLS-1$
return handler.getArchiveComment();
}
public long getExpandedSize(File archive)
/**
* Get total expanded size of an archive.
*
* @throws SystemMessageException in case of an error
* @since 3.0
*/
public long getExpandedSize(File archive) throws SystemMessageException
{
ISystemArchiveHandler handler = getRegisteredHandler(archive);
if (handler == null || !handler.exists()) return 0;
@ -556,12 +590,15 @@ public class ArchiveHandlerManager
}
/**
* Returns the classification for the entry in a archive with the given virtual path.
* Returns the classification for the entry in a archive with the given
* virtual path.
*
* @param file the archive file.
* @param virtualPath the virtual path.
* @return the classification for the virtual file.
* @throws SystemMessageException in case of an error
*/
public String getClassification(File file, String virtualPath) {
public String getClassification(File file, String virtualPath) throws SystemMessageException {
// if archive file is null, or if it does not exist, or if the virtual path
// is null, then return null for the classification

View file

@ -10,10 +10,11 @@
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
*
* Contributors:
* Xuan Chen (IBM) - [160775][api][breaking] rename (at least within a zip) blocks UI thread
* Martin Oberhuber (Wind River) - [cleanup] add API "since" tags to Archive Handler Javadoc
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.services.clientserver.archiveutils;
@ -23,6 +24,7 @@ import java.io.InputStream;
import org.eclipse.rse.services.clientserver.ISystemFileTypes;
import org.eclipse.rse.services.clientserver.ISystemOperationMonitor;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.services.clientserver.search.SystemSearchLineMatch;
import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher;
@ -30,7 +32,7 @@ import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher;
/**
* An interface that allows implementing classes to create their own handlers
* for various types of archive files, ie: zip, jar, tar, rpm.
*
*
* @author mjberger
*/
public interface ISystemArchiveHandler
@ -39,23 +41,26 @@ public interface ISystemArchiveHandler
* Turns the archive that this handler represents into a new, empty archive.
* (The archive could not exist before, in which case this would be a true
* creation).
*
* @return Whether or not the blank archive was successfully created.
*
* @throws SystemMessageException in case of an error
* @since org.eclipse.rse.services 3.0
*/
public boolean create();
public void create() throws SystemMessageException;
/**
* Return a flat list of entries in an archive.
*
*
* @param archiveOperationMonitor the operation progress monitor
* @return an array containing all the entries in the archive file in a flat
* format, where the entries' filenames are prepended by the path to
* the entry within the virtual file system. If there are no entries
* in the file, returns an array of size 0.
*
* format, where the entries' filenames are prepended by the path to the
* entry within the virtual file system. If there are no entries in the
* file, returns an array of size 0.
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
*
* @since org.eclipse.rse.services 3.0
*/
public VirtualChild[] getVirtualChildrenList(ISystemOperationMonitor archiveOperationMonitor);
public VirtualChild[] getVirtualChildrenList(ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Return a flat list of entries in an archive, whose full paths begin with
@ -64,13 +69,14 @@ public interface ISystemArchiveHandler
* @param parent full path of the parent
* @param archiveOperationMonitor the operation progress monitor
* @return an array containing all the entries in the archive file in a flat
* format, whose full paths begin with the String
* <code>parent</code>. Returns an array of length 0 if there are
* no such entries.
* format, whose full paths begin with the String <code>parent</code>.
* Returns an array of length 0 if there are no such entries.
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
*
* @since org.eclipse.rse.services 3.0
*/
public VirtualChild[] getVirtualChildrenList(String parent, ISystemOperationMonitor archiveOperationMonitor);
public VirtualChild[] getVirtualChildrenList(String parent, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Return the children of a specified node in an archive.
@ -78,14 +84,15 @@ public interface ISystemArchiveHandler
* @param fullVirtualName full virtual path of the parent
* @param archiveOperationMonitor the operation progress monitor
* @return an array containing the virtual children of the virtual directory
* named <code>fullVirtualName</code>. If
* <code>fullVirtualName</code> is "", returns the top level in
* the virtual file system tree. If there are no values to return,
* returns null.
* named <code>fullVirtualName</code>. If <code>fullVirtualName</code> is
* "", returns the top level in the virtual file system tree. If there are
* no values to return, returns null.
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
*
* @since org.eclipse.rse.services 3.0
*/
public VirtualChild[] getVirtualChildren(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor);
public VirtualChild[] getVirtualChildren(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Return those children of a specified node in an archive, which are
@ -94,14 +101,16 @@ public interface ISystemArchiveHandler
* @param fullVirtualName full virtual path of the parent
* @param archiveOperationMonitor the operation progress monitor
* @return an array containing the virtual children of the virtual directory
* named <code>fullVirtualName</code> that are themselves
* directories. If <code>fullVirtualName</code> is "", returns the
* top level of directories in the virtual file system tree. If
* there are no values to return, returns null.
* named <code>fullVirtualName</code> that are themselves directories. If
* <code>fullVirtualName</code> is "", returns the top level of directories
* in the virtual file system tree. If there are no values to return,
* returns null.
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
*
* @since org.eclipse.rse.services 3.0
*/
public VirtualChild[] getVirtualChildFolders(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor);
public VirtualChild[] getVirtualChildFolders(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Return an archive node specified by a given virtual path.
@ -109,14 +118,16 @@ public interface ISystemArchiveHandler
* @param fullVirtualName full virtual path of the object to retrieve
* @param archiveOperationMonitor the operation progress monitor
* @return the virtual File or Folder referred to by
* <code>fullVirtualName</code>. This method never returns null.
* In cases where the VirtualChild does not physically exist in the
* archive, this method returns a new VirtualChild object whose
* exists() method returns false.
* <code>fullVirtualName</code>. This method never returns null. In cases
* where the VirtualChild does not physically exist in the archive, this
* method returns a new VirtualChild object whose exists() method returns
* false.
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
*
* @since org.eclipse.rse.services 3.0
*/
public VirtualChild getVirtualFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor);
public VirtualChild getVirtualFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Check whether a given virtual node exists in an archive.
@ -124,17 +135,18 @@ public interface ISystemArchiveHandler
* @param fullVirtualName full virtual path of the object
* @param archiveOperationMonitor the operation progress monitor
* @return Whether or not the virtual file or folder named
* <code>fullVirtualName</code> exists in the archive
* (physically).
* <code>fullVirtualName</code> exists in the archive (physically).
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
*
* @since org.eclipse.rse.services 3.0
*/
public boolean exists(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor);
public boolean exists(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Check if the archive handler implementation associated with this class
* exists.
*
*
* @return Whether or not the handler exists. Usually false if the archive
* is corrupted or unreadable.
*/
@ -142,7 +154,7 @@ public interface ISystemArchiveHandler
/**
* Return the archive that this handler deals with.
*
*
* @return the archive that this handler deals with
*/
public File getArchive();
@ -152,50 +164,55 @@ public interface ISystemArchiveHandler
*
* @param fullVirtualName virtual path specifying the node to check
* @return the current timestamp (last modified) for the archive entry named
* <code>fullVirtualName</code>
* <code>fullVirtualName</code>
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
*/
public long getTimeStampFor(String fullVirtualName);
public long getTimeStampFor(String fullVirtualName) throws SystemMessageException;
/**
* Return the size for an archive node.
*
* @param fullVirtualName virtual path specifying the node to check
* @return the current size (uncompressed) for the entry in the archive
* named <code>fullVirtualName</code>
* named <code>fullVirtualName</code>
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
*/
public long getSizeFor(String fullVirtualName);
public long getSizeFor(String fullVirtualName) throws SystemMessageException;
/**
* Extracts the virtual file named <code>fullVirtualName</code> from the
* archive, placing the results in <code>destination</code>.
*
* @param fullVirtualName The full path and name of the virtual file in the
* archive.
* archive.
* @param destination The destination file for the extracted virtual file.
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor);
public void extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Extracts the virtual file named <code>fullVirtualName</code> from the
* archive, placing the results in <code>destination</code>. Extracts to
* the native encoding, but assumes that the source was archived using
* archive, placing the results in <code>destination</code>. Extracts to the
* native encoding, but assumes that the source was archived using
* <code>sourceEncoding</code> if <code>isText</code> is true.
*
* @param fullVirtualName The full path and name of the virtual file in the
* archive.
* archive.
* @param destination The destination file for the extracted virtual file.
* @param sourceEncoding The encoding of the file in the archive.
* @param isText Whether or not the virtual file is a text file.
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean extractVirtualFile(String fullVirtualName, File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor);
public void extractVirtualFile(String fullVirtualName, File destination, String sourceEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Extracts the directory <code>dir</code> (and its children) from the
@ -204,13 +221,13 @@ public interface ISystemArchiveHandler
*
* @param dir The full name of the virtual directory to extract
* @param destinationParent A handle to the directory in which the extracted
* directory will be placed as a subdirectory.
* directory will be placed as a subdirectory.
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean extractVirtualDirectory(String dir, File destinationParent, ISystemOperationMonitor archiveOperationMonitor);
public void extractVirtualDirectory(String dir, File destinationParent, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Extracts the directory <code>dir</code> (and its children) from the
@ -221,15 +238,16 @@ public interface ISystemArchiveHandler
*
* @param dir The full name of the virtual directory to extract
* @param destinationParent A handle to the directory in which the extracted
* directory will be placed as a subdirectory.
* directory will be placed as a subdirectory.
* @param sourceEncoding The encoding of the files in the archive.
* @param isText Whether or not the files in the directory are text files
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean extractVirtualDirectory(String dir, File destinationParent, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor);
public void extractVirtualDirectory(String dir, File destinationParent, String sourceEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Extracts the directory <code>dir</code> (and its children) from the
@ -239,67 +257,68 @@ public interface ISystemArchiveHandler
*
* @param dir The full name of the virtual directory to extract
* @param destinationParent A handle to the directory in which the extracted
* directory will be placed as a subdirectory.
* directory will be placed as a subdirectory.
* @param destination A handle to the directory that will be created.
* Whatever contents are in that directory will be replaced with
* what is extracted from the archive.
* Whatever contents are in that directory will be replaced with what
* is extracted from the archive.
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean extractVirtualDirectory(String dir, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor);
public void extractVirtualDirectory(String dir, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor)
throws SystemMessageException;
/**
* Extracts the directory <code>dir</code> (and its children) from the
* archive and places the results in the directory
* <code>destinationParent</code>. The results will be named
* destination.getName() rather than <code>dir</code>'s name. Extracts to
* the native encoding (if <code>isText</code>), but assumes that the
* source was archived using <code>sourceEncoding</code>.
* the native encoding (if <code>isText</code>), but assumes that the source
* was archived using <code>sourceEncoding</code>.
*
* @param dir The full name of the virtual directory to extract
* @param destinationParent A handle to the directory in which the extracted
* directory will be placed as a subdirectory.
* directory will be placed as a subdirectory.
* @param destination A handle to the directory that will be created.
* Whatever contents are in that directory will be replaced with
* what is extracted from the archive.
* Whatever contents are in that directory will be replaced with what
* is extracted from the archive.
* @param sourceEncoding The encoding of the files in the archive.
* @param isText Whether or not the files to be extracted in the directory
* are all text files
* are all text files
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean extractVirtualDirectory(String dir, File destinationParent, File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor);
public void extractVirtualDirectory(String dir, File destinationParent, File destination, String sourceEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Compresses the file <code>file</code> and adds it to the archive,
* placing it in the virtual directory <code>virtualPath</code>. Pass the
* name as the parameter <code>name</code>. If the virtual path does not
* exist in the archive, create it. If <code>file</code> is a directory,
* copy it and its contents into the archive, maintaining the tree
* structure.
* Compresses the file <code>file</code> and adds it to the archive, placing
* it in the virtual directory <code>virtualPath</code>. Pass the name as
* the parameter <code>name</code>. If the virtual path does not exist in
* the archive, create it. If <code>file</code> is a directory, copy it and
* its contents into the archive, maintaining the tree structure.
*
* @param file the file to be added to the archive
* @param virtualPath the destination of the file
* @param name the name of the result virtual file
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor);
public void add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Compresses the file <code>file</code> and adds it to the archive,
* saving it in the encoding specified by <code>encoding</code> if the
* isText is true. placing it in the virtual directory
* <code>virtualPath</code>. Pass the name as the parameter
* <code>name</code>. If the virtual path does not exist in the archive,
* create it. If <code>file</code> is a directory, copy it and its
* contents into the archive, maintaining the tree structure.
* Compresses the file <code>file</code> and adds it to the archive, saving
* it in the encoding specified by <code>encoding</code> if the isText is
* true. placing it in the virtual directory <code>virtualPath</code>. Pass
* the name as the parameter <code>name</code>. If the virtual path does not
* exist in the archive, create it. If <code>file</code> is a directory,
* copy it and its contents into the archive, maintaining the tree
* structure.
*
* @param file the file to be added to the archive
* @param virtualPath the destination of the file
@ -308,19 +327,20 @@ public interface ISystemArchiveHandler
* @param targetEncoding the encoding of the result file
* @param isText is the file a text file
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor);
public void add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Compresses the bytes in the InputStream <code>stream</code> and adds
* them as an entry to the archive, saving them in the encoding specified by
* <code>encoding</code> if <code>isText</code> is true, and placing it
* in the virtual directory <code>virtualPath</code>. Pass the name as
* the parameter <code>name</code>. If the virtual path does not exist in
* the archive, create it.
* Compresses the bytes in the InputStream <code>stream</code> and adds them
* as an entry to the archive, saving them in the encoding specified by
* <code>encoding</code> if <code>isText</code> is true, and placing it in
* the virtual directory <code>virtualPath</code>. Pass the name as the
* parameter <code>name</code>. If the virtual path does not exist in the
* archive, create it.
*
* @param stream the InputStream to be added as an entry to the archive
* @param virtualPath the destination of the stream
@ -329,20 +349,21 @@ public interface ISystemArchiveHandler
* @param targetEncoding the encoding of the result file
* @param isText is the file a text file
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor);
public void add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Compresses the file <code>file</code> and adds it to the archive,
* saving it in the encoding specified by <code>encoding</code> if the
* isText is true. placing it in the virtual directory
* <code>virtualPath</code>. Pass the name as the parameter
* <code>name</code>. If the virtual path does not exist in the archive,
* create it. If <code>file</code> is a directory, copy it and its
* contents into the archive, maintaining the tree structure.
* Compresses the file <code>file</code> and adds it to the archive, saving
* it in the encoding specified by <code>encoding</code> if the isText is
* true. placing it in the virtual directory <code>virtualPath</code>. Pass
* the name as the parameter <code>name</code>. If the virtual path does not
* exist in the archive, create it. If <code>file</code> is a directory,
* copy it and its contents into the archive, maintaining the tree
* structure.
*
* @param file the file to be added to the archive
* @param virtualPath the destination of the file
@ -351,39 +372,39 @@ public interface ISystemArchiveHandler
* @param targetEncoding the encoding of the result file
* @param typeRegistery file transfer mode (binary or text) of this file
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes typeRegistery, ISystemOperationMonitor archiveOperationMonitor);
public void add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes typeRegistery,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* A generalization of the add method. Compresses the array of files
* <code>files</code> and adds each of them to the archive, placing them
* in the virtual directory <code>virtualPath</code>. Pass the names of
* the files as the parameter <code>names</code>, where
* <code>files[i]</code> has the name <code>names[i]</code>. If the
* virtual path does not exist in the archive, create it.
* <code>files</code> and adds each of them to the archive, placing them in
* the virtual directory <code>virtualPath</code>. Pass the names of the
* files as the parameter <code>names</code>, where <code>files[i]</code>
* has the name <code>names[i]</code>. If the virtual path does not exist in
* the archive, create it.
*
* @param files the list of files to be added to the archive
* @param virtualPath the destination of the file
* @param names the names of the result virtual files
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor);
public void add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* A generalization of the add method. Compresses the array of files
* <code>files</code> and adds each of them to the archive, placing them
* in the virtual directory <code>virtualPath</code>. Save the i'th file
* in the i'th encoding (if isText[i] is true) specified by
* <code>encodings</code>. Pass the names of the files as the parameter
* <code>names</code>, where <code>files[i]</code> has the name
* <code>names[i]</code>. If the virtual path does not exist in the
* archive, create it.
* <code>files</code> and adds each of them to the archive, placing them in
* the virtual directory <code>virtualPath</code>. Save the i'th file in the
* i'th encoding (if isText[i] is true) specified by <code>encodings</code>.
* Pass the names of the files as the parameter <code>names</code>, where
* <code>files[i]</code> has the name <code>names[i]</code>. If the virtual
* path does not exist in the archive, create it.
*
* @param files the list of files to be added to the archive
* @param virtualPath the destination of the files
@ -392,33 +413,34 @@ public interface ISystemArchiveHandler
* @param targetEncodings the encoding of the result files
* @param isText file transfer mode (binary or text) of the files
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText, ISystemOperationMonitor archiveOperationMonitor);
public void add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Compress the file <code>file</code> and replace the virtual file
* referred to by <code>fullVirtualName</code> with the compressed file.
* Pass the name of the file as the parameter <code>name</code>.
* Compress the file <code>file</code> and replace the virtual file referred
* to by <code>fullVirtualName</code> with the compressed file. Pass the
* name of the file as the parameter <code>name</code>.
*
* @param fullVirtualName the path of the file to be replaced
* @param file the file to be added to the archive
* @param name the name of the file
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the replacement is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor);
public void replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Compress the InputStream <code>stream</code> and replace the virtual
* file referred to by <code>fullVirtualName</code> with the compressed
* stream. Pass the name of the new entry as the parameter <code>name</code>,
* the encoding of the entry as <code>encoding</code> and whether or not
* the entry <code>isText</code> or not.
* Compress the InputStream <code>stream</code> and replace the virtual file
* referred to by <code>fullVirtualName</code> with the compressed stream.
* Pass the name of the new entry as the parameter <code>name</code>, the
* encoding of the entry as <code>encoding</code> and whether or not the
* entry <code>isText</code> or not.
*
* @param fullVirtualName the path of the file to be replaced
* @param stream the InputStream to be added as an entry to the archive
@ -427,11 +449,12 @@ public interface ISystemArchiveHandler
* @param targetEncoding the encoding of the result file
* @param isText is the file a text file
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the replacement is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor);
public void replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Deletes the entry <code>fullVirtualName</code> from the archive, and
@ -440,10 +463,13 @@ public interface ISystemArchiveHandler
* @param fullVirtualName the path of the file to be deleted
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the deletion is successful,
* <code>false</code> otherwise
* <code>false</code> if the file to delete was not found so this was a
* successful no-op.
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor);
public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Renames the entry <code>fullVirtualName</code> to the new name
@ -452,25 +478,25 @@ public interface ISystemArchiveHandler
*
* @param fullVirtualName the path of the file to be renamed
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the rename is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor);
public void rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Moves the entry <code>fullVirtualName</code> to the location specified
* by <code>destinationVirtualPath</code>, while leaving the entry with
* the same name as before.
* Moves the entry <code>fullVirtualName</code> to the location specified by
* <code>destinationVirtualPath</code>, while leaving the entry with the
* same name as before.
*
* @param fullVirtualName the path of the file to be renamed
* @param destinationVirtualPath the destination of the file to move to
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the move is successful, <code>false</code>
* otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor);
public void move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Replaces the full name and path of the entry <code>fullVirtualName</code>
@ -479,11 +505,11 @@ public interface ISystemArchiveHandler
* @param fullVirtualName the path of the file to be renamed
* @param newFullVirtualName the full path of the virtual file name
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the rename is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor);
public void fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Extracts and returns the specified list of virtual files from the
@ -492,42 +518,44 @@ public interface ISystemArchiveHandler
* @param fullNames The list of files to return
* @param archiveOperationMonitor the operation progress monitor
* @return An array of handles to the extracted files. If fullNames has
* length 0 then this method returns an array of length 0.
* length 0 then this method returns an array of length 0.
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor);
public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Creates a new, empty folder in the archive. If parent folders do not
* exist either, creates them.
*
* @param fullVirtualName The full name and path of the new folder within
* the virtual file system.
* the virtual file system.
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the create operation is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean createFolder(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor);
public void createFolder(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Creates a new, empty file in the archive. If parent folders do not exist
* either, creates them.
*
* @param fullVirtualName The full name and path of the new file within the
* virtual file system.
* virtual file system.
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the create operation is successful,
* <code>false</code> otherwise
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public boolean createFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor);
public void createFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException;
/**
* Get the archive-type specific standard name for the VirtualChild
* <code>vc</code>. For example, for Zip archives, if vc is a directory,
* then the standard name must end with a "/".
*
*
* @param vc the archive node to use
* @return the standard name for the node
*/
@ -541,18 +569,22 @@ public interface ISystemArchiveHandler
* @param matcher the pattern matcher to use.
* @param archiveOperationMonitor the operation progress monitor
* @return an array of match objects corresponding to lines where matches
* were found. Returns an empty array if there are no results.
* were found. Returns an empty array if there are no results.
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0
*/
public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor);
public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor)
throws SystemMessageException;
/**
* Get the user-defined comment for a specific entry in the archive.
*
* @param fullVirtualName The entry who's comment is desired
* @return the comment as a String or "" if there is none
* @throws SystemMessageException in case of an error
*/
public String getCommentFor(String fullVirtualName);
public String getCommentFor(String fullVirtualName) throws SystemMessageException;
/**
* Get the amount of space taken up by a specific entry in the archive when
@ -561,31 +593,35 @@ public interface ISystemArchiveHandler
*
* @param fullVirtualName The entry who's compressed size is desired
* @return the compressed size of the specified entry, or 0 if the entry is
* not found. If the archive is not a compression type (ie. tar),
* return the same as getSizeFor(String).
* not found. If the archive is not a compression type (ie. tar), return
* the same as getSizeFor(String).
* @throws SystemMessageException in case of an error
*/
public long getCompressedSizeFor(String fullVirtualName);
public long getCompressedSizeFor(String fullVirtualName) throws SystemMessageException;
/**
* Get the method used to compress a specific entry in the archive.
*
* @param fullVirtualName The entry who's compression method is desired
* @return The compression method of the specified entry, or "" if none.
* @throws SystemMessageException in case of an error
*/
public String getCompressionMethodFor(String fullVirtualName);
public String getCompressionMethodFor(String fullVirtualName) throws SystemMessageException;
/**
* Get the comment associated with an archive.
*
* @return The comment associated with this archive, or "" if there is none.
* @throws SystemMessageException in case of an error
*/
public String getArchiveComment();
public String getArchiveComment() throws SystemMessageException;
/**
* Get the classification for the entry with the given path.
*
* @param fullVirtualName the virtual name.
* @return the classification.
* @throws SystemMessageException in case of an error
*/
public String getClassification(String fullVirtualName);
public String getClassification(String fullVirtualName) throws SystemMessageException;
}

View file

@ -10,7 +10,7 @@
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
*
* Contributors:
* Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors
* Xuan Chen (IBM) - [199132] [Archives-TAR][Local-Windows] Can't open files in tar archives
@ -24,6 +24,7 @@
* Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
* Johnson Ma (Wind River) - [195402][api] Add tar.gz archive support
* Xuan Chen (IBM) - [224576] [api] Inconsistent boolean return values in SystemTarHandler API
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.services.clientserver.archiveutils;
@ -46,12 +47,19 @@ import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.eclipse.rse.internal.services.Activator;
import org.eclipse.rse.internal.services.clientserver.archiveutils.ITarConstants;
import org.eclipse.rse.internal.services.clientserver.archiveutils.SystemArchiveUtil;
import org.eclipse.rse.services.clientserver.ISystemFileTypes;
import org.eclipse.rse.services.clientserver.ISystemOperationMonitor;
import org.eclipse.rse.services.clientserver.SystemReentrantMutex;
import org.eclipse.rse.services.clientserver.java.BasicClassFileParser;
import org.eclipse.rse.services.clientserver.messages.SystemLockTimeoutException;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.services.clientserver.messages.SystemOperationCancelledException;
import org.eclipse.rse.services.clientserver.messages.SystemOperationFailedException;
import org.eclipse.rse.services.clientserver.messages.SystemUnexpectedErrorException;
import org.eclipse.rse.services.clientserver.messages.SystemUnsupportedOperationException;
import org.eclipse.rse.services.clientserver.search.SystemSearchLineMatch;
import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatchLocator;
import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher;
@ -894,7 +902,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
/* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualFile(java.lang.String, java.io.File)
*/
public boolean extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor) {
public void extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
TarEntry entry = null;
@ -922,14 +930,14 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// the entry's last modified time
destination.mkdirs();
destination.setLastModified(entry.getModificationTime());
return true;
return;
}
inStream = getTarFile().getInputStream(entry);
if (inStream == null) {
destination.setLastModified(entry.getModificationTime());
return false; // TODO: return true or false?
throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID);
}
//Need to make sure destination file exists.
if (!destination.exists())
@ -952,7 +960,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
}
}
catch (IOException e) {
// TODO: log error
throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
}
finally {
@ -980,38 +988,37 @@ public class SystemTarHandler implements ISystemArchiveHandler {
releaseMutex(mutexLockStatus);
}
return true;
}
/**
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, ISystemOperationMonitor)
*/
public boolean extractVirtualDirectory(String fullVirtualName, File destinationParent, ISystemOperationMonitor archiveOperationMonitor) {
return extractVirtualDirectory(fullVirtualName, destinationParent, (File) null, archiveOperationMonitor);
public void extractVirtualDirectory(String fullVirtualName, File destinationParent, ISystemOperationMonitor archiveOperationMonitor)
throws SystemMessageException {
extractVirtualDirectory(fullVirtualName, destinationParent, (File) null, archiveOperationMonitor);
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File, org.eclipse.rse.services.clientserver.ISystemOperationMonitor)
*/
public boolean extractVirtualDirectory(String fullVirtualName, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor) {
public void extractVirtualDirectory(String fullVirtualName, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor)
throws SystemMessageException {
// if the destination directory doesn't exist, create it
if (!destinationParent.exists()) {
if (!destinationParent.mkdirs()) {
// TODO: log error
return false; // quit if we fail to create the destination directory
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Create folder " + destinationParent); //$NON-NLS-1$
}
}
// otherwise if the destination directory does exist, but is not a directory, then quit
else if (!destinationParent.isDirectory()) {
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "No folder: " + destinationParent); //$NON-NLS-1$
}
fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK;
try
{
@ -1024,7 +1031,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
VirtualChild dir = vfs.getEntry(fullVirtualName);
if (dir == null || !dir.isDirectory) {
return false;
throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID);
}
if (destination == null) {
@ -1052,15 +1059,10 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// if the directory does not exist, try to create it
if (!topDir.exists() && !topDir.mkdirs()) {
// TODO: log error
return false; // log error and quit if we fail to create the directory
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Create folder " + topDir); //$NON-NLS-1$
}
else {
boolean returnCode = extractVirtualFile(fullVirtualName, topDir, archiveOperationMonitor);
if (returnCode == false)
{
return returnCode;
}
extractVirtualFile(fullVirtualName, topDir, archiveOperationMonitor);
}
// get the children of this directory
@ -1075,41 +1077,34 @@ public class SystemTarHandler implements ISystemArchiveHandler {
}
File childFile = new File(childPath);
boolean returnCode = false;
// if the child is a directory, then we need to extract it and its children
if (tempChild.isDirectory) {
// and now extract its children
returnCode = extractVirtualDirectory(tempChild.fullName, childFile, (File) null, archiveOperationMonitor);
extractVirtualDirectory(tempChild.fullName, childFile, (File) null, archiveOperationMonitor);
}
// otherwise if the child is a file, simply extract it
else {
returnCode = extractVirtualFile(tempChild.fullName, childFile, archiveOperationMonitor);
}
if (returnCode == false)
{
return returnCode;
extractVirtualFile(tempChild.fullName, childFile, archiveOperationMonitor);
}
}
}
}
catch (IOException e)
{
e.printStackTrace();
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
}
finally
{
releaseMutex(mutexLockStatus);
}
return true;
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor)
*/
public boolean add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor ) {
public void add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath);
int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK;
@ -1123,18 +1118,16 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// if it exists, call replace
String fullVirtualName = getFullVirtualName(virtualPath, name);
if (exists(fullVirtualName, archiveOperationMonitor)) {
boolean returnCode = replace(fullVirtualName, file, name, archiveOperationMonitor);
replace(fullVirtualName, file, name, archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return returnCode;
}
else {
File[] files = new File[1];
files[0] = file;
String[] names = new String[1];
names[0] = name;
boolean returnCode = add(files, virtualPath, names, archiveOperationMonitor);
add(files, virtualPath, names, archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return returnCode;
}
}
else {
@ -1162,22 +1155,21 @@ public class SystemTarHandler implements ISystemArchiveHandler {
newNames[numOfChildren] = newNames[numOfChildren] + "/"; //$NON-NLS-1$
}
boolean returnCode = add(sources, virtualPath, newNames, archiveOperationMonitor);
add(sources, virtualPath, newNames, archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return returnCode;
}
}
}
catch (Exception e)
{
e.printStackTrace();
throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
}
finally
{
releaseMutex(mutexLockStatus);
}
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return false;
throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID);
}
/**
@ -1203,7 +1195,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File[], java.lang.String, java.lang.String[], org.eclipse.rse.services.clientserver.ISystemOperationMonitor)
*/
public boolean add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor) {
public void add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK;
File outputTempFile = null;
@ -1225,7 +1217,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
if (!files[i].exists() || !files[i].canRead()) {
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Cannot read: " + files[i]); //$NON-NLS-1$
}
// if the entry already exists, then we should do a replace
@ -1234,9 +1226,8 @@ public class SystemTarHandler implements ISystemArchiveHandler {
String fullVirtualName = getFullVirtualName(virtualPath, names[i]);
if (exists(fullVirtualName, archiveOperationMonitor)) {
boolean returnCode = replace(fullVirtualName, files[i], names[i], archiveOperationMonitor);
replace(fullVirtualName, files[i], names[i], archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return returnCode;
}
}
@ -1252,13 +1243,13 @@ public class SystemTarHandler implements ISystemArchiveHandler {
boolean ok = createTar(children, outStream, (HashSet)null, archiveOperationMonitor);
if (!ok)
{
//cancelled
outStream.close();
if (outputTempFile != null)
{
outputTempFile.delete();
}
return false;
throw new SystemOperationCancelledException();
}
}
VirtualChild[] newEntriesAdded = new VirtualChild[numFiles];
@ -1272,7 +1263,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{
outputTempFile.delete();
}
return false;
throw new SystemOperationCancelledException();
}
String childVirtualPath = virtualPath + "/" + names[i]; //$NON-NLS-1$
@ -1303,7 +1294,6 @@ public class SystemTarHandler implements ISystemArchiveHandler {
}
catch (IOException e) {
e.printStackTrace();
// close output stream
if (outStream != null)
{
@ -1321,27 +1311,27 @@ public class SystemTarHandler implements ISystemArchiveHandler {
outputTempFile.delete();
}
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
}
finally
{
releaseMutex(mutexLockStatus);
}
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return true;
}
/**
* Create a tar file from the given virtual child objects, using the given
* output stream and omitting the children in the given set.
*
*
* @param children an array of virtual children from which to create a tar
* file.
* file.
* @param outStream the tar output stream to use.
* @param omitChildren the set of names for children that should be omitted
* from the given array of virtual children.
* from the given array of virtual children.
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the operation has been cancelled, <code>false</code> otherwise
* @return <code>true</code> if the operation completes successfully, or
* <code>false</code> if it has been cancelled.
* @throws IOException if an I/O exception occurs.
* @since org.eclipse.rse.services 3.0
*/
@ -1661,26 +1651,25 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#replace(java.lang.String, java.io.File, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor)
*/
public boolean replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor) {
public void replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
// update our cache before accessing cache
try {
updateCache();
}
catch (IOException e) {
// TODO: log error
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
}
if (!file.exists() && !file.canRead()) {
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Cannot read " + file); //$NON-NLS-1$
}
fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
// if the virtual file does not exist, we actually want to add
if (!exists(fullVirtualName, archiveOperationMonitor)) {
return add(file, fullVirtualName, name, archiveOperationMonitor);
add(file, fullVirtualName, name, archiveOperationMonitor);
}
try {
@ -1707,8 +1696,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{
outputTempFile.delete();
}
return false;
throw new SystemOperationCancelledException();
}
// now append the new file to the tar
@ -1751,12 +1739,9 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// replace the current tar file with the new one, and do not update cache since
// we just did
replaceFile(outputTempFile, false);
return true;
}
catch (IOException e) {
// TODO: log error
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
}
}
@ -1764,7 +1749,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#delete(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor)
*/
public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor)
public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException
{
boolean returnCode = doDelete(fullVirtualName, archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
@ -1772,15 +1757,17 @@ public class SystemTarHandler implements ISystemArchiveHandler {
}
/**
/**
* Delete a virtual object.
*
*
* @param fullVirtualName virtual path identifying the object
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if successful, <code>false</code> otherwise
* @return <code>true</code> if successful, <code>false</code> if the entry
* to delete did not exist (so this was a successful no-op).
* @throws SystemMessageException in case of an error
* @since org.eclipse.rse.services 3.0
*/
protected boolean doDelete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) {
protected boolean doDelete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
File outputTempFile = null;
int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK;
@ -1831,8 +1818,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{
outputTempFile.delete();
}
return false;
throw new SystemOperationCancelledException();
}
// delete the child from the cache (this will also delete its children if it
@ -1845,53 +1831,48 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// replace the current tar file with the new one, and do not update cache since
// we just did
replaceFile(outputTempFile, false);
return true;
} else {
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
}
}
catch (IOException e) {
System.out.println(e.getMessage());
System.out.println("Could not delete " + fullVirtualName); //$NON-NLS-1$
if (!(outputTempFile == null)) outputTempFile.delete();
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not delete " + fullVirtualName, e); //$NON-NLS-1$
}
finally
{
releaseMutex(mutexLockStatus);
}
return false;
return true;
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#rename(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor)
*/
public boolean rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor) {
public void rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$
boolean resultCode = false;
// if the original does not have any separator, simply rename it.
if (i == -1)
{
resultCode = fullRename(fullVirtualName, newName, archiveOperationMonitor);
fullRename(fullVirtualName, newName, archiveOperationMonitor);
}
// otherwise, get the parent path and append the new name to it.
else
{
String fullNewName = fullVirtualName.substring(0, i+1) + newName;
resultCode = fullRename(fullVirtualName, fullNewName, archiveOperationMonitor);
fullRename(fullVirtualName, fullNewName, archiveOperationMonitor);
}
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return resultCode;
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#move(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor)
*/
public boolean move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor) {
public void move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
destinationVirtualPath = ArchiveHandlerManager.cleanUpVirtualPath(destinationVirtualPath);
@ -1899,12 +1880,12 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// if the original does not have any separator, simply append it to the destination path.
if (i == -1) {
return fullRename(fullVirtualName, destinationVirtualPath + "/" + fullVirtualName, archiveOperationMonitor); //$NON-NLS-1$
fullRename(fullVirtualName, destinationVirtualPath + "/" + fullVirtualName, archiveOperationMonitor); //$NON-NLS-1$
}
// otherwise, get the last segment (the name) and append that to the destination path.
else {
String name = fullVirtualName.substring(i);
return fullRename(fullVirtualName, destinationVirtualPath + name, archiveOperationMonitor);
fullRename(fullVirtualName, destinationVirtualPath + name, archiveOperationMonitor);
}
}
@ -1912,7 +1893,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#fullRename(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor)
*/
public boolean fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor) {
public void fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK;
File outputTempFile = null;
@ -1929,10 +1910,9 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// if the virtual file to be renamed does not exist, then quit
if (!child.exists()) {
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Not exists: " + child); //$NON-NLS-1$
}
// open a new temp file which will be our destination for the new tar file
outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
TarOutputStream outStream = getTarOutputStream(outputTempFile);
@ -1999,11 +1979,10 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{
outputTempFile.delete();
}
return false;
throw new SystemOperationCancelledException();
}
// close the output stream
outStream.close();
@ -2013,19 +1992,15 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// probably be more efficient
replaceFile(outputTempFile, true);
updateTree(newOldNames);
return true;
}
else
{
return false;
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
}
}
catch (IOException e) {
e.printStackTrace();
System.out.println("Could not rename " + fullVirtualName); //$NON-NLS-1$
if (!(outputTempFile == null)) outputTempFile.delete();
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not rename " + fullVirtualName, e); //$NON-NLS-1$
}
finally
{
@ -2036,15 +2011,16 @@ public class SystemTarHandler implements ISystemArchiveHandler {
/**
* Creates a tar file from the given virtual child objects, using the given
* output stream and renaming entries according to hash map entries.
*
*
* @param children an array of virtual children from which to create a tar
* file.
* file.
* @param outStream the tar output stream to use.
* @param renameMap a map containing associations between old names and new
* names. Old names are the keys in the map, and the values are
* the new names.
* names. Old names are the keys in the map, and the values are the new
* names.
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the operation has been cancelled, <code>false</code> otherwise.
* @return <code>true</code> if the operation completes successfully, or
* <code>false</code> if it is cancelled by the user.
* @throws IOException if an I/O exception occurs.
* @since org.eclipse.rse.services 3.0
*/
@ -2148,7 +2124,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getFiles(java.lang.String[], org.eclipse.rse.services.clientserver.ISystemOperationMonitor)
*/
public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor) {
public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
File[] files = new File[fullNames.length];
@ -2171,8 +2147,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
extractVirtualFile(fullNames[i], files[i], archiveOperationMonitor);
}
catch (IOException e) {
// TODO: log error
return null;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
}
}
@ -2183,36 +2158,42 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFolder(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor)
*/
public boolean createFolder(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) {
public void createFolder(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
fullVirtualName = fullVirtualName + "/"; //$NON-NLS-1$
boolean returnCode = createVirtualObject(fullVirtualName, archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return returnCode;
try {
createVirtualObject(fullVirtualName, archiveOperationMonitor);
} finally {
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
}
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFile(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor)
*/
public boolean createFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) {
public void createFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
boolean returnCode = createVirtualObject(fullVirtualName, archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return returnCode;
try {
createVirtualObject(fullVirtualName, archiveOperationMonitor);
} finally {
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
}
}
/**
* Creates a virtual object that does not already exist in the virtual file
* system. Creates an empty file in the tar file.
*
*
* @param name the name of the virtual object.
* @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the object was created successfully,
* <code>false</code> otherwise.
* <code>false</code> if the object already exists such that this is a
* successful no-op, or if the operation is cancelled by the user.
* @throws SystemMessageException in case of an error.
* @since org.eclipse.rse.services 3.0
*/
protected boolean createVirtualObject(String name, ISystemOperationMonitor archiveOperationMonitor) {
protected boolean createVirtualObject(String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
File outputTempFile = null;
TarOutputStream outStream = null;
@ -2224,7 +2205,6 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{
updateCache();
// if the object already exists, return false
if (exists(name, archiveOperationMonitor)) {
return false;
@ -2247,8 +2227,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{
outputTempFile.delete();
}
return false;
throw new SystemOperationCancelledException();
}
}
@ -2265,12 +2244,11 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// replace the current tar file with the new one, but do not update the cache
// since we have already updated to the cache
replaceFile(outputTempFile, false);
return true;
} else {
throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
}
}
catch (IOException e) {
e.printStackTrace();
// close output stream
if (outStream != null)
{
@ -2287,13 +2265,13 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{
outputTempFile.delete();
}
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
}
finally
{
releaseMutex(mutexLockStatus);
}
return false;
return true;
}
/**
@ -2380,7 +2358,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#create()
*/
public boolean create() {
public void create() throws SystemMessageException {
try {
@ -2397,13 +2375,12 @@ public class SystemTarHandler implements ISystemArchiveHandler {
modTimeDuringCache = file.lastModified();
}
catch (IOException e) {
return false;
throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
}
return true;
}
public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor) {
public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor)
throws SystemMessageException {
// if the search string is empty or if it is "*", then return no matches
// since it is a file search
if (matcher.isSearchStringEmpty() || matcher.isSearchStringAsterisk()) {
@ -2443,8 +2420,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
}
}
catch (IOException e) {
// TODO: log error
return new SystemSearchLineMatch[0];
throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
}
}
@ -2491,73 +2467,76 @@ public class SystemTarHandler implements ISystemArchiveHandler {
}
/**
* Compresses the file <code>file</code> and adds it to the archive,
* saving it in the encoding specified by <code>encoding</code> if saving
* in text mode. Places the file in the virtual directory
* <code>virtualPath</code>. Pass the name as the parameter
* <code>name</code>. If the virtual path does not exist in the archive,
* create it. If <code>file</code> is a directory, copy it and its
* contents into the archive, maintaining the tree structure.
*
* Compresses the file <code>file</code> and adds it to the archive, saving
* it in the encoding specified by <code>encoding</code> if saving in text
* mode. Places the file in the virtual directory <code>virtualPath</code>.
* Pass the name as the parameter <code>name</code>. If the virtual path
* does not exist in the archive, create it. If <code>file</code> is a
* directory, copy it and its contents into the archive, maintaining the
* tree structure.
*
* @param file the file to be added to the archive
* @param virtualPath the destination of the file
* @param name the name of the result virtual file
* @param encoding the file encoding to use
* @param registry the file type to use (text or binary)
* @param archiveOperationMonitor the operation progress monitor
* @return true if and only if the add was successful
* @throws SystemMessageException in case of an error
* @since org.eclipse.rse.services 3.0
*/
public boolean add(File file, String virtualPath, String name,
String encoding, ISystemFileTypes registry, ISystemOperationMonitor archiveOperationMonitor) {
return add(file, virtualPath, name, archiveOperationMonitor);
public void add(File file, String virtualPath, String name, String encoding, ISystemFileTypes registry, ISystemOperationMonitor archiveOperationMonitor)
throws SystemMessageException {
add(file, virtualPath, name, archiveOperationMonitor);
}
/* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean)
*/
public boolean add(File file, String virtualPath, String name,
String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) {
return add(file, virtualPath, name, archiveOperationMonitor);
public void add(File file, String virtualPath, String name,
String sourceEncoding, String targetEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
add(file, virtualPath, name, archiveOperationMonitor);
}
/* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File[], java.lang.String, java.lang.String[], java.lang.String[], java.lang.String[], boolean[])
*/
public boolean add(File[] files, String virtualPath, String[] names,
String[] sourceEncodings, String[] targetEncodings, boolean[] isTexts, ISystemOperationMonitor archiveOperationMonitor) {
return add(files, virtualPath, names, archiveOperationMonitor);
public void add(File[] files, String virtualPath, String[] names,
String[] sourceEncodings, String[] targetEncodings, boolean[] isTexts,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
add(files, virtualPath, names, archiveOperationMonitor);
}
/* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File, java.lang.String, boolean)
*/
public boolean extractVirtualDirectory(String dir, File destinationParent,
File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) {
return extractVirtualDirectory(dir, destinationParent, destination, archiveOperationMonitor);
public void extractVirtualDirectory(String dir, File destinationParent,
File destination, String sourceEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
extractVirtualDirectory(dir, destinationParent, destination, archiveOperationMonitor);
}
/* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.lang.String, boolean)
*/
public boolean extractVirtualDirectory(String dir, File destinationParent,
String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) {
return extractVirtualDirectory(dir, destinationParent, archiveOperationMonitor);
public void extractVirtualDirectory(String dir, File destinationParent, String sourceEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
extractVirtualDirectory(dir, destinationParent, archiveOperationMonitor);
}
/* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualFile(java.lang.String, java.io.File, java.lang.String, boolean)
*/
public boolean extractVirtualFile(String fullVirtualName, File destination,
String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) {
return extractVirtualFile(fullVirtualName, destination, archiveOperationMonitor);
public void extractVirtualFile(String fullVirtualName, File destination, String sourceEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
extractVirtualFile(fullVirtualName, destination, archiveOperationMonitor);
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getClassification(java.lang.String)
*/
public String getClassification(String fullVirtualName) {
public String getClassification(String fullVirtualName) throws SystemMessageException {
fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
// default type
@ -2612,18 +2591,19 @@ public class SystemTarHandler implements ISystemArchiveHandler {
return type;
}
public boolean add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) {
// TODO Auto-generated method stub
return false;
public void add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
throw new SystemUnsupportedOperationException(Activator.PLUGIN_ID, "add"); //$NON-NLS-1$
}
public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes typeRegistery, ISystemOperationMonitor archiveOperationMonitor) {
return add(file, virtualPath, name, archiveOperationMonitor);
public void add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes typeRegistery,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
add(file, virtualPath, name, archiveOperationMonitor);
}
public boolean replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) {
// TODO Auto-generated method stub
return false;
public void replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText,
ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
throw new SystemUnsupportedOperationException(Activator.PLUGIN_ID, "replace"); //$NON-NLS-1$
}
/**
@ -2667,7 +2647,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
/**
* Get the tar output stream for a given file. This method can be overridden
* by subclass to return compressed output steam if needed.
*
*
* @param outputFile the output file to create stream
* @return OutputStream the output stream to write
* @throws FileNotFoundException when the output file doesn't exist

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2007 IBM Corporation and others.
* Copyright (c) 2003, 2008 IBM Corporation and others.
* 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
@ -7,14 +7,15 @@
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
*
* 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
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancellation of archive operations
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
*******************************************************************************/
package org.eclipse.rse.services.clientserver.archiveutils;
@ -22,13 +23,18 @@ package org.eclipse.rse.services.clientserver.archiveutils;
import java.io.File;
import java.io.IOException;
import org.eclipse.rse.internal.services.Activator;
import org.eclipse.rse.services.clientserver.ISystemOperationMonitor;
import org.eclipse.rse.services.clientserver.SystemEncodingUtil;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.services.clientserver.messages.SystemOperationFailedException;
import org.eclipse.rse.services.clientserver.messages.SystemUnexpectedErrorException;
/**
* @author mjberger
* A simple structure for passing information about virtual files and folders.
*
* @author mjberger
*/
public final class VirtualChild {
@ -39,7 +45,7 @@ public final class VirtualChild {
protected ISystemArchiveHandler _handler;
protected File _extractedFile;
protected File _containingArchive;
private String comment;
private long compressedSize;
private String compressionMethod;
@ -50,8 +56,8 @@ public final class VirtualChild {
* Constructs a new VirtualChild given a reference to its parent archive's
* handler, but does not populate any fields in the child. Clients must
* populate the fullName, name, path, and isDirectory fields.
*/
public VirtualChild(ISystemArchiveHandler handler)
*/
public VirtualChild(ISystemArchiveHandler handler)
{
fullName = ""; //$NON-NLS-1$
name = ""; //$NON-NLS-1$
@ -60,14 +66,14 @@ public final class VirtualChild {
_handler = handler;
_extractedFile = null;
_containingArchive = null;
comment = ""; //$NON-NLS-1$
compressedSize = -1;
compressionMethod = ""; //$NON-NLS-1$
size = -1;
timeStamp = -1;
timeStamp = -1;
}
/**
* Constructs a new VirtualChild given a reference to its parent archive's
* handler (<code>handler</code>), and immediately populates the name and path info
@ -79,9 +85,9 @@ public final class VirtualChild {
this(handler);
renameTo(fullVirtualName);
}
/**
* Constructs a new VirtualChild given the name of its parent archive,
* Constructs a new VirtualChild given the name of its parent archive,
* and immediately populates the name and path info
* for the VirtualChild given its <code>fullVirtualName</code>. Clients
* must still populate the isDirectory field.
@ -94,7 +100,7 @@ public final class VirtualChild {
renameTo(fullVirtualName);
_containingArchive = containingArchive;
}
/**
* @return This VirtualChild's parent archive's Handler.
*/
@ -102,7 +108,7 @@ public final class VirtualChild {
{
return _handler;
}
/**
* @return This VirtualChild's time stamp (retrieves the latest one
* from the archive).
@ -115,15 +121,15 @@ public final class VirtualChild {
*/
return timeStamp;
}
/**
* @param value the time stamp value
*/
public void setTimeStamp(long value)
public void setTimeStamp(long value)
{
timeStamp = value;
}
/**
* @return This VirtualChild's uncompressed size (retrieves the latest one
* from the archive).
@ -136,19 +142,19 @@ public final class VirtualChild {
*/
return size;
}
/**
* @param value the size value
*/
public void setSize(long value)
public void setSize(long value)
{
size = value;
}
/**
* @return The comment associated with this VirtualChild.
*/
public String getComment()
public String getComment()
{
/*
if (_handler == null) return ""; //$NON-NLS-1$
@ -156,11 +162,11 @@ public final class VirtualChild {
*/
return comment;
}
/**
* @param value the comment value
*/
public void setComment(String value)
public void setComment(String value)
{
if (null != value)
{
@ -176,7 +182,7 @@ public final class VirtualChild {
* @return The amount of space this VirtualChild takes up in the archive
* in compressed form.
*/
public long getCompressedSize()
public long getCompressedSize()
{
/*
if (_handler == null) return 0;
@ -184,11 +190,11 @@ public final class VirtualChild {
*/
return compressedSize;
}
/**
* @param value the compressedSize value
*/
public void setCompressedSize(long value)
public void setCompressedSize(long value)
{
compressedSize = value;
}
@ -196,7 +202,7 @@ public final class VirtualChild {
/**
* @return The method used to compress this VirtualChild.
*/
public String getCompressionMethod()
public String getCompressionMethod()
{
/*
if (_handler == null) return ""; //$NON-NLS-1$
@ -208,7 +214,7 @@ public final class VirtualChild {
/**
* @param value the compression method value
*/
public void setCompressionMethod(String value)
public void setCompressionMethod(String value)
{
if (null != value)
{
@ -219,12 +225,12 @@ public final class VirtualChild {
compressionMethod = ""; //$NON-NLS-1$
}
}
/**
* @return The actual minus compressed size of this VirtualChild, divided
* by the actual size.
*/
public double getCompressionRatio()
public double getCompressionRatio()
{
/*
if (getSize() == 0)
@ -241,29 +247,29 @@ public final class VirtualChild {
{
return 1;
}
return ((double)size - (double)compressedSize) / size;
}
/**
* @return The extracted file or directory represented by this VirtualChild from the archive.
* Note that the extracted file is cached after it is extracted once, but if the
* Note that the extracted file is cached after it is extracted once, but if the
* timestamps on the cached and archived files do not match, the cached file is erased,
* and reextracted from the archive.
*/
public File getExtractedFile()
public File getExtractedFile() throws SystemMessageException
{
return getExtractedFile(SystemEncodingUtil.ENCODING_UTF_8, false, null);
}
/**
* @return The extracted file or directory represented by this VirtualChild from the archive.
* Assumes that the file has been encoded in the encoding specified.
* Note that the extracted file is cached after it is extracted once, but if the
* Note that the extracted file is cached after it is extracted once, but if the
* timestamps on the cached and archived files do not match, the cached file is erased,
* and reextracted from the archive.
*/
public File getExtractedFile(String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor)
public File getExtractedFile(String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException
{
File returnedFile = null;
if (_extractedFile == null || _extractedFile.lastModified() != getTimeStamp())
@ -307,11 +313,10 @@ public final class VirtualChild {
}
catch (IOException e)
{
System.out.println("VirtualChild.getExtractedFile(): "); //$NON-NLS-1$
System.out.println(e.getMessage());
throw new SystemOperationFailedException(Activator.PLUGIN_ID, "VirtualChild.getExtractedFile()", e); //$NON-NLS-1$
}
}
if (isDirectory)
{
returnedFile = new File(_extractedFile, name);
@ -320,77 +325,80 @@ public final class VirtualChild {
{
returnedFile = _extractedFile;
}
//We only set the status of the archive operation montor to done if it is not been cancelled.
if (null != archiveOperationMonitor && !archiveOperationMonitor.isCancelled())
{
archiveOperationMonitor.setDone(true);
}
return returnedFile;
}
/**
* Gets the extracted file or directory represented by this VirtualChild from the archive,
* and replaces the object referred to by <code>destination</code> with that extracted file or directory.
* Note that the extracted file is cached after it is extracted once, but if the
* timestamps on the cached and archived files do not match, the cached file is erased,
* and reextracted from the archive.
* <code>destination</code> is always overwritten with either what is cached, or
* what is in the archive.
* @return true if and only if the extraction succeeded.
* Gets the extracted file or directory represented by this VirtualChild
* from the archive, and replaces the object referred to by
* <code>destination</code> with that extracted file or directory. Note that
* the extracted file is cached after it is extracted once, but if the
* timestamps on the cached and archived files do not match, the cached file
* is erased, and reextracted from the archive. <code>destination</code> is
* always overwritten with either what is cached, or what is in the archive.
*
* @throws SystemMessageException in case of an error
*/
public boolean getExtractedFile(File destination, ISystemOperationMonitor archiveOperationMonitor)
public void getExtractedFile(File destination, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException
{
return getExtractedFile(destination, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor);
getExtractedFile(destination, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor);
}
/**
* Gets the extracted file or directory represented by this VirtualChild from the archive,
* and replaces the object referred to by <code>destination</code> with that extracted file or directory.
* Note that the extracted file is cached after it is extracted once, but if the
* timestamps on the cached and archived files do not match, the cached file is erased,
* and reextracted from the archive.
* <code>destination</code> is always overwritten with either what is cached, or
* what is in the archive.
* @return true if and only if the extraction succeeded.
* Gets the extracted file or directory represented by this VirtualChild
* from the archive, and replaces the object referred to by
* <code>destination</code> with that extracted file or directory. Note that
* the extracted file is cached after it is extracted once, but if the
* timestamps on the cached and archived files do not match, the cached file
* is erased, and reextracted from the archive. <code>destination</code> is
* always overwritten with either what is cached, or what is in the archive.
*
* @throws SystemMessageException in case of an error
*/
public boolean getExtractedFile(File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor)
public void getExtractedFile(File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor)
throws SystemMessageException
{
boolean success = true;
if (_handler == null) return false;
if (_extractedFile == null ||
if (_handler == null)
throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID);
if (_extractedFile == null ||
_extractedFile.lastModified() != getTimeStamp() ||
!destination.getAbsolutePath().equals(_extractedFile.getAbsolutePath())
)
{
if (isDirectory)
{
success = _handler.extractVirtualDirectory(fullName, destination.getParentFile(), destination, sourceEncoding, isText, archiveOperationMonitor);
_handler.extractVirtualDirectory(fullName, destination.getParentFile(), destination, sourceEncoding, isText, archiveOperationMonitor);
}
else
{
success = _handler.extractVirtualFile(fullName, destination, sourceEncoding, isText, archiveOperationMonitor);
_handler.extractVirtualFile(fullName, destination, sourceEncoding, isText, archiveOperationMonitor);
}
_extractedFile = destination;
}
//We only set the status of the archive operation montor to done if it is not been cancelled.
//We only set the status of the archive operation monitor to done if it is not been cancelled.
if (null != archiveOperationMonitor && !archiveOperationMonitor.isCancelled())
{
archiveOperationMonitor.setDone(true);
}
return success;
}
/**
* @return Whether or not this VirtualChild exists in the archive.
*/
public boolean exists()
public boolean exists() throws SystemMessageException
{
if (_handler == null) return false;
return _handler.exists(fullName, null);
}
/**
* Renames this virtual child to newName. WARNING!!
* This method does not change the underlying zip file,
@ -414,9 +422,9 @@ public final class VirtualChild {
}
// force reextraction of temp file
_extractedFile = null;
}
/**
* @return The "standard" name for this VirtualChild, based on
* the handler type.
@ -426,12 +434,12 @@ public final class VirtualChild {
if (_handler == null) return fullName;
return _handler.getStandardName(this);
}
public File getContainingArchive()
{
if (_handler == null) return _containingArchive;
return _handler.getArchive();
}
}