1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 15:45:25 +02:00

[208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND

This commit is contained in:
Kevin Doyle 2007-11-29 16:13:29 +00:00
parent 1aa4c0a448
commit 77a094ca8a
13 changed files with 415 additions and 16 deletions

View file

@ -24,6 +24,7 @@
* Martin Oberhuber (Wind River) - [191589] fix Rename by adding putInfo() for RSE EFS, and fetch symlink info
* Martin Oberhuber (Wind River) - [199552] fix deadlock with dstore-backed efs access
* David McKnight (IBM) - [207178] changing list APIs for file service and subsystems
* Kevin Doyle (IBM) - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND
********************************************************************************/
package org.eclipse.rse.internal.efs;
@ -649,6 +650,7 @@ public class RSEFileStoreImpl extends FileStore
* @see org.eclipse.core.filesystem.IFileStore#openOutputStream(int, org.eclipse.core.runtime.IProgressMonitor)
*/
public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException {
boolean append = (options & EFS.APPEND) != 0;
cacheRemoteFile(null);
IRemoteFile remoteFile = getRemoteFileObject(monitor, false);
if (remoteFile==null) {
@ -671,7 +673,7 @@ public class RSEFileStoreImpl extends FileStore
if (remoteFile.isFile()) {
try {
return subSys.getOutputStream(remoteFile.getParentPath(), remoteFile.getName(), true, monitor);
return subSys.getOutputStream(remoteFile.getParentPath(), remoteFile.getName(), true, append, monitor);
}
catch (SystemMessageException e) {
throw new CoreException(new Status(IStatus.ERROR,

View file

@ -28,6 +28,7 @@
* David McKnight (IBM) - [210109] store constants in IFileService rather than IFileServiceConstants
* David McKnight (IBM) - [210812] for text transfer, need to honour the preference (instead of straight binary)
* David McKnight (IBM) - [209704] [api] Ability to override default encoding conversion needed.
* Kevin Doyle (IBM) - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND
********************************************************************************/
package org.eclipse.rse.internal.services.dstore.files;
@ -1977,7 +1978,25 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
mode = IUniversalDataStoreConstants.TEXT_MODE;
}
DStoreOutputStream outputStream = new DStoreOutputStream(getDataStore(), remotePath, getEncoding(monitor), mode, unixStyle);
DStoreOutputStream outputStream = new DStoreOutputStream(getDataStore(), remotePath, getEncoding(monitor), mode, unixStyle, false);
return outputStream;
}
public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, boolean append, IProgressMonitor monitor) throws SystemMessageException {
String remotePath = remoteParent + getSeparator(remoteParent) + remoteFile;
int mode;
if (isBinary)
{
mode = IUniversalDataStoreConstants.BINARY_MODE;
}
else
{
mode = IUniversalDataStoreConstants.TEXT_MODE;
}
DStoreOutputStream outputStream = new DStoreOutputStream(getDataStore(), remotePath, getEncoding(monitor), mode, unixStyle, append);
return outputStream;
}

View file

@ -9,7 +9,7 @@
* component that contains this file: David McKnight.
*
* Contributors:
* {Name} (company) - description of contribution.
* Kevin Doyle (IBM) - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND
********************************************************************************/
package org.eclipse.rse.internal.services.dstore.files;
@ -27,12 +27,13 @@ public class DStoreOutputStream extends OutputStream
private String _encoding;
private int _mode;
private boolean _firstWrite = true;
private boolean _append;
private String _byteStreamHandlerId;
private String _localLineSep;
private String _targetLineSep;
private int _localLineSepLength;
public DStoreOutputStream(DataStore dataStore, String remotePath, String encoding, int mode, boolean unixStyle)
public DStoreOutputStream(DataStore dataStore, String remotePath, String encoding, int mode, boolean unixStyle, boolean append)
{
_dataStore = dataStore;
_remotePath = remotePath;
@ -51,20 +52,17 @@ public class DStoreOutputStream extends OutputStream
}
_localLineSepLength = _localLineSep.length();
}
_append = append;
}
public void close() throws IOException
{
// TODO Auto-generated method stub
super.close();
}
public void flush() throws IOException {
// TODO Auto-generated method stub
super.flush();
}
@ -80,7 +78,7 @@ public class DStoreOutputStream extends OutputStream
b = tempStr.getBytes(_encoding);
}
if (_firstWrite)
if (_firstWrite && !_append)
{
_firstWrite = false;
@ -136,7 +134,7 @@ public class DStoreOutputStream extends OutputStream
b = tempStr.getBytes(_encoding);
}
if (_firstWrite)
if (_firstWrite && !_append)
{
_firstWrite = false;
// send first set of bytes
@ -158,7 +156,7 @@ public class DStoreOutputStream extends OutputStream
String tempStr = new String(b, 0, 1);
b = tempStr.getBytes(_encoding);
}
if (_firstWrite)
if (_firstWrite && !_append)
{
_firstWrite = false;
// send first set of bytes

View file

@ -67,6 +67,7 @@
* David McKnight (IBM) - [207178] changing list APIs for file service and subsystems
* Javier Montalvo Orus (Symbian) - [208912] Cannot expand /C on a VxWorks SSH Server
* David McKnight (IBM) - [210109] store constants in IFileService rather than IFileServiceConstants
* Kevin Doyle (IBM) - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND
********************************************************************************/
package org.eclipse.rse.internal.services.files.ftp;
@ -1648,6 +1649,37 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
return stream;
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.services.files.AbstractFileService#getOutputStream(java.lang.String, java.lang.String, boolean, boolean, org.eclipse.core.runtime.IProgressMonitor)
*/
public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, boolean append, IProgressMonitor monitor) throws SystemMessageException {
remoteParent = checkEncoding(remoteParent);
remoteFile = checkEncoding(remoteFile);
if (monitor != null && monitor.isCanceled()){
throw new RemoteFileCancelledException();
}
OutputStream stream = null;
try {
FTPClient ftpClient = cloneFTPClient(isBinary);
clearCache(remoteParent);
ftpClient.changeWorkingDirectory(remoteParent);
if (!append){
stream = new FTPBufferedOutputStream(ftpClient.storeFileStream(remoteFile), ftpClient);
} else {
stream = new FTPBufferedOutputStream(ftpClient.appendFileStream(remoteFile), ftpClient);
}
}
catch (Exception e) {
throw new RemoteFileIOException(e);
}
return stream;
}
private void setDataConnectionMode()
{
if(_ftpPropertySet != null)

View file

@ -27,6 +27,7 @@
* Xuan Chen (IBM) - [209828] Need to move the Create operation to a job.
* David McKnight (IBM) - [210109] store constants in IFileService rather than IFileServiceConstants
* Xuan Chen (IBM) - [210555] [regression] NPE when deleting a file on SSH
* Kevin Doyle (IBM) - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND
********************************************************************************/
package org.eclipse.rse.internal.services.local.files;
@ -1653,6 +1654,28 @@ public class LocalFileService extends AbstractFileService implements IFileServic
return stream;
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.services.files.AbstractFileService#getOutputStream(java.lang.String, java.lang.String, boolean, boolean, org.eclipse.core.runtime.IProgressMonitor)
*/
public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, boolean append, IProgressMonitor monitor) throws SystemMessageException {
File file = new File(remoteParent, remoteFile);
OutputStream stream = null;
try {
if (!append) {
stream = new FileOutputStream(file);
} else {
stream = new FileOutputStream(file, true);
}
}
catch (Exception e) {
throw new RemoteFileIOException(e);
}
return stream;
}
public SystemMessage getMessage(String messageID) {
return (_msgProvider != null ? _msgProvider.getMessage(messageID) : super.getMessage(messageID));
}

View file

@ -18,6 +18,7 @@
* David McKnight (IBM) - [207178] changing list APIs for file service and subsystems
* Martin Oberhuber (Wind River) - [208912] Cannot expand /C on a VxWorks SSH Server
* David McKnight (IBM) - [210109] store constants in IFileService rather than IFileServiceConstants
* Kevin Doyle (IBM) - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND
*******************************************************************************/
package org.eclipse.rse.internal.services.ssh.files;
@ -1110,4 +1111,44 @@ public class SftpFileService extends AbstractFileService implements IFileService
}
return stream;
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.services.files.AbstractFileService#getOutputStream(java.lang.String, java.lang.String, boolean, boolean, org.eclipse.core.runtime.IProgressMonitor)
*/
public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, boolean append, IProgressMonitor monitor) throws SystemMessageException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
OutputStream stream = null;
String dst = remoteParent;
if (remoteFile!=null) {
dst = concat(remoteParent, remoteFile);
}
try {
SftpProgressMonitor sftpMonitor = new MyProgressMonitor(monitor);
int mode;
if (!append) {
mode = ChannelSftp.OVERWRITE;
} else {
mode = ChannelSftp.APPEND;
}
getChannel("SftpFileService.getOutputStream " + remoteFile); //check the session is healthy //$NON-NLS-1$
ChannelSftp channel = (ChannelSftp)fSessionProvider.getSession().openChannel("sftp"); //$NON-NLS-1$
channel.connect();
stream = new SftpBufferedOutputStream(channel.put(recodeSafe(dst), sftpMonitor, mode), channel);
Activator.trace("SftpFileService.getOutputStream " + remoteFile + " ok"); //$NON-NLS-1$ //$NON-NLS-2$
}
catch (Exception e) {
Activator.trace("SftpFileService.getOutputStream " + dst + " failed: " + e.toString()); //$NON-NLS-1$ //$NON-NLS-2$
throw makeSystemMessageException(e);
}
if (monitor.isCanceled()) {
throw new RemoteFileCancelledException();
}
return stream;
}
}

