1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-18 21:55: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. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* Noriaki Takatsu (IBM) [220126] [dstore][api][breaking] Single process server for multiple clients * 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 * 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 * 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 * 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; 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 * The DataStore framework knows how to load and route commands to miners
* because it interfaces miners through the restricted set of interfaces declared here. * 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. * 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 * @noinstantiate This class is not intended to be instantiated by clients. The dstore server infrastructure
* will take care of loading the Miner. * 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 * @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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,13 +7,14 @@
* *
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir, * component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* {Name} (company) - description of contribution. * {Name} (company) - description of contribution.
* Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread * 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; 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 class UniversalByteStreamHandler extends ByteStreamHandler
{ {
public UniversalByteStreamHandler(DataStore dataStore, DataElement log) public UniversalByteStreamHandler(DataStore dataStore, DataElement log)
{ {
super(dataStore, 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 * 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 remotePath the path where to save the file
* @param buffer the bytes to insert in 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) public void receiveBytes(String remotePath, byte[] buffer, int size, boolean binary)
{ {
boolean isVirtual = ArchiveHandlerManager.isVirtual(remotePath); boolean isVirtual = ArchiveHandlerManager.isVirtual(remotePath);
if (!isVirtual) if (!isVirtual)
{ {
super.receiveBytes(remotePath, buffer, size, binary); super.receiveBytes(remotePath, buffer, size, binary);
@ -79,11 +80,11 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
String virtualFileName = fileName; String virtualFileName = fileName;
ArchiveHandlerManager mgr = ArchiveHandlerManager.getInstance(); ArchiveHandlerManager mgr = ArchiveHandlerManager.getInstance();
VirtualChild child = mgr.getVirtualObject(virtualFileName);
ISystemArchiveHandler handler = child.getHandler();
try try
{ {
VirtualChild child = mgr.getVirtualObject(virtualFileName);
ISystemArchiveHandler handler = child.getHandler();
File file = child.getExtractedFile(); File file = child.getExtractedFile();
fileName = file.getAbsolutePath(); fileName = file.getAbsolutePath();
@ -128,20 +129,12 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
String filePath = virtualFileName.substring(0, virtualIndex); String filePath = virtualFileName.substring(0, virtualIndex);
handler = mgr.getRegisteredHandler(new File(filePath)); handler = mgr.getRegisteredHandler(new File(filePath));
} }
boolean success = handler != null && handler.add(newFile, child.path, child.name, null); if (handler != null)
if (!success) handler.add(newFile, child.path, child.name, null);
{ if (status == null)
if (status == null) return; return;
status.setAttribute(DE.A_VALUE, IClientServerConstants.FILEMSG_REMOTE_SAVE_FAILED); status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); _dataStore.refresh(status.getParent());
_dataStore.refresh(status.getParent());
}
else
{
if (status == null) return;
status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
_dataStore.refresh(status.getParent());
}
} }
catch (IOException e) 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 * 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 remotePath the path where to save the file
* @param buffer the bytes to append in 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) public void receiveAppendedBytes(String remotePath, byte[] buffer, int size, boolean binary)
{ {
boolean isVirtual = ArchiveHandlerManager.isVirtual(remotePath); boolean isVirtual = ArchiveHandlerManager.isVirtual(remotePath);
if (!isVirtual) if (!isVirtual)
{ {
@ -188,20 +181,15 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
if (fileName != null) if (fileName != null)
{ {
String virtualFileName = fileName; 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 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(); File file = child.getExtractedFile();
fileName = file.getAbsolutePath(); fileName = file.getAbsolutePath();
@ -242,7 +230,9 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
String filePath = virtualFileName.substring(0, virtualIndex); String filePath = virtualFileName.substring(0, virtualIndex);
handler = mgr.getRegisteredHandler(new File(filePath)); 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 else
@ -308,7 +298,7 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
// remote old file // remote old file
oldFile.delete(); oldFile.delete();
// rename new file // rename new file
newFile.renameTo(oldFile); newFile.renameTo(oldFile);
// write the temp file to the archive // write the temp file to the archive
@ -318,25 +308,17 @@ public class UniversalByteStreamHandler extends ByteStreamHandler
String filePath = virtualFileName.substring(0, virtualIndex); String filePath = virtualFileName.substring(0, virtualIndex);
handler = mgr.getRegisteredHandler(new File(filePath)); 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 (status == null)
return;
if (!success) status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
{ _dataStore.refresh(status.getParent());
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());
}
} }
catch (IOException e) catch (Exception e)
{ {
_dataStore.trace(e); _dataStore.trace(e);
if (status == null) return; if (status == null) return;

View file

@ -8,10 +8,11 @@
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight. * component that contains this file: David McKnight.
* *
* Contributors: * Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * 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 * 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; 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.AbsoluteVirtualPath;
import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler;
import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; 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) public CopyBatchThread(DataElement targetFolder, DataElement theElement, UniversalFileSystemMiner miner, boolean isWindows, DataElement status)
{ {
super(targetFolder, theElement, miner, isWindows, status); super(targetFolder, theElement, miner, isWindows, status);
} }
public void run() public void run()
{ {
super.run(); super.run();
handleCopyBatch(); try {
handleCopyBatch();
} catch (SystemMessageException e) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
miner.statusDone(status);
}
_isDone = true; _isDone = true;
} }
private DataElement handleCopyBatch() private DataElement handleCopyBatch() throws SystemMessageException
{ {
String targetType = targetFolder.getType(); String targetType = targetFolder.getType();
File tgtFolder = getFileFor(targetFolder); File tgtFolder = getFileFor(targetFolder);
int numOfSources = theElement.getNestedSize() - 2; int numOfSources = theElement.getNestedSize() - 2;
systemOperationMonitor = new SystemOperationMonitor(); 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 // if target is virtual or an archive, insert into an archive
AbsoluteVirtualPath vpath = miner.getAbsoluteVirtualPath(targetFolder); AbsoluteVirtualPath vpath = miner.getAbsoluteVirtualPath(targetFolder);
ISystemArchiveHandler handler = miner.getArchiveHandlerFor(vpath.getContainingArchiveString()); ISystemArchiveHandler handler = miner.getArchiveHandlerFor(vpath.getContainingArchiveString());
boolean result = true; boolean result = true;
if (handler == null)
{
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
return miner.statusDone(status);
}
List nonDirectoryArrayList = new ArrayList(); List nonDirectoryArrayList = new ArrayList();
List nonDirectoryNamesArrayList = new ArrayList(); List nonDirectoryNamesArrayList = new ArrayList();
String virtualContainer = ""; //$NON-NLS-1$ String virtualContainer = ""; //$NON-NLS-1$
if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR))
{ {
virtualContainer = vpath.getVirtualPart(); virtualContainer = vpath.getVirtualPart();
} }
for (int i = 0; i < numOfSources; i++) for (int i = 0; i < numOfSources; i++)
{ {
if (isCancelled()) if (isCancelled())
@ -86,21 +87,21 @@ public class CopyBatchThread extends CopyThread {
File srcFile; File srcFile;
if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) 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); 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); AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile);
ISystemArchiveHandler shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); ISystemArchiveHandler shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString());
if (shandler == null) if (shandler == null)
{ {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
return miner.statusDone(status); return miner.statusDone(status);
} }
VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart(), systemOperationMonitor); VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart(), systemOperationMonitor);
srcFile = child.getExtractedFile(); srcFile = child.getExtractedFile();
} }
@ -109,15 +110,16 @@ public class CopyBatchThread extends CopyThread {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
return miner.statusDone(status); 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. //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 //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. //call ISystemArchiveHandler#add(File[] ...) to add them in batch.
if (srcFile.isDirectory()) if (srcFile.isDirectory())
{ {
result = handler.add(srcFile, virtualContainer, srcName, systemOperationMonitor); try {
if (!result) { handler.add(srcFile, virtualContainer, srcName, systemOperationMonitor);
} catch (SystemMessageException e) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
if (isCancelled()) if (isCancelled())
{ {
@ -127,6 +129,7 @@ public class CopyBatchThread extends CopyThread {
{ {
return miner.statusDone(status); return miner.statusDone(status);
} }
} }
} }
else else
@ -135,15 +138,19 @@ public class CopyBatchThread extends CopyThread {
nonDirectoryNamesArrayList.add(srcName); nonDirectoryNamesArrayList.add(srcName);
} }
} }
if (nonDirectoryArrayList.size() > 0) if (nonDirectoryArrayList.size() > 0)
{ {
File[] resultFiles = (File[])nonDirectoryArrayList.toArray(new File[nonDirectoryArrayList.size()]); File[] resultFiles = (File[])nonDirectoryArrayList.toArray(new File[nonDirectoryArrayList.size()]);
String[] resultNames = (String[])nonDirectoryNamesArrayList.toArray(new String[nonDirectoryNamesArrayList.size()]); String[] resultNames = (String[])nonDirectoryNamesArrayList.toArray(new String[nonDirectoryNamesArrayList.size()]);
//we need to add those files into the archive file as well. //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) if (result)
{ {
status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
@ -176,42 +183,38 @@ public class CopyBatchThread extends CopyThread {
} }
DataElement sourceFile = miner.getCommandArgument(theElement, i+1); DataElement sourceFile = miner.getCommandArgument(theElement, i+1);
String srcType = sourceFile.getType(); 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 // extract from an archive to folder
AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile); try {
ISystemArchiveHandler shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile);
ISystemArchiveHandler shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString());
if (shandler == null) 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); status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
return miner.statusDone(status); 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 else // source is regular file or folder
{ {
File srcFile = getFileFor(sourceFile); File srcFile = getFileFor(sourceFile);
folderCopy = folderCopy || srcFile.isDirectory(); folderCopy = folderCopy || srcFile.isDirectory();
String src = srcFile.getAbsolutePath(); String src = srcFile.getAbsolutePath();
// handle special characters in source and target strings // handle special characters in source and target strings
src = enQuote(src); src = enQuote(src);
// handle window case separately, since xcopy command could not handler // handle window case separately, since xcopy command could not handler
// multiple source names // multiple source names
if (isWindows) if (isWindows)
@ -234,13 +237,13 @@ public class CopyBatchThread extends CopyThread {
source = source + " " + src; //$NON-NLS-1$ source = source + " " + src; //$NON-NLS-1$
} }
numOfNonVirtualSources++; numOfNonVirtualSources++;
} }
} // end for loop iterating through sources } // end for loop iterating through sources
if (numOfNonVirtualSources > 0) if (numOfNonVirtualSources > 0)
{ {
doCopyCommand(source, tgt, folderCopy, status); doCopyCommand(source, tgt, folderCopy, status);
} }
} // end if/then/else (target is regular folder) } // end if/then/else (target is regular folder)
if (isCancelled()) if (isCancelled())
{ {
@ -251,7 +254,7 @@ public class CopyBatchThread extends CopyThread {
return miner.statusDone(status); return miner.statusDone(status);
} }
} }
} }

View file

@ -8,10 +8,11 @@
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight. * component that contains this file: David McKnight.
* *
* Contributors: * Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * 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 * 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; 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.ArchiveHandlerManager;
import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler;
import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; 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; private DataElement nameObj;
public CopySingleThread(DataElement targetFolder, DataElement theElement, DataElement nameObj, UniversalFileSystemMiner miner, boolean isWindows, DataElement status) public CopySingleThread(DataElement targetFolder, DataElement theElement, DataElement nameObj, UniversalFileSystemMiner miner, boolean isWindows, DataElement status)
{ {
super(targetFolder, theElement, miner, isWindows, status); super(targetFolder, theElement, miner, isWindows, status);
this.nameObj = nameObj; this.nameObj = nameObj;
} }
public void run() public void run()
{ {
super.run(); super.run();
handleCopy(); try {
handleCopy();
} catch (SystemMessageException e) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
miner.statusDone(status);
}
_isDone = true; _isDone = true;
} }
private DataElement handleCopy() private DataElement handleCopy() throws SystemMessageException
{ {
DataElement sourceFile = theElement; DataElement sourceFile = theElement;
String newName = nameObj.getName(); String newName = nameObj.getName();
String targetType = targetFolder.getType(); String targetType = targetFolder.getType();
String srcType = sourceFile.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. //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. //We need to find out its real type first before going to different if statement.
File srcFile = null; File srcFile = null;
@ -64,25 +71,25 @@ public class CopySingleThread extends CopyThread {
{ {
String goodFullName = ArchiveHandlerManager.cleanUpVirtualPath(sourceFile.getValue()); String goodFullName = ArchiveHandlerManager.cleanUpVirtualPath(sourceFile.getValue());
child = ArchiveHandlerManager.getInstance().getVirtualObject(goodFullName); child = ArchiveHandlerManager.getInstance().getVirtualObject(goodFullName);
if (child.exists()) if (child.exists())
{ {
if (child.isDirectory) if (child.isDirectory)
{ {
srcType = IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR; srcType = IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR;
} else } else
{ {
srcType = IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR; srcType = IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR;
} }
} }
} }
} }
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)) {
// insert into an archive // insert into an archive
AbsoluteVirtualPath vpath = miner.getAbsoluteVirtualPath(targetFolder); AbsoluteVirtualPath vpath = miner.getAbsoluteVirtualPath(targetFolder);
ISystemArchiveHandler handler = miner.getArchiveHandlerFor(vpath.getContainingArchiveString()); ISystemArchiveHandler handler = miner.getArchiveHandlerFor(vpath.getContainingArchiveString());
if (handler == null) { if (handler == null) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
return miner.statusDone(status); 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) 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); 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)) {
@ -99,7 +106,7 @@ public class CopySingleThread extends CopyThread {
{ {
AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile); AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile);
shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString());
if (shandler == null) { if (shandler == null) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
return miner.statusDone(status); return miner.statusDone(status);
@ -115,19 +122,12 @@ public class CopySingleThread extends CopyThread {
} }
String virtualContainer = ""; //$NON-NLS-1$ String virtualContainer = ""; //$NON-NLS-1$
if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) {
virtualContainer = vpath.getVirtualPart(); virtualContainer = vpath.getVirtualPart();
} }
boolean result = handler.add(srcFile, virtualContainer, newName, systemOperationMonitor); handler.add(srcFile, virtualContainer, newName, systemOperationMonitor);
if (result) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
}
else {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
}
} }
else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) {
ISystemArchiveHandler shandler = null; ISystemArchiveHandler shandler = null;
@ -136,7 +136,7 @@ public class CopySingleThread extends CopyThread {
{ {
svpath = miner.getAbsoluteVirtualPath(sourceFile); svpath = miner.getAbsoluteVirtualPath(sourceFile);
shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString());
if (shandler == null) { if (shandler == null) {
status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
return miner.statusDone(status); return miner.statusDone(status);
@ -152,7 +152,7 @@ public class CopySingleThread extends CopyThread {
File parentDir = getFileFor(targetFolder); File parentDir = getFileFor(targetFolder);
File destination = new File(parentDir, newName); File destination = new File(parentDir, newName);
if (child.isDirectory) { if (child.isDirectory) {
shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination, systemOperationMonitor); shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination, systemOperationMonitor);
} }
@ -169,7 +169,7 @@ public class CopySingleThread extends CopyThread {
String src = srcFile.getAbsolutePath(); String src = srcFile.getAbsolutePath();
String tgt = tgtFolder.getAbsolutePath() + File.separatorChar + newName; String tgt = tgtFolder.getAbsolutePath() + File.separatorChar + newName;
File tgtFile = new File(tgt); File tgtFile = new File(tgt);
if (tgtFile.exists() && tgtFile.isDirectory()) if (tgtFile.exists() && tgtFile.isDirectory())
{ {
//For Windows, we need to use xcopy command, which require the new directory //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(); tgt = tgtFolder.getAbsolutePath();
} }
} }
doCopyCommand(enQuote(src), enQuote(tgt), folderCopy, status); doCopyCommand(enQuote(src), enQuote(tgt), folderCopy, status);
} }
return miner.statusDone(status); return miner.statusDone(status);
} }
} }