View file

@ -20,6 +20,7 @@
* Martin Oberhuber (Wind River) - [210109] no need to declare IFileService constants in AbstractFileService
* David McKnight (IBM) - [209704] [api] Ability to override default encoding conversion needed.
* Xuan Chen (IBM) - [210555] [regression] NPE when deleting a file on SSH
* Kevin Doyle (IBM) - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND
********************************************************************************/
package org.eclipse.rse.services.files;
@ -206,4 +207,8 @@ public abstract class AbstractFileService implements IFileService
public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, IProgressMonitor monitor) throws SystemMessageException {
return null;
}
public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, boolean append, IProgressMonitor monitor) throws SystemMessageException {
return null;
}
}

View file

@ -19,6 +19,7 @@
* David McKnight (IBM) - [162195] new APIs for upload multi and download multi
* David McKnight (IBM) - [209552] API changes to use multiple and getting rid of deprecated
* David McKnight (IBM) - [210109] store constants in IFileService rather than IFileServiceConstants
* Kevin Doyle (IBM) - [208778] new API getOutputSteam for getting an output stream in append mode
********************************************************************************/
package org.eclipse.rse.services.files;
@ -454,8 +455,22 @@ public interface IFileService extends IService
* @return the input stream to access the contents of the remote file.
* @throws SystemMessageException if an error occurs.
* @since 2.0
* @deprecated As of 3.0M4, replaced by
* {@link #getOutputStream(String, String, boolean, boolean, IProgressMonitor)}
*/
public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, IProgressMonitor monitor) throws SystemMessageException;
/**
* Gets the output stream to write/append to a remote file. Clients should close the output stream when done.
* @param remoteParent the absolute path of the parent.
* @param remoteFile the name of the remote file.
* @param isBinary <code>true</code> if the file is a binary file, <code>false</code> otherwise.
* @param append <code>true</code> if you want to append to a file, <code>false</code> if you want to overwrite the file's contents.
* @param monitor the progress monitor.
* @return the input stream to access the contents of the remote file.
* @throws SystemMessageException if an error occurs.
* @since 3.0
*/
public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, boolean append, IProgressMonitor monitor) throws SystemMessageException;
}

View file

@ -24,7 +24,8 @@
* David McKnight (IBM) - [207178] changing list APIs for file service and subsystems
* David McKnight (IBM) - [162195] new APIs for upload multi and download multi
* David McKnight (IBM) - [203114] don't treat XML files specially (no hidden prefs for bin vs text)
* David McKnight (IBM) - [209552] API changes to use multiple and getting rid of deprecated
* David McKnight (IBM) - [209552] API changes to use multiple and getting rid of deprecated
* Kevin Doyle (IBM) - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND
*******************************************************************************/
package org.eclipse.rse.subsystems.files.core.servicesubsystem;
@ -1028,4 +1029,8 @@ public final class FileServiceSubSystem extends RemoteFileSubSystem implements I
return new FileSubSystemOutputStream(getFileService().getOutputStream(remoteParent, remoteFile, isBinary, monitor), remoteParent, remoteFile, this);
}
public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, boolean append, IProgressMonitor monitor) throws SystemMessageException {
return new FileSubSystemOutputStream(getFileService().getOutputStream(remoteParent, remoteFile, isBinary, append, monitor), remoteParent, remoteFile, this);
}
}

View file

@ -18,6 +18,7 @@
* David McKnight (IBM) - [207178] changing list APIs for file service and subsystems
* David McKnight (IBM) - [162195] new APIs for upload multi and download multi
* David McKnight (IBM) - [209552] API changes to use multiple and getting rid of deprecated
* Kevin Doyle (IBM) - [208778] new API getOutputSteam for getting an output stream in append mode
*******************************************************************************/
package org.eclipse.rse.subsystems.files.core.subsystems;
@ -657,7 +658,22 @@ public interface IRemoteFileSubSystem extends ISubSystem {
* @param monitor the progress monitor.
* @throws SystemMessageException if an error occurs.
* @since 2.0
* @deprecated As of 3.0M4, replaced by
* {@link #getOutputStream(String, String, boolean, boolean, IProgressMonitor)}
*/
public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, IProgressMonitor monitor) throws SystemMessageException;
/**
* Gets the output stream to write/append to a remote file. Clients should close the output stream when done. Implementations should not return <code>null</code>.
* @param remoteParent the absolute path of the parent.
* @param remoteFile the name of the remote file.
* @param isBinary <code>true</code> if the file is a binary file, <code>false</code> otherwise.
* @param append <code>true</code> if you want to append to a file, <code>false</code> if you want to overwrite the file's contents.
* @return the input stream to access the contents of the remote file.
* @param monitor the progress monitor.
* @throws SystemMessageException if an error occurs.
* @since 3.0
*/
public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, boolean append, IProgressMonitor monitor) throws SystemMessageException;
}