View file

@ -8,10 +8,11 @@
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight. * component that contains this file: David McKnight.
* *
* Contributors: * Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * 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 * 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; 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.DE;
import org.eclipse.dstore.core.model.DataElement; import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.dstore.core.model.DataStore; 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.ICancellableHandler;
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; 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.AbsoluteVirtualPath;
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; 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 { public class CreateFileThread extends SecuredThread implements ICancellableHandler {
@ -37,14 +39,14 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl
protected DataElement _status; protected DataElement _status;
protected UniversalFileSystemMiner _miner; protected UniversalFileSystemMiner _miner;
protected String _queryType; protected String _queryType;
protected boolean _isCancelled = false; protected boolean _isCancelled = false;
protected boolean _isDone = false; protected boolean _isDone = false;
protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor();
public static final String CLASSNAME = "CreateFileThread"; //$NON-NLS-1$ public static final String CLASSNAME = "CreateFileThread"; //$NON-NLS-1$
public CreateFileThread(DataElement theElement, String queryType, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status) public CreateFileThread(DataElement theElement, String queryType, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status)
{ {
super(dataStore); super(dataStore);
@ -53,9 +55,9 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl
this._status = status; this._status = status;
this._queryType = queryType; this._queryType = queryType;
} }
public void cancel() { public void cancel() {
_isCancelled = true; _isCancelled = true;
@ -72,16 +74,20 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl
public boolean isDone() { public boolean isDone() {
return _isDone; return _isDone;
} }
public void run() public void run()
{ {
super.run(); super.run();
try {
handleCreateFile(); handleCreateFile();
} catch (SystemMessageException e) {
_status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
_miner.statusDone(_status);
}
_isDone = true; _isDone = true;
} }
private DataElement handleCreateFile() private DataElement handleCreateFile() throws SystemMessageException
{ {
boolean wasFilter = _queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR); boolean wasFilter = _queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR);
if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) { if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) {
@ -115,11 +121,9 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl
try { try {
boolean done = filename.createNewFile(); boolean done = filename.createNewFile();
if (ArchiveHandlerManager.getInstance().isArchive(filename)) { if (ArchiveHandlerManager.getInstance().isArchive(filename)) {
done = ArchiveHandlerManager.getInstance() ArchiveHandlerManager.getInstance()
.createEmptyArchive(filename); .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 { } else {
if (done) if (done)
{ {
@ -152,9 +156,9 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl
_dataStore.refresh(_subject); _dataStore.refresh(_subject);
return _miner.statusDone(_status); return _miner.statusDone(_status);
} }
public DataElement handleCreateVirtualFile(DataElement subject, public DataElement handleCreateVirtualFile(DataElement subject,
DataElement status, String type) { DataElement status, String type) throws SystemMessageException {
AbsoluteVirtualPath vpath = null; AbsoluteVirtualPath vpath = null;
if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) {

View file

@ -8,10 +8,11 @@
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight. * component that contains this file: David McKnight.
* *
* Contributors: * Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * 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 * 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; 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.DE;
import org.eclipse.dstore.core.model.DataElement; import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.dstore.core.model.DataStore; 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.ICancellableHandler;
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; 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.AbsoluteVirtualPath;
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; 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 { public class CreateFolderThread extends SecuredThread implements ICancellableHandler {
@ -37,14 +39,14 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan
protected DataElement _status; protected DataElement _status;
protected UniversalFileSystemMiner _miner; protected UniversalFileSystemMiner _miner;
protected String _queryType; protected String _queryType;
protected boolean _isCancelled = false; protected boolean _isCancelled = false;
protected boolean _isDone = false; protected boolean _isDone = false;
protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor();
public static final String CLASSNAME = "CreateFileThread"; //$NON-NLS-1$ public static final String CLASSNAME = "CreateFileThread"; //$NON-NLS-1$
public CreateFolderThread(DataElement theElement, String queryType, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status) public CreateFolderThread(DataElement theElement, String queryType, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status)
{ {
super(dataStore); super(dataStore);
@ -53,9 +55,9 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan
this._status = status; this._status = status;
this._queryType = queryType; this._queryType = queryType;
} }
public void cancel() { public void cancel() {
_isCancelled = true; _isCancelled = true;
@ -72,37 +74,42 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan
public boolean isDone() { public boolean isDone() {
return _isDone; return _isDone;
} }
public void run() public void run()
{ {
super.run(); super.run();
handleCreateFile(); try {
handleCreateFile();
} catch (SystemMessageException e) {
_status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
_miner.statusDone(_status);
}
_isDone = true; _isDone = true;
} }
private DataElement handleCreateFile() private DataElement handleCreateFile() throws SystemMessageException
{ {
if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) {
return handleCreateVirtualFolder(_subject, _status, _queryType); return handleCreateVirtualFolder(_subject, _status, _queryType);
} }
File filename = null; File filename = null;
if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR))
{ {
if (_subject.getName().indexOf( if (_subject.getName().indexOf(
ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0) ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0)
{ {
_subject.setAttribute(DE.A_TYPE, _subject.setAttribute(DE.A_TYPE,
IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR); IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR);
return handleCreateVirtualFolder(_subject, _status, _queryType); return handleCreateVirtualFolder(_subject, _status, _queryType);
} }
else else
{ {
filename = new File(_subject.getValue()); filename = new File(_subject.getValue());
_subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR); _subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR);
_subject.setAttribute(DE.A_SOURCE, _miner.setProperties(filename)); _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(filename));
} }
} }
else if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR)) else if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR))
{ {
filename = new File(_subject.getValue()); filename = new File(_subject.getValue());
@ -115,23 +122,23 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan
{ {
if (filename.exists()) if (filename.exists())
_status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXIST); _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXIST);
else else
{ {
try { try {
boolean done = filename.mkdirs(); boolean done = filename.mkdirs();
if (done) if (done)
{ {
_status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); _status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
_subject.setAttribute(DE.A_SOURCE, _miner.setProperties(filename)); _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(filename));
_subject.setAttribute(DE.A_TYPE,IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR); _subject.setAttribute(DE.A_TYPE,IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR);
_subject.setAttribute(DE.A_NAME, filename.getName()); _subject.setAttribute(DE.A_NAME, filename.getName());
_subject.setAttribute(DE.A_VALUE, filename.getParentFile().getAbsolutePath()); _subject.setAttribute(DE.A_VALUE, filename.getParentFile().getAbsolutePath());
} }
else else
{ {
_status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
} }
} catch (Exception e) { } catch (Exception e) {
UniversalServerUtilities.logError(CLASSNAME, UniversalServerUtilities.logError(CLASSNAME,
"handleCreateFolder failed", e, _dataStore); //$NON-NLS-1$ "handleCreateFolder failed", e, _dataStore); //$NON-NLS-1$
@ -142,9 +149,9 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan
_dataStore.refresh(_subject); _dataStore.refresh(_subject);
return _miner.statusDone(_status); return _miner.statusDone(_status);
} }
public DataElement handleCreateVirtualFolder(DataElement subject, public DataElement handleCreateVirtualFolder(DataElement subject,
DataElement status, String type) { DataElement status, String type) throws SystemMessageException {
AbsoluteVirtualPath vpath = null; AbsoluteVirtualPath vpath = null;
if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) {

View file

@ -8,10 +8,11 @@
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight. * component that contains this file: David McKnight.
* *
* Contributors: * Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * 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 * 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; 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.DE;
import org.eclipse.dstore.core.model.DataElement; import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.dstore.core.model.DataStore; 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.ICancellableHandler;
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; 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.AbsoluteVirtualPath;
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; 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 { public class DeleteThread extends SecuredThread implements ICancellableHandler {
@ -37,14 +39,14 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
protected DataElement _status; protected DataElement _status;
protected UniversalFileSystemMiner _miner; protected UniversalFileSystemMiner _miner;
protected boolean _batch; protected boolean _batch;
protected boolean _isCancelled = false; protected boolean _isCancelled = false;
protected boolean _isDone = false; protected boolean _isDone = false;
protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor();
public static final String CLASSNAME = "DeleteThread"; //$NON-NLS-1$ public static final String CLASSNAME = "DeleteThread"; //$NON-NLS-1$
public DeleteThread(DataElement theElement, UniversalFileSystemMiner miner, DataStore dataStore, boolean batch, DataElement status) public DeleteThread(DataElement theElement, UniversalFileSystemMiner miner, DataStore dataStore, boolean batch, DataElement status)
{ {
super(dataStore); super(dataStore);
@ -53,9 +55,9 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
this._status = status; this._status = status;
this._batch = batch; this._batch = batch;
} }
public void cancel() { public void cancel() {
_isCancelled = true; _isCancelled = true;
@ -72,22 +74,24 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
public boolean isDone() { public boolean isDone() {
return _isDone; return _isDone;
} }
public void run() public void run()
{ {
super.run(); super.run();
if (_batch) try {
{ if (_batch) {
handleDeleteBatch(); handleDeleteBatch();
} } else {
else handleDelete(_theElement, _status);
{ }
handleDelete(_theElement, _status); } catch (SystemMessageException e) {
_status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
_miner.statusDone(_status);
} }
_isDone = true; _isDone = true;
} }
private DataElement handleDeleteBatch() private DataElement handleDeleteBatch() throws SystemMessageException
{ {
DataElement substatus = _dataStore.createObject(null, "status", "substatus"); //$NON-NLS-1$ //$NON-NLS-2$ DataElement substatus = _dataStore.createObject(null, "status", "substatus"); //$NON-NLS-1$ //$NON-NLS-2$
int numOfSources = _theElement.getNestedSize() - 2; int numOfSources = _theElement.getNestedSize() - 2;
@ -100,7 +104,7 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
DataElement subject = _miner.getCommandArgument(_theElement, i+1); DataElement subject = _miner.getCommandArgument(_theElement, i+1);
handleDelete(subject, substatus); handleDelete(subject, substatus);
/* /*
if (!substatus.getSource().startsWith(IServiceConstants.SUCCESS)) if (!substatus.getSource().startsWith(IServiceConstants.SUCCESS))
{ {
status.setAttribute(DE.A_SOURCE, substatus.getSource()); status.setAttribute(DE.A_SOURCE, substatus.getSource());
return statusDone(status); return statusDone(status);
@ -110,7 +114,7 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
_status.setAttribute(DE.A_SOURCE, substatus.getSource()); _status.setAttribute(DE.A_SOURCE, substatus.getSource());
return _miner.statusDone(_status); return _miner.statusDone(_status);
} }
private DataElement handleDelete(DataElement subject, DataElement thisStatus) private DataElement handleDelete(DataElement subject, DataElement thisStatus) throws SystemMessageException
{ {
String type = subject.getType(); String type = subject.getType();
@ -172,11 +176,11 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
} }
_dataStore.refresh(subject); _dataStore.refresh(subject);
return _miner.statusDone(_status); return _miner.statusDone(_status);
} }
public DataElement handleDeleteFromArchive(DataElement subject, public DataElement handleDeleteFromArchive(DataElement subject,
DataElement status) { DataElement status) throws SystemMessageException {
String type = subject.getType(); String type = subject.getType();
DataElement deObj = null; DataElement deObj = null;
@ -207,10 +211,10 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
_dataStore.refresh(subject); _dataStore.refresh(subject);
return _miner.statusDone(status); return _miner.statusDone(status);
} }
/** /**
* Delete directory and its children. * Delete directory and its children.
* *
*/ */
public void deleteDir(File fileObj, DataElement status) { public void deleteDir(File fileObj, DataElement status) {
try { try {
@ -238,5 +242,5 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler {
"Deletion of dir failed", e, _dataStore); //$NON-NLS-1$ "Deletion of dir failed", e, _dataStore); //$NON-NLS-1$
} }
} }
} }

View file

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

View file

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

View file

@ -8,10 +8,11 @@
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight. * component that contains this file: David McKnight.
* *
* Contributors: * Contributors:
* Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * 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 * 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; 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.DE;
import org.eclipse.dstore.core.model.DataElement; import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.dstore.core.model.DataStore; 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.ICancellableHandler;
import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner;
import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; 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.AbsoluteVirtualPath;
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; 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 { public class RenameThread extends SecuredThread implements ICancellableHandler {
protected DataElement _subject; protected DataElement _subject;
protected DataElement _status; protected DataElement _status;
protected UniversalFileSystemMiner _miner; protected UniversalFileSystemMiner _miner;
protected boolean _isCancelled = false; protected boolean _isCancelled = false;
protected boolean _isDone = false; protected boolean _isDone = false;
protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor();
public static final String CLASSNAME = "RenameThread"; //$NON-NLS-1$ public static final String CLASSNAME = "RenameThread"; //$NON-NLS-1$
public RenameThread(DataElement theElement, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status) public RenameThread(DataElement theElement, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status)
{ {
super(dataStore); super(dataStore);
@ -50,8 +52,8 @@ public class RenameThread extends SecuredThread implements ICancellableHandler {
this._miner = miner; this._miner = miner;
this._status = status; this._status = status;
} }
public void cancel() { public void cancel() {
_isCancelled = true; _isCancelled = true;
@ -68,15 +70,20 @@ public class RenameThread extends SecuredThread implements ICancellableHandler {
public boolean isDone() { public boolean isDone() {
return _isDone; return _isDone;
} }
public void run() public void run()
{ {
super.run(); super.run();
handleRename(); try {
handleRename();
} catch (SystemMessageException e) {
_status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED);
_miner.statusDone(_status);
}
_isDone = true; _isDone = true;
} }
private DataElement handleRename() private DataElement handleRename() throws SystemMessageException
{ {
File fileoldname = new File(_subject.getAttribute(DE.A_VALUE) File fileoldname = new File(_subject.getAttribute(DE.A_VALUE)
+ File.separatorChar + _subject.getName()); + File.separatorChar + _subject.getName());
@ -91,16 +98,14 @@ public class RenameThread extends SecuredThread implements ICancellableHandler {
ISystemArchiveHandler handler = archiveHandlerManager ISystemArchiveHandler handler = archiveHandlerManager
.getRegisteredHandler(new File(oldAbsPath .getRegisteredHandler(new File(oldAbsPath
.getContainingArchiveString())); .getContainingArchiveString()));
boolean success = !(handler == null) if (handler != null) {
&& handler.fullRename(oldAbsPath.getVirtualPart(), handler.fullRename(oldAbsPath.getVirtualPart(), newAbsPath.getVirtualPart(), systemOperationMonitor);
newAbsPath.getVirtualPart(), systemOperationMonitor);
if (success && handler != null) {
_subject.setAttribute(DE.A_NAME, filerename.getName()); _subject.setAttribute(DE.A_NAME, filerename.getName());
_subject.setAttribute(DE.A_SOURCE, _miner.setProperties(handler _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(handler
.getVirtualFile(newAbsPath.getVirtualPart(), systemOperationMonitor))); .getVirtualFile(newAbsPath.getVirtualPart(), systemOperationMonitor)));
_status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); _status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS);
_dataStore.update(_subject); _dataStore.update(_subject);
} }
else if (systemOperationMonitor.isCancelled()) else if (systemOperationMonitor.isCancelled())
{ {
_subject.setAttribute(DE.A_SOURCE, _miner.setProperties(handler _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(handler
@ -140,7 +145,7 @@ public class RenameThread extends SecuredThread implements ICancellableHandler {
_dataStore.refresh(_subject); _dataStore.refresh(_subject);
return _miner.statusDone(_status); return _miner.statusDone(_status);
} }
// DKM: during folder rename we need to recursively update all the parent // DKM: during folder rename we need to recursively update all the parent
// paths // paths
private void updateChildProperties(DataElement subject, File filerename) { private void updateChildProperties(DataElement subject, File filerename) {

View file

@ -7,16 +7,17 @@
* *
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir, * component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* Michael Berger (IBM) - Bug 147791 - symbolic links can cause circular search. * Michael Berger (IBM) - Bug 147791 - symbolic links can cause circular search.
* David McKnight (IBM) - [190010] cancelling search * David McKnight (IBM) - [190010] cancelling search
* Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread * 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 * 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 * 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; 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.DE;
import org.eclipse.dstore.core.model.DataElement; import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.dstore.core.model.DataStore; import org.eclipse.dstore.core.model.DataStore;
import org.eclipse.dstore.core.server.SecuredThread;
import org.eclipse.dstore.core.util.StringCompare; import org.eclipse.dstore.core.util.StringCompare;
import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; import org.eclipse.rse.dstore.universal.miners.ICancellableHandler;
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; 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.AbsoluteVirtualPath;
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; 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.SystemSearchFileNameMatcher;
import org.eclipse.rse.services.clientserver.search.SystemSearchLineMatch; import org.eclipse.rse.services.clientserver.search.SystemSearchLineMatch;
import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatchLocator; import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatchLocator;
import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher; import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher;
import org.eclipse.dstore.core.server.SecuredThread;
public class UniversalSearchHandler extends SecuredThread implements ICancellableHandler public class UniversalSearchHandler extends SecuredThread implements ICancellableHandler
{ {
@ -59,19 +61,19 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
protected UniversalFileSystemMiner _miner; protected UniversalFileSystemMiner _miner;
protected DataElement _status; protected DataElement _status;
protected SystemSearchString _searchString; protected SystemSearchString _searchString;
protected SystemSearchStringMatcher _stringMatcher; protected SystemSearchStringMatcher _stringMatcher;
protected boolean _isFileSearch; protected boolean _isFileSearch;
protected SystemSearchFileNameMatcher _fileNameMatcher; protected SystemSearchFileNameMatcher _fileNameMatcher;
protected String _classificationString; protected String _classificationString;
protected DataElement _deGrep; protected DataElement _deGrep;
protected DataElement _deFile; protected DataElement _deFile;
protected DataElement _deFolder; protected DataElement _deFolder;
protected DataElement _deArchiveFile; protected DataElement _deArchiveFile;
protected DataElement _deVirtualFile; protected DataElement _deVirtualFile;
protected boolean _fsCaseSensitive; protected boolean _fsCaseSensitive;
public UniversalSearchHandler(DataStore dataStore, UniversalFileSystemMiner miner, SystemSearchString searchString, boolean fsCaseSensitive, File theFile, DataElement status) { 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; _searchString = searchString;
_fsCaseSensitive = fsCaseSensitive; _fsCaseSensitive = fsCaseSensitive;
_alreadySearched = new HashSet(); _alreadySearched = new HashSet();
_deGrep = _dataStore.findObjectDescriptor("grep"); //$NON-NLS-1$ _deGrep = _dataStore.findObjectDescriptor("grep"); //$NON-NLS-1$
_deFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR); _deFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR);
_deFolder = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR); _deFolder = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR);
_deArchiveFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR); _deArchiveFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR);
_deVirtualFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR); _deVirtualFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR);
boolean includeSubfolders = searchString.isIncludeSubfolders(); boolean includeSubfolders = searchString.isIncludeSubfolders();
if (includeSubfolders) { if (includeSubfolders) {
_depth = -1; _depth = -1;
} }
else { else {
_depth = 1; _depth = 1;
} }
_rootFile = theFile; _rootFile = theFile;
_status = status; _status = status;
_isCancelled = false; _isCancelled = false;
_isDone = false; _isDone = false;
_stringMatcher = new SystemSearchStringMatcher(_searchString.getTextString(), _searchString.isCaseSensitive(), _searchString.isTextStringRegex()); _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 // 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 // i.e. we do not want to look inside files
_isFileSearch = _stringMatcher.isSearchStringEmpty() || _stringMatcher.isSearchStringAsterisk(); _isFileSearch = _stringMatcher.isSearchStringEmpty() || _stringMatcher.isSearchStringAsterisk();
_fileNameMatcher = new SystemSearchFileNameMatcher(_searchString.getFileNamesString(), fsCaseSensitive, _searchString.isFileNamesRegex()); _fileNameMatcher = new SystemSearchFileNameMatcher(_searchString.getFileNamesString(), fsCaseSensitive, _searchString.isFileNamesRegex());
// classification of files to restrict the search to // classification of files to restrict the search to
_classificationString = _searchString.getClassificationString(); _classificationString = _searchString.getClassificationString();
} }
@ -123,7 +125,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
} }
_isDone = true; _isDone = true;
if (_isCancelled) { if (_isCancelled) {
_miner.statusCancelled(_status); _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 // Otherwise we don't get an event on the client corresponding
// to status refresh. As a result client thinks // to status refresh. As a result client thinks
// search isn't finished. // search isn't finished.
// _miner.statusDone(_status); // _miner.statusDone(_status);
_status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$ _status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$
_dataStore.refresh(_status, true); // true indicates refresh immediately _dataStore.refresh(_status, true); // true indicates refresh immediately
} }
} }
@ -150,10 +152,10 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
} }
public void cancel() { public void cancel() {
_isCancelled = true; _isCancelled = true;
} }
protected boolean hasSearchedDirectory(File file) protected boolean hasSearchedDirectory(File file)
{ {
try 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? // is it a directory?
boolean isDirectory = theFile.isDirectory(); boolean isDirectory = theFile.isDirectory();
// is it an archive? // is it an archive?
boolean isArchive = ArchiveHandlerManager.getInstance().isArchive(theFile); boolean isArchive = ArchiveHandlerManager.getInstance().isArchive(theFile);
String absPath = theFile.getAbsolutePath(); String absPath = theFile.getAbsolutePath();
String compareStr = theFile.getName(); String compareStr = theFile.getName();
// is it a virtual file? // is it a virtual file?
boolean isVirtual = ArchiveHandlerManager.isVirtual(absPath); boolean isVirtual = ArchiveHandlerManager.isVirtual(absPath);
// is it a virtual directory? // is it a virtual directory?
boolean isVirtualDirectory = false; boolean isVirtualDirectory = false;
// if it is a virtual object, then get a reference to it // if it is a virtual object, then get a reference to it
if (isVirtual) { if (isVirtual) {
VirtualChild vc = ArchiveHandlerManager.getInstance().getVirtualObject(absPath); VirtualChild vc = ArchiveHandlerManager.getInstance().getVirtualObject(absPath);
@ -194,38 +196,38 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
// base case for the recursive method call // base case for the recursive method call
// if the file is not a directory, an archive or a virtual directory, // 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 // and we get a match with the file name, then we can search for match within the file
if (!isDirectory && if (!isDirectory &&
(!isArchive || _isFileSearch) && (!isArchive || _isFileSearch) &&
!isVirtualDirectory && !isVirtualDirectory &&
doesFilePatternMatch(compareStr) && doesFilePatternMatch(compareStr) &&
doesClassificationMatch(absPath)) doesClassificationMatch(absPath))
{ {
DataElement deObj = null; DataElement deObj = null;
// if the file is a virtual file, then get matches from the archive handler // if the file is a virtual file, then get matches from the archive handler
if (ArchiveHandlerManager.isVirtual(absPath)) { if (ArchiveHandlerManager.isVirtual(absPath)) {
VirtualChild vc = ArchiveHandlerManager.getInstance().getVirtualObject(absPath); VirtualChild vc = ArchiveHandlerManager.getInstance().getVirtualObject(absPath);
if (!vc.isDirectory) { if (!vc.isDirectory) {
deObj = _dataStore.createObject(null, _deVirtualFile, compareStr); deObj = _dataStore.createObject(null, _deVirtualFile, compareStr);
// if parent of virtual child is archive, then create it this way // if parent of virtual child is archive, then create it this way
if (vc.path.equals("")) { //$NON-NLS-1$ if (vc.path.equals("")) { //$NON-NLS-1$
deObj.setAttribute(DE.A_VALUE, vc.getContainingArchive().getAbsolutePath()); deObj.setAttribute(DE.A_VALUE, vc.getContainingArchive().getAbsolutePath());
} }
else { else {
deObj.setAttribute(DE.A_VALUE, vc.getContainingArchive().getAbsolutePath() + deObj.setAttribute(DE.A_VALUE, vc.getContainingArchive().getAbsolutePath() +
ArchiveHandlerManager.VIRTUAL_SEPARATOR + vc.path); ArchiveHandlerManager.VIRTUAL_SEPARATOR + vc.path);
} }
deObj.setAttribute(DE.A_SOURCE, _miner.setProperties(vc)); deObj.setAttribute(DE.A_SOURCE, _miner.setProperties(vc));
SystemSearchLineMatch[] results = null; SystemSearchLineMatch[] results = null;
// if it's not a file search, call the handler method to search // if it's not a file search, call the handler method to search
if (!_isFileSearch) { if (!_isFileSearch) {
results = vc.getHandler().search(vc.fullName, _stringMatcher, null); results = vc.getHandler().search(vc.fullName, _stringMatcher, null);
// if at least one match found, then send back the remote file with matches // if at least one match found, then send back the remote file with matches
if (results != null && results.length > 0) { if (results != null && results.length > 0) {
convert(deObj, absPath, results); 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 // otherwise if it is a file search, return the remote file back with no children
else { else {
deObj.setParent(_status); deObj.setParent(_status);
_status.addNestedData(deObj, false); _status.addNestedData(deObj, false);
} }
} }
} }
@ -248,10 +250,10 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
else { else {
deObj = _dataStore.createObject(null, _deArchiveFile, compareStr); deObj = _dataStore.createObject(null, _deArchiveFile, compareStr);
} }
deObj.setAttribute(DE.A_VALUE, theFile.getParentFile().getAbsolutePath()); deObj.setAttribute(DE.A_VALUE, theFile.getParentFile().getAbsolutePath());
deObj.setAttribute(DE.A_SOURCE, _miner.setProperties(theFile)); deObj.setAttribute(DE.A_SOURCE, _miner.setProperties(theFile));
// if it is a file search, we send the remote file back // 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 // otherwise search within the file and see if there is at least one match
if (_isFileSearch || internalSearchWithinFile(deObj, absPath, theFile)) { if (_isFileSearch || internalSearchWithinFile(deObj, absPath, theFile)) {
@ -259,21 +261,21 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
_status.addNestedData(deObj, false); _status.addNestedData(deObj, false);
} }
} }
// do a refresh // do a refresh
//_dataStore.refresh(_status, true); //_dataStore.refresh(_status, true);
} }
// if the depth is not 0, then we need to recursively search // if the depth is not 0, then we need to recursively search
if (depth != 0) { if (depth != 0) {
// if it is a directory, or an archive, or a virtual directory, then we need to get the // if it is a directory, or an archive, or a virtual directory, then we need to get the
// children and search those // children and search those
if (isDirectory || ((isArchive || isVirtualDirectory) && _searchString.isIncludeArchives())) if (isDirectory || ((isArchive || isVirtualDirectory) && _searchString.isIncludeArchives()))
{ {
if (!hasSearchedDirectory(theFile)) { if (!hasSearchedDirectory(theFile)) {
try try
{ {
_alreadySearched.add(theFile.getCanonicalFile()); _alreadySearched.add(theFile.getCanonicalFile());
@ -285,34 +287,34 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
} }
File[] children = null; File[] children = null;
// if the file is an archive or a virtual directory, then get the children from // if the file is an archive or a virtual directory, then get the children from
// the archive handler // the archive handler
if (isArchive || isVirtualDirectory) { if (isArchive || isVirtualDirectory) {
AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absPath); AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absPath);
File archive = new File(avp.getContainingArchiveString()); File archive = new File(avp.getContainingArchiveString());
String virtualPath = avp.getVirtualPart(); String virtualPath = avp.getVirtualPart();
VirtualChild[] virtualchildren = null; VirtualChild[] virtualchildren = null;
try { try {
virtualchildren = ArchiveHandlerManager.getInstance().getContents(archive, virtualPath); 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$ UniversalServerUtilities.logError(_miner.getName(), "Error occured trying to get the canonical file", e, _dataStore); //$NON-NLS-1$
} }
if (virtualchildren != null) { if (virtualchildren != null) {
children = new File[virtualchildren.length]; children = new File[virtualchildren.length];
for (int i = 0; i < virtualchildren.length; i++) { for (int i = 0; i < virtualchildren.length; i++) {
AbsoluteVirtualPath newAvp = new AbsoluteVirtualPath(absPath); AbsoluteVirtualPath newAvp = new AbsoluteVirtualPath(absPath);
newAvp.setVirtualPart(virtualchildren[i].fullName); newAvp.setVirtualPart(virtualchildren[i].fullName);
children[i] = new File(newAvp.toString()); children[i] = new File(newAvp.toString());
} }
if (virtualchildren.length == 0) { if (virtualchildren.length == 0) {
children = null; children = null;
} }
@ -322,11 +324,11 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
else { else {
children = theFile.listFiles(); children = theFile.listFiles();
} }
if (children != null) { if (children != null) {
for (int i = 0; i < children.length && !_isCancelled; i++) { for (int i = 0; i < children.length && !_isCancelled; i++) {
File child = children[i]; File child = children[i];
internalSearch(child, depth - 1); internalSearch(child, depth - 1);
} }
@ -341,24 +343,24 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
if (_isFileSearch) { if (_isFileSearch) {
return true; return true;
} }
FileInputStream inputStream = null; FileInputStream inputStream = null;
try { try {
inputStream = new FileInputStream(theFile); inputStream = new FileInputStream(theFile);
InputStreamReader reader = new InputStreamReader(inputStream); InputStreamReader reader = new InputStreamReader(inputStream);
BufferedReader bufReader = new BufferedReader(reader); BufferedReader bufReader = new BufferedReader(reader);
SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, _stringMatcher); SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, _stringMatcher);
SystemSearchLineMatch[] matches = locator.locateMatches(); SystemSearchLineMatch[] matches = locator.locateMatches();
boolean foundMatches = ((matches != null) && (matches.length > 0)); boolean foundMatches = ((matches != null) && (matches.length > 0));
if (foundMatches) { if (foundMatches) {
convert(remoteFile, absPath, matches); convert(remoteFile, absPath, matches);
} }
return foundMatches; return foundMatches;
} }
catch (Exception e) { catch (Exception e) {
@ -371,14 +373,14 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
protected boolean doesFilePatternMatch(String compareStr) { protected boolean doesFilePatternMatch(String compareStr) {
return _fileNameMatcher.matches(compareStr); return _fileNameMatcher.matches(compareStr);
} }
/** /**
* Returns whether classification matches. * Returns whether classification matches.
* @param absolutePath the absolute path of the file for which we want to check classification. * @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. * @return <code>true</code> if the classification matches, <code>false</code> otherwise.
*/ */
protected boolean doesClassificationMatch(String absolutePath) { protected boolean doesClassificationMatch(String absolutePath) {
if (_classificationString == null || _classificationString.equals("")) { //$NON-NLS-1$ if (_classificationString == null || _classificationString.equals("")) { //$NON-NLS-1$
return true; return true;
} }
@ -387,7 +389,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
return StringCompare.compare(_classificationString, classification, true); return StringCompare.compare(_classificationString, classification, true);
} }
} }
/** /**
* Converts from system line matches to data elements that will be sent back. * 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. * @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. * @param lineMatches an array of line matches, or empty if no matches.
*/ */
protected void convert(DataElement deObj, String absPath, SystemSearchLineMatch[] lineMatches) { protected void convert(DataElement deObj, String absPath, SystemSearchLineMatch[] lineMatches) {
SystemSearchLineMatch match = null; SystemSearchLineMatch match = null;
for (int i = 0; i < lineMatches.length; i++) { for (int i = 0; i < lineMatches.length; i++) {
match = lineMatches[i]; match = lineMatches[i];
DataElement obj = _dataStore.createObject(deObj, _deGrep, match.getLine(), absPath); 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 * 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 * available at http://www.eclipse.org/legal/epl-v10.html
* *
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir, * component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * 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; 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.AbsoluteVirtualPath;
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
import org.eclipse.rse.services.clientserver.java.BasicClassFileParser; 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. * This singleton class classifies a file on the remote system.
*/ */
public class SystemFileClassifier { public class SystemFileClassifier {
private static SystemFileClassifier instance; private static SystemFileClassifier instance;
/** /**
@ -41,20 +43,20 @@ public class SystemFileClassifier {
private SystemFileClassifier() { private SystemFileClassifier() {
super(); super();
} }
/** /**
* Returns the singleton instance. * Returns the singleton instance.
* @return the singleton instance. * @return the singleton instance.
*/ */
public static SystemFileClassifier getInstance() { public static SystemFileClassifier getInstance() {
if (instance == null) { if (instance == null) {
instance = new SystemFileClassifier(); instance = new SystemFileClassifier();
} }
return instance; return instance;
} }
/** /**
* Classifies the file with the given absolute path. The absolute path can represent a virtual file. * Classifies the file with the given absolute path. The absolute path can represent a virtual file.
* By default, returns <code>"file"</code>. * By default, returns <code>"file"</code>.
@ -62,10 +64,10 @@ public class SystemFileClassifier {
* @return the classification. * @return the classification.
*/ */
public String classifyFile(String absolutePath) { public String classifyFile(String absolutePath) {
// first check if the absolute path is virtual // first check if the absolute path is virtual
boolean isVirtual = ArchiveHandlerManager.isVirtual(absolutePath); boolean isVirtual = ArchiveHandlerManager.isVirtual(absolutePath);
// if virtual, classify using archive handler manager // if virtual, classify using archive handler manager
if (isVirtual) { if (isVirtual) {
return classifyVirtual(absolutePath); return classifyVirtual(absolutePath);
@ -75,52 +77,56 @@ public class SystemFileClassifier {
return classifyNonVirtual(absolutePath); return classifyNonVirtual(absolutePath);
} }
} }
/** /**
* Classifies a virtual file with the given path. * Classifies a virtual file with the given path.
* @param absolutePath the absolute path of the virtual file. * @param absolutePath the absolute path of the virtual file.
* @return the classification. * @return the classification.
*/ */
protected String classifyVirtual(String absolutePath) { protected String classifyVirtual(String absolutePath) {
// create an abolute virtual path object // create an absolute virtual path object
AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absolutePath); AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absolutePath);
// get the path of the containing archive // get the path of the containing archive
String archivePath = avp.getContainingArchiveString(); String archivePath = avp.getContainingArchiveString();
// get the virtual part of the file path // get the virtual part of the file path
String virtualPath = avp.getVirtualPart(); String virtualPath = avp.getVirtualPart();
// get archive file // get archive file
File archiveFile = new File(archivePath); File archiveFile = new File(archivePath);
// get classification of virtual file // 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. * Classifies a non-virtual file with the given path.
* @param absolutePath the absolute path of the file. * @param absolutePath the absolute path of the file.
* @return the classification. * @return the classification.
*/ */
protected String classifyNonVirtual(String absolutePath) { protected String classifyNonVirtual(String absolutePath) {
// default type // default type
String type = "file"; //$NON-NLS-1$ String type = "file"; //$NON-NLS-1$
File file = new File(absolutePath); File file = new File(absolutePath);
// check if file exists // check if file exists
if (!file.exists()) { if (!file.exists()) {
return type; return type;
} }
// find out if we are on Windows // find out if we are on Windows
boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("win"); //$NON-NLS-1$ //$NON-NLS-2$ boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("win"); //$NON-NLS-1$ //$NON-NLS-2$
// for Windows, we only detect *.exe and *.dll files // for Windows, we only detect *.exe and *.dll files
if (isWindows) if (isWindows)
{ {
absolutePath = absolutePath.toLowerCase(); absolutePath = absolutePath.toLowerCase();
// classify *.class file // classify *.class file
@ -135,43 +141,43 @@ public class SystemFileClassifier {
else if (absolutePath.endsWith(".dll")) { //$NON-NLS-1$ else if (absolutePath.endsWith(".dll")) { //$NON-NLS-1$
type = "module"; //$NON-NLS-1$ type = "module"; //$NON-NLS-1$
} }
return type; return type;
} }
// get specified encoding if any // get specified encoding if any
String encoding = System.getProperty("dstore.stdin.encoding"); //$NON-NLS-1$ String encoding = System.getProperty("dstore.stdin.encoding"); //$NON-NLS-1$
// otherwise, default to system encoding // otherwise, default to system encoding
if (encoding == null || encoding.equals("")) { //$NON-NLS-1$ if (encoding == null || encoding.equals("")) { //$NON-NLS-1$
encoding = System.getProperty("file.encoding"); //$NON-NLS-1$ encoding = System.getProperty("file.encoding"); //$NON-NLS-1$
} }
// create command "sh -c file <absolutePath>" // create command "sh -c file <absolutePath>"
String args[] = new String[3]; String args[] = new String[3];
args[0] = "sh"; //$NON-NLS-1$ args[0] = "sh"; //$NON-NLS-1$
args[1] = "-c"; //$NON-NLS-1$ args[1] = "-c"; //$NON-NLS-1$
args[2] = "file " + PathUtility.enQuoteUnix(absolutePath); //$NON-NLS-1$ args[2] = "file " + PathUtility.enQuoteUnix(absolutePath); //$NON-NLS-1$
BufferedReader poutReader = null; BufferedReader poutReader = null;
try { try {
Process childProcess = Runtime.getRuntime().exec(args); Process childProcess = Runtime.getRuntime().exec(args);
InputStreamReader reader = new InputStreamReader(childProcess.getInputStream(), encoding); InputStreamReader reader = new InputStreamReader(childProcess.getInputStream(), encoding);
poutReader = new BufferedReader(reader); poutReader = new BufferedReader(reader);
// get line of output // get line of output
String line = poutReader.readLine(); String line = poutReader.readLine();
if (line != null) { if (line != null) {
line = line.trim(); line = line.trim();
// classify from line of output // classify from line of output
type = getClassification(absolutePath, line); type = getClassification(absolutePath, line);
// close stream // close stream
poutReader.close(); poutReader.close();
// if it a symbolic link, then get the canonical path and classify it as well // if it a symbolic link, then get the canonical path and classify it as well
if (type.equals("link")) { //$NON-NLS-1$ if (type.equals("link")) { //$NON-NLS-1$
String canonicalPath = file.getCanonicalPath(); String canonicalPath = file.getCanonicalPath();
@ -190,37 +196,37 @@ public class SystemFileClassifier {
// TODO: log it // TODO: log it
return type; return type;
} }
return type; return type;
} }
/** /**
* Classifies from the given line of classification output. * Classifies from the given line of classification output.
* @param absolutePath the absolute path of the file that was classified. * @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. * @return the classification.
*/ */
protected String getClassification(String absolutePath, String line) { protected String getClassification(String absolutePath, String line) {
// default type // default type
String type = "file"; //$NON-NLS-1$ String type = "file"; //$NON-NLS-1$
String name = line; String name = line;
String fulltype = ""; //$NON-NLS-1$ String fulltype = ""; //$NON-NLS-1$
// Look for colon. Name appears before colon. Full type appears after the colon // Look for colon. Name appears before colon. Full type appears after the colon
int colon = line.indexOf(':'); int colon = line.indexOf(':');
if (colon >= 0) { if (colon >= 0) {
name = line.substring(0, colon); name = line.substring(0, colon);
fulltype = line.substring(colon + 1, line.length()).trim(); fulltype = line.substring(colon + 1, line.length()).trim();
} }
// if it is a *.class file, then we look for main method and qulaified class name // if it is a *.class file, then we look for main method and qulaified class name
// as part of the classification // as part of the classification
if (name.endsWith(".class")) { //$NON-NLS-1$ if (name.endsWith(".class")) { //$NON-NLS-1$
type = classifyClassFile(absolutePath); type = classifyClassFile(absolutePath);
} }
// check if it is a shared library // check if it is a shared library
boolean matchesLib = (fulltype.indexOf("shared object") > -1) || //$NON-NLS-1$ boolean matchesLib = (fulltype.indexOf("shared object") > -1) || //$NON-NLS-1$
(fulltype.indexOf("object module") > -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 // check if it is an executable
boolean matchesExe = (fulltype.indexOf("executable") > -1); //$NON-NLS-1$ boolean matchesExe = (fulltype.indexOf("executable") > -1); //$NON-NLS-1$
// check if it is a script // check if it is a script
boolean matchesScript = (fulltype.indexOf("script") > -1); //$NON-NLS-1$ boolean matchesScript = (fulltype.indexOf("script") > -1); //$NON-NLS-1$
// shared library // shared library
if (matchesLib) { if (matchesLib) {
// all *.a, *.so and *.so.* files are of type "module" // 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$ 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$ type = "module"; //$NON-NLS-1$
} }
} }
// a script file // a script file
else if (matchesScript) { else if (matchesScript) {
// an executable script file // an executable script file
if (matchesExe) { if (matchesExe) {
type = "executable(script)"; //$NON-NLS-1$ type = "executable(script)"; //$NON-NLS-1$
@ -253,74 +259,74 @@ public class SystemFileClassifier {
type = "script"; //$NON-NLS-1$ type = "script"; //$NON-NLS-1$
} }
} }
// binary executable // binary executable
else if (matchesExe) { else if (matchesExe) {
type = "executable(binary)"; //$NON-NLS-1$ type = "executable(binary)"; //$NON-NLS-1$
} }
// on iSeries we look for "OS/400 object" as a type // on iSeries we look for "OS/400 object" as a type
else if (fulltype.indexOf("OS/400 object") > -1) { //$NON-NLS-1$ else if (fulltype.indexOf("OS/400 object") > -1) { //$NON-NLS-1$
type = "OS/400 object"; //$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" // 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$ else if (fulltype.startsWith("symbolic link to")) { //$NON-NLS-1$
type = "link"; //$NON-NLS-1$ type = "link"; //$NON-NLS-1$
} }
return type; return type;
} }
/** /**
* Classifies a class file. * Classifies a class file.
* @param absolutePath the absolute path of the class file. * @param absolutePath the absolute path of the class file.
* @return the classification. * @return the classification.
*/ */
protected String classifyClassFile(String absolutePath) { protected String classifyClassFile(String absolutePath) {
// default type // default type
String type = "file"; //$NON-NLS-1$ String type = "file"; //$NON-NLS-1$
// input stream to file // input stream to file
FileInputStream stream = null; FileInputStream stream = null;
// class file parser // class file parser
BasicClassFileParser parser = null; BasicClassFileParser parser = null;
boolean isExecutable = false; boolean isExecutable = false;
try { try {
stream = new FileInputStream(absolutePath); stream = new FileInputStream(absolutePath);
// use class file parser to parse the class file // use class file parser to parse the class file
parser = new BasicClassFileParser(stream); parser = new BasicClassFileParser(stream);
parser.parse(); parser.parse();
// query if it is executable, i.e. whether it has main method // query if it is executable, i.e. whether it has main method
isExecutable = parser.isExecutable(); isExecutable = parser.isExecutable();
} }
catch (IOException e) { catch (IOException e) {
// TODO: log it // TODO: log it
// we assume not executable // we assume not executable
isExecutable = false; isExecutable = false;
return type; return type;
} }
// if it is executable, then also get qualified class name // if it is executable, then also get qualified class name
if (isExecutable) { if (isExecutable) {
type = "executable(java"; //$NON-NLS-1$ type = "executable(java"; //$NON-NLS-1$
String qualifiedClassName = parser.getQualifiedClassName(); String qualifiedClassName = parser.getQualifiedClassName();
if (qualifiedClassName != null) { if (qualifiedClassName != null) {
type = type + ":" + qualifiedClassName; //$NON-NLS-1$ type = type + ":" + qualifiedClassName; //$NON-NLS-1$
} }
type = type + ")"; //$NON-NLS-1$ type = type + ")"; //$NON-NLS-1$
} }
return type; return type;
} }
} }

View file

@ -10,13 +10,14 @@
* component that contains this file: David McKnight, Kushal Munir, * component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors * 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) - [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) - [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) * 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 * 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; package org.eclipse.rse.services.clientserver.archiveutils;
@ -27,6 +28,11 @@ import java.lang.reflect.InvocationTargetException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; 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 * 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 * 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 * Folder separator used in virtual paths inside the archive, i.e. after the
* VIRTUAL_SEPARATOR. * VIRTUAL_SEPARATOR.
* *
* @since org.eclipse.rse.services 3.0 * @since org.eclipse.rse.services 3.0
*/ */
public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$ public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$
/** /**
* Character used to separate file extension from file name. This is used in * Character used to separate file extension from file name. This is used in
* order to recognize file patterns that should be treated as archives. * order to recognize file patterns that should be treated as archives.
* *
* @since org.eclipse.rse.services 3.0 * @since org.eclipse.rse.services 3.0
*/ */
public static final String EXTENSION_SEPARATOR = "."; //$NON-NLS-1$ 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 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 * @param virtualpath The parent virtual object whose children this method
* get the top level virtualchildren in the archive, set virtualpath to "" or null. * is to return. To get the top level virtual children in the archive,
* @return An array of VirtualChild objects representing the children of the virtual object * set virtual path to "" or null.
* in <code>file</code> referred to by <code>virtualpath</code>. If no class implementing * @return An array of VirtualChild objects representing the children of the
* ISystemArchiveHandler can be found that corresponds to file, then this method returns null. * virtual object in <code>file</code> referred to by
* If the virtual object has no children, this method also returns null. * <code>virtual path</code>. If no class implementing ISystemArchiveHandler
* @throws IOException if there was a problem getting the registered handler for the * can be found that corresponds to file, then this method returns null. If
* file. This usually means the archive is corrupted. * 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$ if (virtualpath == null) virtualpath = ""; //$NON-NLS-1$
ISystemArchiveHandler handler = getRegisteredHandler(file); 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); 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 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 * @param virtualpath The parent virtual object whose children this method
* get the top level virtualchildren in the archive, set virtualpath to "" or null. * is to return. To get the top level virtual children in the archive,
* @return An array of VirtualChild objects representing the children of the virtual object * set virtual path to "" or null.
* in <code>file</code> referred to by <code>virtualpath</code> that are themselves folders. * @return An array of VirtualChild objects representing the children of the
* If no class implementing ISystemArchiveHandler can be found that corresponds to file, then * virtual object in <code>file</code> referred to by
* this method returns null. If the virtual object has no children, this method also returns null. * <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$ if (virtualpath == null) virtualpath = ""; //$NON-NLS-1$
ISystemArchiveHandler handler = getRegisteredHandler(file); ISystemArchiveHandler handler = getRegisteredHandler(file);
@ -222,14 +243,18 @@ public class ArchiveHandlerManager
} }
/** /**
* Given the absolute path to a virtual object, returns that object * Given the absolute path to a virtual object, returns that object as a
* as a VirtualChild. * VirtualChild.
* @param fullyQualifiedName The absolute path to the object. Usually consists *
* of the fullyQualifiedName of the archive, followed by the virtual path separator * @param fullyQualifiedName The absolute path to the object. Usually
* (defined in ArchiveHandlerManager.VIRTUAL_SEPARATOR) followed by the virtual path to * consists of the fullyQualifiedName of the archive, followed by the
* the object within the archive's virtual file system. * 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); String cleanName = cleanUpVirtualPath(fullyQualifiedName);
AbsoluteVirtualPath avp = new AbsoluteVirtualPath(cleanName); AbsoluteVirtualPath avp = new AbsoluteVirtualPath(cleanName);
@ -243,11 +268,15 @@ public class ArchiveHandlerManager
} }
/** /**
* Returns the registered handler for the File <code>file</code>. If * Returns the registered handler for the File <code>file</code>. If no
* no handler exists for that file yet, create it. If the extension of * handler exists for that file yet, create it. If the extension of
* <code>file</code> is not registered, then returns null. * <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; ISystemArchiveHandler handler = null;
if (_handlers.containsKey(file)) if (_handlers.containsKey(file))
@ -279,17 +308,11 @@ public class ArchiveHandlerManager
catch (InvocationTargetException e) catch (InvocationTargetException e)
{ {
//Throwable target = e.getCause(); //Throwable target = e.getCause();
System.out.println(e.getMessage()); throw new SystemOperationFailedException(Activator.PLUGIN_ID, "instantiate handler for " + file.getName(), e); //$NON-NLS-1$
e.printStackTrace();
System.out.println("Could not instantiate handler for " + file.getName()); //$NON-NLS-1$
return null;
} }
catch (Exception e) catch (Exception e)
{ {
System.out.println(e.getMessage()); throw new SystemOperationFailedException(Activator.PLUGIN_ID, "instantiate handler for " + file.getName(), e); //$NON-NLS-1$
System.out.println("Could not instantiate handler for " + file.getName()); //$NON-NLS-1$
return null;
} }
_handlers.put(file, handler); _handlers.put(file, handler);
return handler; return handler;
@ -475,28 +498,30 @@ public class ArchiveHandlerManager
_handlers.clear(); _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())) if (!isRegisteredArchive(newFile.getName()))
{ {
System.out.println("Could not create new archive."); //$NON-NLS-1$ throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive, because " //$NON-NLS-1$
System.out.println(newFile + " is not a registered type of archive."); //$NON-NLS-1$ + newFile + " is not a registered type of archive."); //$NON-NLS-1$
return false;
} }
if (newFile.exists()) if (newFile.exists())
{ {
if (!newFile.isFile()) if (!newFile.isFile())
{ {
System.out.println("Could not create new archive."); //$NON-NLS-1$ throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive." //$NON-NLS-1$
System.out.println(newFile + " is not a file."); //$NON-NLS-1$ + newFile + " is not a file."); //$NON-NLS-1$
return false;
} }
if (!newFile.delete()) if (!newFile.delete())
{ {
System.out.println("Could not create new archive."); //$NON-NLS-1$ throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive." //$NON-NLS-1$
System.out.println(newFile + " could not be deleted."); //$NON-NLS-1$ + newFile + " could not be deleted."); //$NON-NLS-1$
return false;
} }
} }
@ -504,20 +529,17 @@ public class ArchiveHandlerManager
{ {
if (!newFile.createNewFile()) if (!newFile.createNewFile())
{ {
System.out.println("Could not create new archive."); //$NON-NLS-1$ throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive." //$NON-NLS-1$
System.out.println(newFile + " could not be created."); //$NON-NLS-1$ + newFile + " could not be created."); //$NON-NLS-1$
return false;
} }
} }
catch (IOException e) catch (IOException e)
{ {
System.out.println("Could not create new archive."); //$NON-NLS-1$ throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive: " + newFile, e); //$NON-NLS-1$
System.out.println(e.getMessage());
return false;
} }
ISystemArchiveHandler handler = getRegisteredHandler(newFile); ISystemArchiveHandler handler = getRegisteredHandler(newFile);
return handler.create(); handler.create();
} }
/** /**
@ -535,14 +557,26 @@ public class ArchiveHandlerManager
return extensions; 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); ISystemArchiveHandler handler = getRegisteredHandler(archive);
if (handler == null || !handler.exists()) return ""; //$NON-NLS-1$ if (handler == null || !handler.exists()) return ""; //$NON-NLS-1$
return handler.getArchiveComment(); 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); ISystemArchiveHandler handler = getRegisteredHandler(archive);
if (handler == null || !handler.exists()) return 0; 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 file the archive file.
* @param virtualPath the virtual path. * @param virtualPath the virtual path.
* @return the classification for the virtual file. * @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 // if archive file is null, or if it does not exist, or if the virtual path
// is null, then return null for the classification // is null, then return null for the classification

View file

@ -10,10 +10,11 @@
* component that contains this file: David McKnight, Kushal Munir, * component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* Xuan Chen (IBM) - [160775][api][breaking] rename (at least within a zip) blocks UI thread * 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) - [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; 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.ISystemFileTypes;
import org.eclipse.rse.services.clientserver.ISystemOperationMonitor; 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.SystemSearchLineMatch;
import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher; 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 * An interface that allows implementing classes to create their own handlers
* for various types of archive files, ie: zip, jar, tar, rpm. * for various types of archive files, ie: zip, jar, tar, rpm.
* *
* @author mjberger * @author mjberger
*/ */
public interface ISystemArchiveHandler public interface ISystemArchiveHandler
@ -39,23 +41,26 @@ public interface ISystemArchiveHandler
* Turns the archive that this handler represents into a new, empty archive. * 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 * (The archive could not exist before, in which case this would be a true
* creation). * 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. * Return a flat list of entries in an archive.
* *
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return an array containing all the entries in the archive file in a flat * @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 * format, where the entries' filenames are prepended by the path to the
* the entry within the virtual file system. If there are no entries * entry within the virtual file system. If there are no entries in the
* in the file, returns an array of size 0. * 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 * @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 * 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 parent full path of the parent
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return an array containing all the entries in the archive file in a flat * @return an array containing all the entries in the archive file in a flat
* format, whose full paths begin with the String * format, whose full paths begin with the String <code>parent</code>.
* <code>parent</code>. Returns an array of length 0 if there are * Returns an array of length 0 if there are no such entries.
* no such entries. * @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* *
* @since org.eclipse.rse.services 3.0 * @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. * 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 fullVirtualName full virtual path of the parent
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return an array containing the virtual children of the virtual directory * @return an array containing the virtual children of the virtual directory
* named <code>fullVirtualName</code>. If * named <code>fullVirtualName</code>. If <code>fullVirtualName</code> is
* <code>fullVirtualName</code> is "", returns the top level in * "", returns the top level in the virtual file system tree. If there are
* the virtual file system tree. If there are no values to return, * no values to return, returns null.
* returns null. * @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* *
* @since org.eclipse.rse.services 3.0 * @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 * 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 fullVirtualName full virtual path of the parent
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return an array containing the virtual children of the virtual directory * @return an array containing the virtual children of the virtual directory
* named <code>fullVirtualName</code> that are themselves * named <code>fullVirtualName</code> that are themselves directories. If
* directories. If <code>fullVirtualName</code> is "", returns the * <code>fullVirtualName</code> is "", returns the top level of directories
* top level of directories in the virtual file system tree. If * in the virtual file system tree. If there are no values to return,
* there are no values to return, returns null. * returns null.
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* *
* @since org.eclipse.rse.services 3.0 * @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. * 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 fullVirtualName full virtual path of the object to retrieve
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return the virtual File or Folder referred to by * @return the virtual File or Folder referred to by
* <code>fullVirtualName</code>. This method never returns null. * <code>fullVirtualName</code>. This method never returns null. In cases
* In cases where the VirtualChild does not physically exist in the * where the VirtualChild does not physically exist in the archive, this
* archive, this method returns a new VirtualChild object whose * method returns a new VirtualChild object whose exists() method returns
* exists() method returns false. * false.
* @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* *
* @since org.eclipse.rse.services 3.0 * @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. * 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 fullVirtualName full virtual path of the object
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return Whether or not the virtual file or folder named * @return Whether or not the virtual file or folder named
* <code>fullVirtualName</code> exists in the archive * <code>fullVirtualName</code> exists in the archive (physically).
* (physically). * @throws SystemMessageException in case of an error,
* or SystemOperationCancelledException in case of user cancellation
* *
* @since org.eclipse.rse.services 3.0 * @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 * Check if the archive handler implementation associated with this class
* exists. * exists.
* *
* @return Whether or not the handler exists. Usually false if the archive * @return Whether or not the handler exists. Usually false if the archive
* is corrupted or unreadable. * 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.
* *
* @return the archive that this handler deals with * @return the archive that this handler deals with
*/ */
public File getArchive(); public File getArchive();
@ -152,50 +164,55 @@ public interface ISystemArchiveHandler
* *
* @param fullVirtualName virtual path specifying the node to check * @param fullVirtualName virtual path specifying the node to check
* @return the current timestamp (last modified) for the archive entry named * @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. * Return the size for an archive node.
* *
* @param fullVirtualName virtual path specifying the node to check * @param fullVirtualName virtual path specifying the node to check
* @return the current size (uncompressed) for the entry in the archive * @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 * Extracts the virtual file named <code>fullVirtualName</code> from the
* archive, placing the results in <code>destination</code>. * archive, placing the results in <code>destination</code>.
* *
* @param fullVirtualName The full path and name of the virtual file in the * @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 destination The destination file for the extracted virtual file.
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * Extracts the virtual file named <code>fullVirtualName</code> from the
* archive, placing the results in <code>destination</code>. Extracts to * archive, placing the results in <code>destination</code>. Extracts to the
* the native encoding, but assumes that the source was archived using * native encoding, but assumes that the source was archived using
* <code>sourceEncoding</code> if <code>isText</code> is true. * <code>sourceEncoding</code> if <code>isText</code> is true.
* *
* @param fullVirtualName The full path and name of the virtual file in the * @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 destination The destination file for the extracted virtual file.
* @param sourceEncoding The encoding of the file in the archive. * @param sourceEncoding The encoding of the file in the archive.
* @param isText Whether or not the virtual file is a text file. * @param isText Whether or not the virtual file is a text file.
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * 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 dir The full name of the virtual directory to extract
* @param destinationParent A handle to the directory in which the extracted * @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 * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * 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 dir The full name of the virtual directory to extract
* @param destinationParent A handle to the directory in which the extracted * @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 sourceEncoding The encoding of the files in the archive.
* @param isText Whether or not the files in the directory are text files * @param isText Whether or not the files in the directory are text files
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * 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 dir The full name of the virtual directory to extract
* @param destinationParent A handle to the directory in which the extracted * @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. * @param destination A handle to the directory that will be created.
* Whatever contents are in that directory will be replaced with * Whatever contents are in that directory will be replaced with what
* what is extracted from the archive. * is extracted from the archive.
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * Extracts the directory <code>dir</code> (and its children) from the
* archive and places the results in the directory * archive and places the results in the directory
* <code>destinationParent</code>. The results will be named * <code>destinationParent</code>. The results will be named
* destination.getName() rather than <code>dir</code>'s name. Extracts to * destination.getName() rather than <code>dir</code>'s name. Extracts to
* the native encoding (if <code>isText</code>), but assumes that the * the native encoding (if <code>isText</code>), but assumes that the source
* source was archived using <code>sourceEncoding</code>. * was archived using <code>sourceEncoding</code>.
* *
* @param dir The full name of the virtual directory to extract * @param dir The full name of the virtual directory to extract
* @param destinationParent A handle to the directory in which the extracted * @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. * @param destination A handle to the directory that will be created.
* Whatever contents are in that directory will be replaced with * Whatever contents are in that directory will be replaced with what
* what is extracted from the archive. * is extracted from the archive.
* @param sourceEncoding The encoding of the files in 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 * @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 * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the extraction is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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, * Compresses the file <code>file</code> and adds it to the archive, placing
* placing it in the virtual directory <code>virtualPath</code>. Pass the * it in the virtual directory <code>virtualPath</code>. Pass the name as
* name as the parameter <code>name</code>. If the virtual path does not * the parameter <code>name</code>. If the virtual path does not exist in
* exist in the archive, create it. If <code>file</code> is a directory, * the archive, create it. If <code>file</code> is a directory, copy it and
* copy it and its contents into the archive, maintaining the tree * its contents into the archive, maintaining the tree structure.
* structure.
* *
* @param file the file to be added to the archive * @param file the file to be added to the archive
* @param virtualPath the destination of the file * @param virtualPath the destination of the file
* @param name the name of the result virtual file * @param name the name of the result virtual file
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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, * Compresses the file <code>file</code> and adds it to the archive, saving
* saving it in the encoding specified by <code>encoding</code> if the * it in the encoding specified by <code>encoding</code> if the isText is
* isText is true. placing it in the virtual directory * true. placing it in the virtual directory <code>virtualPath</code>. Pass
* <code>virtualPath</code>. Pass the name as the parameter * the name as the parameter <code>name</code>. If the virtual path does not
* <code>name</code>. If the virtual path does not exist in the archive, * exist in the archive, create it. If <code>file</code> is a directory,
* create it. If <code>file</code> is a directory, copy it and its * copy it and its contents into the archive, maintaining the tree
* contents into the archive, maintaining the tree structure. * structure.
* *
* @param file the file to be added to the archive * @param file the file to be added to the archive
* @param virtualPath the destination of the file * @param virtualPath the destination of the file
@ -308,19 +327,20 @@ public interface ISystemArchiveHandler
* @param targetEncoding the encoding of the result file * @param targetEncoding the encoding of the result file
* @param isText is the file a text file * @param isText is the file a text file
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * Compresses the bytes in the InputStream <code>stream</code> and adds them
* them as an entry to the archive, saving them in the encoding specified by * 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 * <code>encoding</code> if <code>isText</code> is true, and placing it in
* in the virtual directory <code>virtualPath</code>. Pass the name as * the virtual directory <code>virtualPath</code>. Pass the name as the
* the parameter <code>name</code>. If the virtual path does not exist in * parameter <code>name</code>. If the virtual path does not exist in the
* the archive, create it. * archive, create it.
* *
* @param stream the InputStream to be added as an entry to the archive * @param stream the InputStream to be added as an entry to the archive
* @param virtualPath the destination of the stream * @param virtualPath the destination of the stream
@ -329,20 +349,21 @@ public interface ISystemArchiveHandler
* @param targetEncoding the encoding of the result file * @param targetEncoding the encoding of the result file
* @param isText is the file a text file * @param isText is the file a text file
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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, * Compresses the file <code>file</code> and adds it to the archive, saving
* saving it in the encoding specified by <code>encoding</code> if the * it in the encoding specified by <code>encoding</code> if the isText is
* isText is true. placing it in the virtual directory * true. placing it in the virtual directory <code>virtualPath</code>. Pass
* <code>virtualPath</code>. Pass the name as the parameter * the name as the parameter <code>name</code>. If the virtual path does not
* <code>name</code>. If the virtual path does not exist in the archive, * exist in the archive, create it. If <code>file</code> is a directory,
* create it. If <code>file</code> is a directory, copy it and its * copy it and its contents into the archive, maintaining the tree
* contents into the archive, maintaining the tree structure. * structure.
* *
* @param file the file to be added to the archive * @param file the file to be added to the archive
* @param virtualPath the destination of the file * @param virtualPath the destination of the file
@ -351,39 +372,39 @@ public interface ISystemArchiveHandler
* @param targetEncoding the encoding of the result file * @param targetEncoding the encoding of the result file
* @param typeRegistery file transfer mode (binary or text) of this file * @param typeRegistery file transfer mode (binary or text) of this file
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * A generalization of the add method. Compresses the array of files
* <code>files</code> and adds each of them to the archive, placing them * <code>files</code> and adds each of them to the archive, placing them in
* in the virtual directory <code>virtualPath</code>. Pass the names of * the virtual directory <code>virtualPath</code>. Pass the names of the
* the files as the parameter <code>names</code>, where * files as the parameter <code>names</code>, where <code>files[i]</code>
* <code>files[i]</code> has the name <code>names[i]</code>. If the * has the name <code>names[i]</code>. If the virtual path does not exist in
* virtual path does not exist in the archive, create it. * the archive, create it.
* *
* @param files the list of files to be added to the archive * @param files the list of files to be added to the archive
* @param virtualPath the destination of the file * @param virtualPath the destination of the file
* @param names the names of the result virtual files * @param names the names of the result virtual files
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * A generalization of the add method. Compresses the array of files
* <code>files</code> and adds each of them to the archive, placing them * <code>files</code> and adds each of them to the archive, placing them in
* in the virtual directory <code>virtualPath</code>. Save the i'th file * the virtual directory <code>virtualPath</code>. Save the i'th file in the
* in the i'th encoding (if isText[i] is true) specified by * i'th encoding (if isText[i] is true) specified by <code>encodings</code>.
* <code>encodings</code>. Pass the names of the files as the parameter * Pass the names of the files as the parameter <code>names</code>, where
* <code>names</code>, where <code>files[i]</code> has the name * <code>files[i]</code> has the name <code>names[i]</code>. If the virtual
* <code>names[i]</code>. If the virtual path does not exist in the * path does not exist in the archive, create it.
* archive, create it.
* *
* @param files the list of files to be added to the archive * @param files the list of files to be added to the archive
* @param virtualPath the destination of the files * @param virtualPath the destination of the files
@ -392,33 +413,34 @@ public interface ISystemArchiveHandler
* @param targetEncodings the encoding of the result files * @param targetEncodings the encoding of the result files
* @param isText file transfer mode (binary or text) of the files * @param isText file transfer mode (binary or text) of the files
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the addition is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * Compress the file <code>file</code> and replace the virtual file referred
* referred to by <code>fullVirtualName</code> with the compressed file. * to by <code>fullVirtualName</code> with the compressed file. Pass the
* Pass the name of the file as the parameter <code>name</code>. * name of the file as the parameter <code>name</code>.
* *
* @param fullVirtualName the path of the file to be replaced * @param fullVirtualName the path of the file to be replaced
* @param file the file to be added to the archive * @param file the file to be added to the archive
* @param name the name of the file * @param name the name of the file
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the replacement is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * Compress the InputStream <code>stream</code> and replace the virtual file
* file referred to by <code>fullVirtualName</code> with the compressed * referred to by <code>fullVirtualName</code> with the compressed stream.
* stream. Pass the name of the new entry as the parameter <code>name</code>, * Pass the name of the new entry as the parameter <code>name</code>, the
* the encoding of the entry as <code>encoding</code> and whether or not * encoding of the entry as <code>encoding</code> and whether or not the
* the entry <code>isText</code> or not. * entry <code>isText</code> or not.
* *
* @param fullVirtualName the path of the file to be replaced * @param fullVirtualName the path of the file to be replaced
* @param stream the InputStream to be added as an entry to the archive * @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 targetEncoding the encoding of the result file
* @param isText is the file a text file * @param isText is the file a text file
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the replacement is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * 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 fullVirtualName the path of the file to be deleted
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the deletion is successful, * @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 * @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 * 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 fullVirtualName the path of the file to be renamed
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the rename is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * Moves the entry <code>fullVirtualName</code> to the location specified by
* by <code>destinationVirtualPath</code>, while leaving the entry with * <code>destinationVirtualPath</code>, while leaving the entry with the
* the same name as before. * same name as before.
* *
* @param fullVirtualName the path of the file to be renamed * @param fullVirtualName the path of the file to be renamed
* @param destinationVirtualPath the destination of the file to move to * @param destinationVirtualPath the destination of the file to move to
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the move is successful, <code>false</code> * @throws SystemMessageException in case of an error,
* otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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> * 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 fullVirtualName the path of the file to be renamed
* @param newFullVirtualName the full path of the virtual file name * @param newFullVirtualName the full path of the virtual file name
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the rename is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * 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 fullNames The list of files to return
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return An array of handles to the extracted files. If fullNames has * @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 * @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 * Creates a new, empty folder in the archive. If parent folders do not
* exist either, creates them. * exist either, creates them.
* *
* @param fullVirtualName The full name and path of the new folder within * @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 * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the create operation is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * Creates a new, empty file in the archive. If parent folders do not exist
* either, creates them. * either, creates them.
* *
* @param fullVirtualName The full name and path of the new file within the * @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 * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the create operation is successful, * @throws SystemMessageException in case of an error,
* <code>false</code> otherwise * or SystemOperationCancelledException in case of user cancellation
* @since org.eclipse.rse.services 3.0 * @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 * Get the archive-type specific standard name for the VirtualChild
* <code>vc</code>. For example, for Zip archives, if vc is a directory, * <code>vc</code>. For example, for Zip archives, if vc is a directory,
* then the standard name must end with a "/". * then the standard name must end with a "/".
* *
* @param vc the archive node to use * @param vc the archive node to use
* @return the standard name for the node * @return the standard name for the node
*/ */
@ -541,18 +569,22 @@ public interface ISystemArchiveHandler
* @param matcher the pattern matcher to use. * @param matcher the pattern matcher to use.
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return an array of match objects corresponding to lines where matches * @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 * @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. * Get the user-defined comment for a specific entry in the archive.
* *
* @param fullVirtualName The entry who's comment is desired * @param fullVirtualName The entry who's comment is desired
* @return the comment as a String or "" if there is none * @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 * 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 * @param fullVirtualName The entry who's compressed size is desired
* @return the compressed size of the specified entry, or 0 if the entry is * @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), * not found. If the archive is not a compression type (ie. tar), return
* return the same as getSizeFor(String). * 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. * Get the method used to compress a specific entry in the archive.
* *
* @param fullVirtualName The entry who's compression method is desired * @param fullVirtualName The entry who's compression method is desired
* @return The compression method of the specified entry, or "" if none. * @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. * Get the comment associated with an archive.
* *
* @return The comment associated with this archive, or "" if there is none. * @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. * Get the classification for the entry with the given path.
* *
* @param fullVirtualName the virtual name. * @param fullVirtualName the virtual name.
* @return the classification. * @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, * component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors * 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 * 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 * Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
* Johnson Ma (Wind River) - [195402][api] Add tar.gz archive support * Johnson Ma (Wind River) - [195402][api] Add tar.gz archive support
* Xuan Chen (IBM) - [224576] [api] Inconsistent boolean return values in SystemTarHandler API * 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; package org.eclipse.rse.services.clientserver.archiveutils;
@ -46,12 +47,19 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Vector; 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.ITarConstants;
import org.eclipse.rse.internal.services.clientserver.archiveutils.SystemArchiveUtil; import org.eclipse.rse.internal.services.clientserver.archiveutils.SystemArchiveUtil;
import org.eclipse.rse.services.clientserver.ISystemFileTypes; import org.eclipse.rse.services.clientserver.ISystemFileTypes;
import org.eclipse.rse.services.clientserver.ISystemOperationMonitor; import org.eclipse.rse.services.clientserver.ISystemOperationMonitor;
import org.eclipse.rse.services.clientserver.SystemReentrantMutex; import org.eclipse.rse.services.clientserver.SystemReentrantMutex;
import org.eclipse.rse.services.clientserver.java.BasicClassFileParser; 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.SystemSearchLineMatch;
import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatchLocator; import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatchLocator;
import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher; import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher;
@ -894,7 +902,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualFile(java.lang.String, java.io.File) * @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); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
TarEntry entry = null; TarEntry entry = null;
@ -922,14 +930,14 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// the entry's last modified time // the entry's last modified time
destination.mkdirs(); destination.mkdirs();
destination.setLastModified(entry.getModificationTime()); destination.setLastModified(entry.getModificationTime());
return true; return;
} }
inStream = getTarFile().getInputStream(entry); inStream = getTarFile().getInputStream(entry);
if (inStream == null) { if (inStream == null) {
destination.setLastModified(entry.getModificationTime()); destination.setLastModified(entry.getModificationTime());
return false; // TODO: return true or false? throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID);
} }
//Need to make sure destination file exists. //Need to make sure destination file exists.
if (!destination.exists()) if (!destination.exists())
@ -952,7 +960,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
} }
} }
catch (IOException e) { catch (IOException e) {
// TODO: log error throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
} }
finally { finally {
@ -980,38 +988,37 @@ public class SystemTarHandler implements ISystemArchiveHandler {
releaseMutex(mutexLockStatus); releaseMutex(mutexLockStatus);
} }
return true;
} }
/** /**
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, ISystemOperationMonitor) * @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) { public void extractVirtualDirectory(String fullVirtualName, File destinationParent, ISystemOperationMonitor archiveOperationMonitor)
return extractVirtualDirectory(fullVirtualName, destinationParent, (File) null, archiveOperationMonitor); throws SystemMessageException {
extractVirtualDirectory(fullVirtualName, destinationParent, (File) null, archiveOperationMonitor);
} }
/* /*
* (non-Javadoc) * (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) * @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 the destination directory doesn't exist, create it
if (!destinationParent.exists()) { if (!destinationParent.exists()) {
if (!destinationParent.mkdirs()) { if (!destinationParent.mkdirs()) {
// TODO: log error throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Create folder " + destinationParent); //$NON-NLS-1$
return false; // quit if we fail to create the destination directory
} }
} }
// otherwise if the destination directory does exist, but is not a directory, then quit // otherwise if the destination directory does exist, but is not a directory, then quit
else if (!destinationParent.isDirectory()) { else if (!destinationParent.isDirectory()) {
return false; throw new SystemOperationFailedException(Activator.PLUGIN_ID, "No folder: " + destinationParent); //$NON-NLS-1$
} }
fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK;
try try
{ {
@ -1024,7 +1031,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
VirtualChild dir = vfs.getEntry(fullVirtualName); VirtualChild dir = vfs.getEntry(fullVirtualName);
if (dir == null || !dir.isDirectory) { if (dir == null || !dir.isDirectory) {
return false; throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID);
} }
if (destination == null) { if (destination == null) {
@ -1052,15 +1059,10 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// if the directory does not exist, try to create it // if the directory does not exist, try to create it
if (!topDir.exists() && !topDir.mkdirs()) { if (!topDir.exists() && !topDir.mkdirs()) {
// TODO: log error throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Create folder " + topDir); //$NON-NLS-1$
return false; // log error and quit if we fail to create the directory
} }
else { else {
boolean returnCode = extractVirtualFile(fullVirtualName, topDir, archiveOperationMonitor); extractVirtualFile(fullVirtualName, topDir, archiveOperationMonitor);
if (returnCode == false)
{
return returnCode;
}
} }
// get the children of this directory // get the children of this directory
@ -1075,41 +1077,34 @@ public class SystemTarHandler implements ISystemArchiveHandler {
} }
File childFile = new File(childPath); File childFile = new File(childPath);
boolean returnCode = false;
// if the child is a directory, then we need to extract it and its children // if the child is a directory, then we need to extract it and its children
if (tempChild.isDirectory) { if (tempChild.isDirectory) {
// and now extract its children // 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 // otherwise if the child is a file, simply extract it
else { else {
returnCode = extractVirtualFile(tempChild.fullName, childFile, archiveOperationMonitor); extractVirtualFile(tempChild.fullName, childFile, archiveOperationMonitor);
}
if (returnCode == false)
{
return returnCode;
} }
} }
} }
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
return false;
} }
finally finally
{ {
releaseMutex(mutexLockStatus); releaseMutex(mutexLockStatus);
} }
return true;
} }
/* /*
* (non-Javadoc) * (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) * @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); virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath);
int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK;
@ -1123,18 +1118,16 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// if it exists, call replace // if it exists, call replace
String fullVirtualName = getFullVirtualName(virtualPath, name); String fullVirtualName = getFullVirtualName(virtualPath, name);
if (exists(fullVirtualName, archiveOperationMonitor)) { if (exists(fullVirtualName, archiveOperationMonitor)) {
boolean returnCode = replace(fullVirtualName, file, name, archiveOperationMonitor); replace(fullVirtualName, file, name, archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return returnCode;
} }
else { else {
File[] files = new File[1]; File[] files = new File[1];
files[0] = file; files[0] = file;
String[] names = new String[1]; String[] names = new String[1];
names[0] = name; names[0] = name;
boolean returnCode = add(files, virtualPath, names, archiveOperationMonitor); add(files, virtualPath, names, archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return returnCode;
} }
} }
else { else {
@ -1162,22 +1155,21 @@ public class SystemTarHandler implements ISystemArchiveHandler {
newNames[numOfChildren] = newNames[numOfChildren] + "/"; //$NON-NLS-1$ newNames[numOfChildren] = newNames[numOfChildren] + "/"; //$NON-NLS-1$
} }
boolean returnCode = add(sources, virtualPath, newNames, archiveOperationMonitor); add(sources, virtualPath, newNames, archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return returnCode;
} }
} }
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
} }
finally finally
{ {
releaseMutex(mutexLockStatus); releaseMutex(mutexLockStatus);
} }
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return false; throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID);
} }
/** /**
@ -1203,7 +1195,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc) * (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) * @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; int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK;
File outputTempFile = null; File outputTempFile = null;
@ -1225,7 +1217,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
if (!files[i].exists() || !files[i].canRead()) { if (!files[i].exists() || !files[i].canRead()) {
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); 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 // 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]); String fullVirtualName = getFullVirtualName(virtualPath, names[i]);
if (exists(fullVirtualName, archiveOperationMonitor)) { if (exists(fullVirtualName, archiveOperationMonitor)) {
boolean returnCode = replace(fullVirtualName, files[i], names[i], archiveOperationMonitor); replace(fullVirtualName, files[i], names[i], archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return returnCode;
} }
} }
@ -1252,13 +1243,13 @@ public class SystemTarHandler implements ISystemArchiveHandler {
boolean ok = createTar(children, outStream, (HashSet)null, archiveOperationMonitor); boolean ok = createTar(children, outStream, (HashSet)null, archiveOperationMonitor);
if (!ok) if (!ok)
{ {
//cancelled
outStream.close(); outStream.close();
if (outputTempFile != null) if (outputTempFile != null)
{ {
outputTempFile.delete(); outputTempFile.delete();
} }
return false; throw new SystemOperationCancelledException();
} }
} }
VirtualChild[] newEntriesAdded = new VirtualChild[numFiles]; VirtualChild[] newEntriesAdded = new VirtualChild[numFiles];
@ -1272,7 +1263,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{ {
outputTempFile.delete(); outputTempFile.delete();
} }
return false; throw new SystemOperationCancelledException();
} }
String childVirtualPath = virtualPath + "/" + names[i]; //$NON-NLS-1$ String childVirtualPath = virtualPath + "/" + names[i]; //$NON-NLS-1$
@ -1303,7 +1294,6 @@ public class SystemTarHandler implements ISystemArchiveHandler {
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace();
// close output stream // close output stream
if (outStream != null) if (outStream != null)
{ {
@ -1321,27 +1311,27 @@ public class SystemTarHandler implements ISystemArchiveHandler {
outputTempFile.delete(); outputTempFile.delete();
} }
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return false; throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
} }
finally finally
{ {
releaseMutex(mutexLockStatus); releaseMutex(mutexLockStatus);
} }
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return true;
} }
/** /**
* Create a tar file from the given virtual child objects, using the given * Create a tar file from the given virtual child objects, using the given
* output stream and omitting the children in the given set. * output stream and omitting the children in the given set.
* *
* @param children an array of virtual children from which to create a tar * @param children an array of virtual children from which to create a tar
* file. * file.
* @param outStream the tar output stream to use. * @param outStream the tar output stream to use.
* @param omitChildren the set of names for children that should be omitted * @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 * @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. * @throws IOException if an I/O exception occurs.
* @since org.eclipse.rse.services 3.0 * @since org.eclipse.rse.services 3.0
*/ */
@ -1661,26 +1651,25 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc) * (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) * @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 // update our cache before accessing cache
try { try {
updateCache(); updateCache();
} }
catch (IOException e) { catch (IOException e) {
// TODO: log error throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
return false;
} }
if (!file.exists() && !file.canRead()) { if (!file.exists() && !file.canRead()) {
return false; throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Cannot read " + file); //$NON-NLS-1$
} }
fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
// if the virtual file does not exist, we actually want to add // if the virtual file does not exist, we actually want to add
if (!exists(fullVirtualName, archiveOperationMonitor)) { if (!exists(fullVirtualName, archiveOperationMonitor)) {
return add(file, fullVirtualName, name, archiveOperationMonitor); add(file, fullVirtualName, name, archiveOperationMonitor);
} }
try { try {
@ -1707,8 +1696,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{ {
outputTempFile.delete(); outputTempFile.delete();
} }
return false; throw new SystemOperationCancelledException();
} }
// now append the new file to the tar // 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 // replace the current tar file with the new one, and do not update cache since
// we just did // we just did
replaceFile(outputTempFile, false); replaceFile(outputTempFile, false);
return true;
} }
catch (IOException e) { catch (IOException e) {
// TODO: log error throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
return false;
} }
} }
@ -1764,7 +1749,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#delete(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) * @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); boolean returnCode = doDelete(fullVirtualName, archiveOperationMonitor);
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
@ -1772,15 +1757,17 @@ public class SystemTarHandler implements ISystemArchiveHandler {
} }
/** /**
* Delete a virtual object. * Delete a virtual object.
* *
* @param fullVirtualName virtual path identifying the object * @param fullVirtualName virtual path identifying the object
* @param archiveOperationMonitor the operation progress monitor * @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 * @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; File outputTempFile = null;
int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK;
@ -1831,8 +1818,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{ {
outputTempFile.delete(); outputTempFile.delete();
} }
return false; throw new SystemOperationCancelledException();
} }
// delete the child from the cache (this will also delete its children if it // 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 // replace the current tar file with the new one, and do not update cache since
// we just did // we just did
replaceFile(outputTempFile, false); replaceFile(outputTempFile, false);
} else {
return true; throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
} }
catch (IOException e) { catch (IOException e) {
System.out.println(e.getMessage());
System.out.println("Could not delete " + fullVirtualName); //$NON-NLS-1$
if (!(outputTempFile == null)) outputTempFile.delete(); if (!(outputTempFile == null)) outputTempFile.delete();
return false; throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not delete " + fullVirtualName, e); //$NON-NLS-1$
} }
finally finally
{ {
releaseMutex(mutexLockStatus); releaseMutex(mutexLockStatus);
} }
return false; return true;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#rename(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) * @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); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$
boolean resultCode = false;
// if the original does not have any separator, simply rename it. // if the original does not have any separator, simply rename it.
if (i == -1) if (i == -1)
{ {
resultCode = fullRename(fullVirtualName, newName, archiveOperationMonitor); fullRename(fullVirtualName, newName, archiveOperationMonitor);
} }
// otherwise, get the parent path and append the new name to it. // otherwise, get the parent path and append the new name to it.
else else
{ {
String fullNewName = fullVirtualName.substring(0, i+1) + newName; String fullNewName = fullVirtualName.substring(0, i+1) + newName;
resultCode = fullRename(fullVirtualName, fullNewName, archiveOperationMonitor); fullRename(fullVirtualName, fullNewName, archiveOperationMonitor);
} }
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
return resultCode;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#move(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) * @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); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
destinationVirtualPath = ArchiveHandlerManager.cleanUpVirtualPath(destinationVirtualPath); 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 the original does not have any separator, simply append it to the destination path.
if (i == -1) { 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. // otherwise, get the last segment (the name) and append that to the destination path.
else { else {
String name = fullVirtualName.substring(i); 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) * (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#fullRename(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) * @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; int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK;
File outputTempFile = null; 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 the virtual file to be renamed does not exist, then quit
if (!child.exists()) { 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 // open a new temp file which will be our destination for the new tar file
outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$ outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
TarOutputStream outStream = getTarOutputStream(outputTempFile); TarOutputStream outStream = getTarOutputStream(outputTempFile);
@ -1999,11 +1979,10 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{ {
outputTempFile.delete(); outputTempFile.delete();
} }
return false; throw new SystemOperationCancelledException();
} }
// close the output stream // close the output stream
outStream.close(); outStream.close();
@ -2013,19 +1992,15 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// probably be more efficient // probably be more efficient
replaceFile(outputTempFile, true); replaceFile(outputTempFile, true);
updateTree(newOldNames); updateTree(newOldNames);
return true;
} }
else else
{ {
return false; throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace();
System.out.println("Could not rename " + fullVirtualName); //$NON-NLS-1$
if (!(outputTempFile == null)) outputTempFile.delete(); if (!(outputTempFile == null)) outputTempFile.delete();
return false; throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not rename " + fullVirtualName, e); //$NON-NLS-1$
} }
finally finally
{ {
@ -2036,15 +2011,16 @@ public class SystemTarHandler implements ISystemArchiveHandler {
/** /**
* Creates a tar file from the given virtual child objects, using the given * Creates a tar file from the given virtual child objects, using the given
* output stream and renaming entries according to hash map entries. * output stream and renaming entries according to hash map entries.
* *
* @param children an array of virtual children from which to create a tar * @param children an array of virtual children from which to create a tar
* file. * file.
* @param outStream the tar output stream to use. * @param outStream the tar output stream to use.
* @param renameMap a map containing associations between old names and new * @param renameMap a map containing associations between old names and new
* names. Old names are the keys in the map, and the values are * names. Old names are the keys in the map, and the values are the new
* the new names. * names.
* @param archiveOperationMonitor the operation progress monitor * @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. * @throws IOException if an I/O exception occurs.
* @since org.eclipse.rse.services 3.0 * @since org.eclipse.rse.services 3.0
*/ */
@ -2148,7 +2124,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getFiles(java.lang.String[], org.eclipse.rse.services.clientserver.ISystemOperationMonitor) * @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]; File[] files = new File[fullNames.length];
@ -2171,8 +2147,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
extractVirtualFile(fullNames[i], files[i], archiveOperationMonitor); extractVirtualFile(fullNames[i], files[i], archiveOperationMonitor);
} }
catch (IOException e) { catch (IOException e) {
// TODO: log error throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
return null;
} }
} }
@ -2183,36 +2158,42 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFolder(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) * @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 = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
fullVirtualName = fullVirtualName + "/"; //$NON-NLS-1$ fullVirtualName = fullVirtualName + "/"; //$NON-NLS-1$
boolean returnCode = createVirtualObject(fullVirtualName, archiveOperationMonitor); try {
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); createVirtualObject(fullVirtualName, archiveOperationMonitor);
return returnCode; } finally {
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
}
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFile(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) * @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); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
boolean returnCode = createVirtualObject(fullVirtualName, archiveOperationMonitor); try {
setArchiveOperationMonitorStatusDone(archiveOperationMonitor); createVirtualObject(fullVirtualName, archiveOperationMonitor);
return returnCode; } finally {
setArchiveOperationMonitorStatusDone(archiveOperationMonitor);
}
} }
/** /**
* Creates a virtual object that does not already exist in the virtual file * Creates a virtual object that does not already exist in the virtual file
* system. Creates an empty file in the tar file. * system. Creates an empty file in the tar file.
* *
* @param name the name of the virtual object. * @param name the name of the virtual object.
* @param archiveOperationMonitor the operation progress monitor * @param archiveOperationMonitor the operation progress monitor
* @return <code>true</code> if the object was created successfully, * @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 * @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; File outputTempFile = null;
TarOutputStream outStream = null; TarOutputStream outStream = null;
@ -2224,7 +2205,6 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{ {
updateCache(); updateCache();
// if the object already exists, return false // if the object already exists, return false
if (exists(name, archiveOperationMonitor)) { if (exists(name, archiveOperationMonitor)) {
return false; return false;
@ -2247,8 +2227,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{ {
outputTempFile.delete(); 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 // replace the current tar file with the new one, but do not update the cache
// since we have already updated to the cache // since we have already updated to the cache
replaceFile(outputTempFile, false); replaceFile(outputTempFile, false);
} else {
return true; throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace();
// close output stream // close output stream
if (outStream != null) if (outStream != null)
{ {
@ -2287,13 +2265,13 @@ public class SystemTarHandler implements ISystemArchiveHandler {
{ {
outputTempFile.delete(); outputTempFile.delete();
} }
return false; throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
} }
finally finally
{ {
releaseMutex(mutexLockStatus); releaseMutex(mutexLockStatus);
} }
return false; return true;
} }
/** /**
@ -2380,7 +2358,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#create() * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#create()
*/ */
public boolean create() { public void create() throws SystemMessageException {
try { try {
@ -2397,13 +2375,12 @@ public class SystemTarHandler implements ISystemArchiveHandler {
modTimeDuringCache = file.lastModified(); modTimeDuringCache = file.lastModified();
} }
catch (IOException e) { 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 // if the search string is empty or if it is "*", then return no matches
// since it is a file search // since it is a file search
if (matcher.isSearchStringEmpty() || matcher.isSearchStringAsterisk()) { if (matcher.isSearchStringEmpty() || matcher.isSearchStringAsterisk()) {
@ -2443,8 +2420,7 @@ public class SystemTarHandler implements ISystemArchiveHandler {
} }
} }
catch (IOException e) { catch (IOException e) {
// TODO: log error throw new SystemOperationFailedException(Activator.PLUGIN_ID, e);
return new SystemSearchLineMatch[0];
} }
} }
@ -2491,73 +2467,76 @@ public class SystemTarHandler implements ISystemArchiveHandler {
} }
/** /**
* Compresses the file <code>file</code> and adds it to the archive, * Compresses the file <code>file</code> and adds it to the archive, saving
* saving it in the encoding specified by <code>encoding</code> if saving * it in the encoding specified by <code>encoding</code> if saving in text
* in text mode. Places the file in the virtual directory * mode. Places the file in the virtual directory <code>virtualPath</code>.
* <code>virtualPath</code>. Pass the name as the parameter * Pass the name as the parameter <code>name</code>. If the virtual path
* <code>name</code>. If the virtual path does not exist in the archive, * does not exist in the archive, create it. If <code>file</code> is a
* create it. If <code>file</code> is a directory, copy it and its * directory, copy it and its contents into the archive, maintaining the
* contents into the archive, maintaining the tree structure. * tree structure.
* *
* @param file the file to be added to the archive * @param file the file to be added to the archive
* @param virtualPath the destination of the file * @param virtualPath the destination of the file
* @param name the name of the result virtual file * @param name the name of the result virtual file
* @param encoding the file encoding to use * @param encoding the file encoding to use
* @param registry the file type to use (text or binary) * @param registry the file type to use (text or binary)
* @param archiveOperationMonitor the operation progress monitor * @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 * @since org.eclipse.rse.services 3.0
*/ */
public boolean add(File file, String virtualPath, String name, public void add(File file, String virtualPath, String name, String encoding, ISystemFileTypes registry, ISystemOperationMonitor archiveOperationMonitor)
String encoding, ISystemFileTypes registry, ISystemOperationMonitor archiveOperationMonitor) { throws SystemMessageException {
return add(file, virtualPath, name, archiveOperationMonitor); add(file, virtualPath, name, archiveOperationMonitor);
} }
/* (non-Javadoc) /* (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) * @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, public void add(File file, String virtualPath, String name,
String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { String sourceEncoding, String targetEncoding, boolean isText,
return add(file, virtualPath, name, archiveOperationMonitor); ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
add(file, virtualPath, name, archiveOperationMonitor);
} }
/* (non-Javadoc) /* (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[]) * @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, public void add(File[] files, String virtualPath, String[] names,
String[] sourceEncodings, String[] targetEncodings, boolean[] isTexts, ISystemOperationMonitor archiveOperationMonitor) { String[] sourceEncodings, String[] targetEncodings, boolean[] isTexts,
return add(files, virtualPath, names, archiveOperationMonitor); ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
add(files, virtualPath, names, archiveOperationMonitor);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File, java.lang.String, boolean) * @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, public void extractVirtualDirectory(String dir, File destinationParent,
File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { File destination, String sourceEncoding, boolean isText,
return extractVirtualDirectory(dir, destinationParent, destination, archiveOperationMonitor); ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
extractVirtualDirectory(dir, destinationParent, destination, archiveOperationMonitor);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.lang.String, boolean) * @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, public void extractVirtualDirectory(String dir, File destinationParent, String sourceEncoding, boolean isText,
String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
return extractVirtualDirectory(dir, destinationParent, archiveOperationMonitor); extractVirtualDirectory(dir, destinationParent, archiveOperationMonitor);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualFile(java.lang.String, java.io.File, java.lang.String, boolean) * @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, public void extractVirtualFile(String fullVirtualName, File destination, String sourceEncoding, boolean isText,
String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
return extractVirtualFile(fullVirtualName, destination, archiveOperationMonitor); extractVirtualFile(fullVirtualName, destination, archiveOperationMonitor);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getClassification(java.lang.String) * @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); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName);
// default type // default type
@ -2612,18 +2591,19 @@ public class SystemTarHandler implements ISystemArchiveHandler {
return type; return type;
} }
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,
// TODO Auto-generated method stub ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
return false; 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) { public void add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes typeRegistery,
return add(file, virtualPath, name, archiveOperationMonitor); 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) { public void replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText,
// TODO Auto-generated method stub ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException {
return false; 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 * Get the tar output stream for a given file. This method can be overridden
* by subclass to return compressed output steam if needed. * by subclass to return compressed output steam if needed.
* *
* @param outputFile the output file to create stream * @param outputFile the output file to create stream
* @return OutputStream the output stream to write * @return OutputStream the output stream to write
* @throws FileNotFoundException when the output file doesn't exist * @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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,14 +7,15 @@
* *
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir, * component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* {Name} (company) - description of contribution. * {Name} (company) - description of contribution.
* Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread * 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; 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.File;
import java.io.IOException; import java.io.IOException;
import org.eclipse.rse.internal.services.Activator;
import org.eclipse.rse.services.clientserver.ISystemOperationMonitor; import org.eclipse.rse.services.clientserver.ISystemOperationMonitor;
import org.eclipse.rse.services.clientserver.SystemEncodingUtil; 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. * A simple structure for passing information about virtual files and folders.
*
* @author mjberger
*/ */
public final class VirtualChild { public final class VirtualChild {
@ -39,7 +45,7 @@ public final class VirtualChild {
protected ISystemArchiveHandler _handler; protected ISystemArchiveHandler _handler;
protected File _extractedFile; protected File _extractedFile;
protected File _containingArchive; protected File _containingArchive;
private String comment; private String comment;
private long compressedSize; private long compressedSize;
private String compressionMethod; private String compressionMethod;
@ -50,8 +56,8 @@ public final class VirtualChild {
* Constructs a new VirtualChild given a reference to its parent archive's * Constructs a new VirtualChild given a reference to its parent archive's
* handler, but does not populate any fields in the child. Clients must * handler, but does not populate any fields in the child. Clients must
* populate the fullName, name, path, and isDirectory fields. * populate the fullName, name, path, and isDirectory fields.
*/ */
public VirtualChild(ISystemArchiveHandler handler) public VirtualChild(ISystemArchiveHandler handler)
{ {
fullName = ""; //$NON-NLS-1$ fullName = ""; //$NON-NLS-1$
name = ""; //$NON-NLS-1$ name = ""; //$NON-NLS-1$
@ -60,14 +66,14 @@ public final class VirtualChild {
_handler = handler; _handler = handler;
_extractedFile = null; _extractedFile = null;
_containingArchive = null; _containingArchive = null;
comment = ""; //$NON-NLS-1$ comment = ""; //$NON-NLS-1$
compressedSize = -1; compressedSize = -1;
compressionMethod = ""; //$NON-NLS-1$ compressionMethod = ""; //$NON-NLS-1$
size = -1; size = -1;
timeStamp = -1; timeStamp = -1;
} }
/** /**
* Constructs a new VirtualChild given a reference to its parent archive's * Constructs a new VirtualChild given a reference to its parent archive's
* handler (<code>handler</code>), and immediately populates the name and path info * handler (<code>handler</code>), and immediately populates the name and path info
@ -79,9 +85,9 @@ public final class VirtualChild {
this(handler); this(handler);
renameTo(fullVirtualName); 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 * and immediately populates the name and path info
* for the VirtualChild given its <code>fullVirtualName</code>. Clients * for the VirtualChild given its <code>fullVirtualName</code>. Clients
* must still populate the isDirectory field. * must still populate the isDirectory field.
@ -94,7 +100,7 @@ public final class VirtualChild {
renameTo(fullVirtualName); renameTo(fullVirtualName);
_containingArchive = containingArchive; _containingArchive = containingArchive;
} }
/** /**
* @return This VirtualChild's parent archive's Handler. * @return This VirtualChild's parent archive's Handler.
*/ */
@ -102,7 +108,7 @@ public final class VirtualChild {
{ {
return _handler; return _handler;
} }
/** /**
* @return This VirtualChild's time stamp (retrieves the latest one * @return This VirtualChild's time stamp (retrieves the latest one
* from the archive). * from the archive).
@ -115,15 +121,15 @@ public final class VirtualChild {
*/ */
return timeStamp; return timeStamp;
} }
/** /**
* @param value the time stamp value * @param value the time stamp value
*/ */
public void setTimeStamp(long value) public void setTimeStamp(long value)
{ {
timeStamp = value; timeStamp = value;
} }
/** /**
* @return This VirtualChild's uncompressed size (retrieves the latest one * @return This VirtualChild's uncompressed size (retrieves the latest one
* from the archive). * from the archive).
@ -136,19 +142,19 @@ public final class VirtualChild {
*/ */
return size; return size;
} }
/** /**
* @param value the size value * @param value the size value
*/ */
public void setSize(long value) public void setSize(long value)
{ {
size = value; size = value;
} }
/** /**
* @return The comment associated with this VirtualChild. * @return The comment associated with this VirtualChild.
*/ */
public String getComment() public String getComment()
{ {
/* /*
if (_handler == null) return ""; //$NON-NLS-1$ if (_handler == null) return ""; //$NON-NLS-1$
@ -156,11 +162,11 @@ public final class VirtualChild {
*/ */
return comment; return comment;
} }
/** /**
* @param value the comment value * @param value the comment value
*/ */
public void setComment(String value) public void setComment(String value)
{ {
if (null != value) if (null != value)
{ {
@ -176,7 +182,7 @@ public final class VirtualChild {
* @return The amount of space this VirtualChild takes up in the archive * @return The amount of space this VirtualChild takes up in the archive
* in compressed form. * in compressed form.
*/ */
public long getCompressedSize() public long getCompressedSize()
{ {
/* /*
if (_handler == null) return 0; if (_handler == null) return 0;
@ -184,11 +190,11 @@ public final class VirtualChild {
*/ */
return compressedSize; return compressedSize;
} }
/** /**
* @param value the compressedSize value * @param value the compressedSize value
*/ */
public void setCompressedSize(long value) public void setCompressedSize(long value)
{ {
compressedSize = value; compressedSize = value;
} }
@ -196,7 +202,7 @@ public final class VirtualChild {
/** /**
* @return The method used to compress this VirtualChild. * @return The method used to compress this VirtualChild.
*/ */
public String getCompressionMethod() public String getCompressionMethod()
{ {
/* /*
if (_handler == null) return ""; //$NON-NLS-1$ if (_handler == null) return ""; //$NON-NLS-1$
@ -208,7 +214,7 @@ public final class VirtualChild {
/** /**
* @param value the compression method value * @param value the compression method value
*/ */
public void setCompressionMethod(String value) public void setCompressionMethod(String value)
{ {
if (null != value) if (null != value)
{ {
@ -219,12 +225,12 @@ public final class VirtualChild {
compressionMethod = ""; //$NON-NLS-1$ compressionMethod = ""; //$NON-NLS-1$
} }
} }
/** /**
* @return The actual minus compressed size of this VirtualChild, divided * @return The actual minus compressed size of this VirtualChild, divided
* by the actual size. * by the actual size.
*/ */
public double getCompressionRatio() public double getCompressionRatio()
{ {
/* /*
if (getSize() == 0) if (getSize() == 0)
@ -241,29 +247,29 @@ public final class VirtualChild {
{ {
return 1; return 1;
} }
return ((double)size - (double)compressedSize) / size; return ((double)size - (double)compressedSize) / size;
} }
/** /**
* @return The extracted file or directory represented by this VirtualChild from the archive. * @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, * timestamps on the cached and archived files do not match, the cached file is erased,
* and reextracted from the archive. * and reextracted from the archive.
*/ */
public File getExtractedFile() public File getExtractedFile() throws SystemMessageException
{ {
return getExtractedFile(SystemEncodingUtil.ENCODING_UTF_8, false, null); return getExtractedFile(SystemEncodingUtil.ENCODING_UTF_8, false, null);
} }
/** /**
* @return The extracted file or directory represented by this VirtualChild from the archive. * @return The extracted file or directory represented by this VirtualChild from the archive.
* Assumes that the file has been encoded in the encoding specified. * 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, * timestamps on the cached and archived files do not match, the cached file is erased,
* and reextracted from the archive. * 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; File returnedFile = null;
if (_extractedFile == null || _extractedFile.lastModified() != getTimeStamp()) if (_extractedFile == null || _extractedFile.lastModified() != getTimeStamp())
@ -307,11 +313,10 @@ public final class VirtualChild {
} }
catch (IOException e) catch (IOException e)
{ {
System.out.println("VirtualChild.getExtractedFile(): "); //$NON-NLS-1$ throw new SystemOperationFailedException(Activator.PLUGIN_ID, "VirtualChild.getExtractedFile()", e); //$NON-NLS-1$
System.out.println(e.getMessage());
} }
} }
if (isDirectory) if (isDirectory)
{ {
returnedFile = new File(_extractedFile, name); returnedFile = new File(_extractedFile, name);
@ -320,77 +325,80 @@ public final class VirtualChild {
{ {
returnedFile = _extractedFile; returnedFile = _extractedFile;
} }
//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 montor to done if it is not been cancelled.
if (null != archiveOperationMonitor && !archiveOperationMonitor.isCancelled()) if (null != archiveOperationMonitor && !archiveOperationMonitor.isCancelled())
{ {
archiveOperationMonitor.setDone(true); archiveOperationMonitor.setDone(true);
} }
return returnedFile; return returnedFile;
} }
/** /**
* Gets the extracted file or directory represented by this VirtualChild from the archive, * Gets the extracted file or directory represented by this VirtualChild
* and replaces the object referred to by <code>destination</code> with that extracted file or directory. * from the archive, and replaces the object referred to by
* Note that the extracted file is cached after it is extracted once, but if the * <code>destination</code> with that extracted file or directory. Note that
* timestamps on the cached and archived files do not match, the cached file is erased, * the extracted file is cached after it is extracted once, but if the
* and reextracted from the archive. * timestamps on the cached and archived files do not match, the cached file
* <code>destination</code> is always overwritten with either what is cached, or * is erased, and reextracted from the archive. <code>destination</code> is
* what is in the archive. * always overwritten with either what is cached, or what is in the archive.
* @return true if and only if the extraction succeeded. *
* @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, * Gets the extracted file or directory represented by this VirtualChild
* and replaces the object referred to by <code>destination</code> with that extracted file or directory. * from the archive, and replaces the object referred to by
* Note that the extracted file is cached after it is extracted once, but if the * <code>destination</code> with that extracted file or directory. Note that
* timestamps on the cached and archived files do not match, the cached file is erased, * the extracted file is cached after it is extracted once, but if the
* and reextracted from the archive. * timestamps on the cached and archived files do not match, the cached file
* <code>destination</code> is always overwritten with either what is cached, or * is erased, and reextracted from the archive. <code>destination</code> is
* what is in the archive. * always overwritten with either what is cached, or what is in the archive.
* @return true if and only if the extraction succeeded. *
* @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)
if (_handler == null) return false; throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID);
if (_extractedFile == null || if (_extractedFile == null ||
_extractedFile.lastModified() != getTimeStamp() || _extractedFile.lastModified() != getTimeStamp() ||
!destination.getAbsolutePath().equals(_extractedFile.getAbsolutePath()) !destination.getAbsolutePath().equals(_extractedFile.getAbsolutePath())
) )
{ {
if (isDirectory) if (isDirectory)
{ {
success = _handler.extractVirtualDirectory(fullName, destination.getParentFile(), destination, sourceEncoding, isText, archiveOperationMonitor); _handler.extractVirtualDirectory(fullName, destination.getParentFile(), destination, sourceEncoding, isText, archiveOperationMonitor);
} }
else else
{ {
success = _handler.extractVirtualFile(fullName, destination, sourceEncoding, isText, archiveOperationMonitor); _handler.extractVirtualFile(fullName, destination, sourceEncoding, isText, archiveOperationMonitor);
} }
_extractedFile = destination; _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()) if (null != archiveOperationMonitor && !archiveOperationMonitor.isCancelled())
{ {
archiveOperationMonitor.setDone(true); archiveOperationMonitor.setDone(true);
} }
return success;
} }
/** /**
* @return Whether or not this VirtualChild exists in the archive. * @return Whether or not this VirtualChild exists in the archive.
*/ */
public boolean exists() public boolean exists() throws SystemMessageException
{ {
if (_handler == null) return false; if (_handler == null) return false;
return _handler.exists(fullName, null); return _handler.exists(fullName, null);
} }
/** /**
* Renames this virtual child to newName. WARNING!! * Renames this virtual child to newName. WARNING!!
* This method does not change the underlying zip file, * This method does not change the underlying zip file,
@ -414,9 +422,9 @@ public final class VirtualChild {
} }
// force reextraction of temp file // force reextraction of temp file
_extractedFile = null; _extractedFile = null;
} }
/** /**
* @return The "standard" name for this VirtualChild, based on * @return The "standard" name for this VirtualChild, based on
* the handler type. * the handler type.
@ -426,12 +434,12 @@ public final class VirtualChild {
if (_handler == null) return fullName; if (_handler == null) return fullName;
return _handler.getStandardName(this); return _handler.getStandardName(this);
} }
public File getContainingArchive() public File getContainingArchive()
{ {
if (_handler == null) return _containingArchive; if (_handler == null) return _containingArchive;
return _handler.getArchive(); return _handler.getArchive();
} }
} }