View file

@ -20,7 +20,8 @@ Require-Bundle: org.junit,
org.eclipse.rse.services.files.ftp;bundle-version="[3.0.0,4.0.0)",
org.eclipse.rse.subsystems.files.ftp;bundle-version="[3.0.0,4.0.0)",
org.eclipse.core.filesystem,
org.eclipse.rse.files.ui
org.eclipse.rse.files.ui,
org.eclipse.rse.efs
Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Export-Package: org.eclipse.rse.tests,

View file

@ -0,0 +1,242 @@
/********************************************************************************
* Copyright (c) 2007 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: Kevin Doyle
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.tests.subsystems.files;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemRegistry;
import org.eclipse.rse.core.model.SystemStartHere;
import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.internal.efs.RSEFileStore;
import org.eclipse.rse.services.clientserver.PathUtility;
import org.eclipse.rse.services.files.IFileService;
import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
import org.eclipse.rse.ui.ISystemPreferencesConstants;
import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.internal.model.SystemRegistry;
public class FileAppendOutputSteamTestCase extends FileServiceBaseTest {
private String SYSTEM_ADDRESS = "sles8rm";//"SLES8RM";
private String USER_ID = "xxxxxx";
private String PASSWORD = "xxxxxx"; //"xxxxxx";
private IHost host = null;
private IRemoteFile tempDirectory;
private IRemoteFileSubSystem getRemoteFileSubSystem(IHost host) {
IRemoteFileSubSystem fss = null;
ISystemRegistry sr = SystemStartHere.getSystemRegistry();
ISubSystem[] ss = sr.getServiceSubSystems(host, IFileService.class);
for (int i=0; i<ss.length; i++) {
if (ss[i] instanceof FileServiceSubSystem) {
fss = (IRemoteFileSubSystem)ss[i];
return fss;
}
}
return null;
}
protected IHost getSSHHost()
{
IHost sshHost = null;
String SYSTEM_TYPE_ID = IRSESystemType.SYSTEMTYPE_SSH_ONLY_ID;
String SYSTEM_NAME = SYSTEM_ADDRESS + "_ssh";
sshHost = getRemoteSystemConnection(SYSTEM_TYPE_ID, SYSTEM_ADDRESS, SYSTEM_NAME, USER_ID, PASSWORD);
assertNotNull(sshHost);
return sshHost;
}
protected IHost getFTPHost()
{
IHost ftpHost = null;
String SYSTEM_TYPE_ID = IRSESystemType.SYSTEMTYPE_FTP_ONLY_ID;
String SYSTEM_NAME = SYSTEM_ADDRESS + "_ftp";
ftpHost = getRemoteSystemConnection(SYSTEM_TYPE_ID, SYSTEM_ADDRESS, SYSTEM_NAME, USER_ID, PASSWORD);
assertNotNull(ftpHost);
return ftpHost;
}
protected IHost getLocalHost() {
IHost localHost = null;
String SYSTEM_TYPE_ID = IRSESystemType.SYSTEMTYPE_LOCAL_ID;
String SYSTEM_NAME = SYSTEM_ADDRESS + "_local";
localHost = getRemoteSystemConnection(SYSTEM_TYPE_ID, "localhost", SYSTEM_NAME, "", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertNotNull(localHost);
return localHost;
}
protected IHost getDStoreHost()
{
IHost dstoreHost = null;
String SYSTEM_TYPE_ID = IRSESystemType.SYSTEMTYPE_LINUX_ID;
String SYSTEM_NAME = SYSTEM_ADDRESS + "_dstore";
//Ensure that the SSL acknowledge dialog does not show up.
//We need to setDefault first in order to set the value of a preference.
IPreferenceStore store = RSEUIPlugin.getDefault().getPreferenceStore();
store.setDefault(ISystemPreferencesConstants.ALERT_SSL, ISystemPreferencesConstants.DEFAULT_ALERT_SSL);
store.setDefault(ISystemPreferencesConstants.ALERT_NONSSL, ISystemPreferencesConstants.DEFAULT_ALERT_NON_SSL);
store.setValue(ISystemPreferencesConstants.ALERT_SSL, false);
store.setValue(ISystemPreferencesConstants.ALERT_NONSSL, false);
dstoreHost = getRemoteSystemConnection(SYSTEM_TYPE_ID, SYSTEM_ADDRESS, SYSTEM_NAME, USER_ID, PASSWORD);
assertNotNull(dstoreHost);
return dstoreHost;
}
public void testRSEFileStoreAppendOutputStream() throws Exception {
// Go through each connection type setting it up and calling
// appendToOutputStream(host)
host = getLocalHost();
appendToOutputStream();
host = getFTPHost();
appendToOutputStream();
host = getDStoreHost();
appendToOutputStream();
host = getSSHHost();
appendToOutputStream();
}
public void appendToOutputStream() throws Exception {
// RSE URI: rse://SYSTEM_ADDRESS/PATH_TO_FIlE
OutputStream outputStream = null;
InputStream inputStream = null;
// Create temporary folder
FileServiceSubSystem inputFss = (FileServiceSubSystem) getRemoteFileSubSystem(host);
inputFss.connect(new NullProgressMonitor(), false);
IRemoteFile homeDirectory = inputFss.getRemoteFileObject(".", new NullProgressMonitor());
String baseFolderName = "rsetest";
String homeFolderName = homeDirectory.getAbsolutePath();
String testFolderName = FileServiceHelper.getRandomLocation(inputFss, homeFolderName, baseFolderName, new NullProgressMonitor());
IRemoteFile targetDir = createFileOrFolder(inputFss, homeFolderName, testFolderName, true);
tempDirectory = targetDir;
String path = targetDir.getAbsolutePath();
String systemType = host.getSystemType().getLabel();
if (host.getSystemType().isWindows()) {
path = path.replace('\\', '/');
}
path = fixPathForURI(path);
URI uri = new URI("rse", host.getHostName(), path, null);
IFileStore parentFS = RSEFileStore.getInstance(uri);
createDir(parentFS, true);
IFileStore childFS = parentFS.getChild("append.txt");
outputStream = childFS.openOutputStream(EFS.APPEND, new NullProgressMonitor());
// Append to an empty file
String contents = getRandomString();
byte[] readBytes = new byte[contents.length()];
outputStream.write(contents.getBytes());
outputStream.close();
inputStream = childFS.openInputStream(EFS.NONE, new NullProgressMonitor());
inputStream.read(readBytes);
String input = new String(readBytes);
inputStream.close();
assertTrue(systemType + ": Contents incorrect when appending to an empty file. Expected Contents: " + contents + " Actual Contents: " + input, contents.equals(input));
outputStream = childFS.openOutputStream(EFS.APPEND, new NullProgressMonitor());
// Append to a not empty file
String write = " " + getRandomString();
contents += write;
outputStream.write(write.getBytes());
outputStream.close();
readBytes = new byte[contents.length()];
inputStream = childFS.openInputStream(EFS.NONE, new NullProgressMonitor());
inputStream.read(readBytes);
input = new String(readBytes);
inputStream.close();
assertTrue(systemType + ": Contents incorrect when appending to a non-empty file. Expected Contents: " + contents + " Actual Contents: " + input, contents.equals(input));
// Cleanup, so IFileStore uses the correct connection next time.
cleanup();
}
/**
* Adapt a local file system path such that it can be used as
* path in an URI. Converts path delimiters do '/' default
* delimiter, and adds a slash in front if necessary.
*
* Copied from RSEFileSystemContributor as it's private
* @param path the path to adapt
* @return adapted path
*/
private String fixPathForURI(String path) {
String sep = PathUtility.getSeparator(path);
if (!sep.equals("/")) { //$NON-NLS-1$
path = path.replace(sep.charAt(0), '/');
}
//<adapted from org.eclipse.core.filesystem.URIUtil.toURI() Copyright(c) 2005, 2006 IBM>
final int length = path.length();
StringBuffer pathBuf = new StringBuffer(length + 3);
//There must be a leading slash in a hierarchical URI
if (length > 0 && (path.charAt(0) != '/'))
pathBuf.append('/');
//additional double-slash for UNC paths to distinguish from host separator
if (path.startsWith("//")) //$NON-NLS-1$
pathBuf.append('/').append('/');
pathBuf.append(path);
//</adapted from org.eclipse.core.filesystem.URIUtil.toURI() Copyright(c) 2005, 2006 IBM>
return pathBuf.toString();
}
public void cleanup() throws Exception {
if (host != null) {
if (tempDirectory != null) {
IRemoteFileSubSystem fss = getRemoteFileSubSystem(host);
fss.delete(tempDirectory, new NullProgressMonitor());
fss.disconnect();
tempDirectory = null;
}
SystemRegistry.getInstance().deleteHost(host);
host = null;
}
}
public void tearDown() throws Exception {
cleanup();
super.tearDown();
}
}

View file

@ -239,8 +239,8 @@ public class FileServiceBaseTest extends RSEBaseConnectionTestCase {
//----------------------------------------------------------------------
protected IFileStore createDir(IFileStore store, boolean clear) throws CoreException {
if (clear && store.fetchInfo().exists())
store.delete(EFS.NONE, null);
store.mkdir(EFS.NONE, null);
store.delete(EFS.NONE, new NullProgressMonitor());
store.mkdir(EFS.NONE, new NullProgressMonitor());
IFileInfo info = store.fetchInfo();
assertTrue("createDir.1", info.exists());
assertTrue("createDir.1", info.isDirectory());