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

[170916] [efs] Implementation for SSH should work. FTP and Dstore will not work for EFS. Those implementations will be ready in next milestone.

This commit is contained in:
Kushal Munir 2007-02-23 20:15:23 +00:00
parent 01c041cbb7
commit f90bc1961a
5 changed files with 258 additions and 25 deletions

View file

@ -33,6 +33,25 @@ Contributors:
</filesystemContributor>
</extension>
<!--
<extension
id="org.eclipse.rse.eclipse.filesystem"
point="org.eclipse.core.filesystem.filesystems">
<filesystem scheme="rse">
<run class="org.eclipse.rse.eclipse.filesystem.SSHFileSystem"/>
</filesystem>
</extension>
<extension
id="org.eclipse.rse.eclipse.filesystemSupport"
point="org.eclipse.ui.ide.filesystemSupport">
<filesystemContributor
scheme="rse"
class="org.eclipse.rse.eclipse.filesystem.SSHFileSystemContributor"
label="RSE">
</filesystemContributor>
</extension>
-->
<!-- remote eclipse filesystem not properly supported yet-->
<!--
<extension

View file

@ -0,0 +1,144 @@
package org.eclipse.rse.eclipse.filesystem;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
public class RSEFileCache {
private static RSEFileCache instance;
/**
* Constructor.
*/
private RSEFileCache() {
}
/**
* Gets the singleton instance.
* @return the singleton instance.
*/
public static RSEFileCache getInstance() {
if (instance == null) {
instance = new RSEFileCache();
}
return instance;
}
/**
* Returns whether the remote file exists in the cache. Returns <code>true</code> if the file exists in the cache, <code>false</code> otherwise.
* @param remoteFile the remote file.
* @return <code>true</code> if the file exists in the cache, <code>false</code> otherwise.
*/
public boolean isExistsInCache(IRemoteFile remoteFile) {
File file = getFromCache(remoteFile);
if (file != null) {
return true;
}
else {
return false;
}
}
/**
* Writes to the cache. If this is a directory, it simply creates the folder.
* @param remoteFile the remote file.
* @param inputStream the input stream with the contents of the remote file, or <code>null</code> if this is a directory.
* @return the file in the cache.
*/
public File writeToCache(IRemoteFile remoteFile, InputStream inputStream) {
String path = getCachePath(remoteFile.getParentRemoteFileSubSystem().getHost().getHostName(), remoteFile.getAbsolutePath());
File file = new File(path);
if (remoteFile.isDirectory()) {
if (!file.exists()) {
boolean success = file.mkdirs();
if (success) {
return file;
}
else {
return null;
}
}
else {
return file;
}
}
else {
File parent = file.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
}
FileOutputStream outputStream = null;
BufferedOutputStream bufOutputStream = null;
try {
outputStream = new FileOutputStream(file);
bufOutputStream = new BufferedOutputStream(outputStream);
byte[] buffer = new byte[4096];
int readCount;
while((readCount = inputStream.read(buffer)) > 0) {
bufOutputStream.write(buffer, 0, readCount);
}
bufOutputStream.flush();
inputStream.close();
bufOutputStream.close();
}
catch (Exception e) {
return null;
}
return file;
}
/**
* Gets the cached file for the remote file from the cache if any.
* @param remoteFile the remote file.
* @return the cached file, or <code>null</code> if none.
*/
public File getFromCache(IRemoteFile remoteFile) {
String path = getCachePath(remoteFile.getParentRemoteFileSubSystem().getHost().getHostName(), remoteFile.getAbsolutePath());
File file = new File(path);
if (file.exists()) {
return file;
}
else {
return null;
}
}
/**
* Gets the cache path.
* @param hostname the hostname.
* @param remotePath the remote path.
* @return the cache path.
*/
private String getCachePath(String hostname, String remotePath) {
IPath path = Platform.getStateLocation(Activator.getDefault().getBundle());
path = path.makeAbsolute();
path = path.addTrailingSeparator();
path = path.append(hostname);
path = path.addTrailingSeparator();
path = path.append(remotePath);
return path.toOSString();
}
}

View file

@ -53,6 +53,8 @@ import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile;
import org.eclipse.rse.files.ui.resources.UniversalFileTransferUtility;
import org.eclipse.rse.internal.subsystems.files.core.ISystemFilePreferencesConstants;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem;
import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileEmpty;
@ -188,12 +190,24 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto
{
if (_remoteFile.exists())
{
IFile file = null;
if (_remoteFile.isFile() && _subSystem.isConnected())
// IFile file = null;
if (_remoteFile.isFile() && _subSystem.isConnected() && _subSystem instanceof IFileServiceSubSystem)
{
IFileServiceSubSystem fileSubSystem = (IFileServiceSubSystem)_subSystem;
try {
return fileSubSystem.getFileService().getInputStream(monitor, _remoteFile.getParentPath(), _remoteFile.getName(), true);
}
catch (SystemMessageException e) {
return null;
}
}
if (_remoteFile.isDirectory()) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "This is a directory")); //$NON-NLS-1$
}
if (_remoteFile.getName().equals(".project") && _remoteFile.getLength() == 0) //$NON-NLS-1$
/* if (_remoteFile.getName().equals(".project") && _remoteFile.getLength() == 0) //$NON-NLS-1$
{
System.out.println("reading empty .project"); //$NON-NLS-1$
InputStream stream = getDummyProjectFileStream();
@ -208,7 +222,7 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto
{
}
//return stream;
/*
try
{
// only temp file has contents
@ -222,7 +236,7 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto
{
e.printStackTrace();
}
*/
}
{
@ -281,7 +295,7 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto
}
}
}
}*/
}
return null;
}
@ -365,15 +379,42 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto
public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
File file = null;
try {
// File file = null;
// try {
// create temp file first
try {
if (!_remoteFile.exists())
{
_subSystem.createFile(_remoteFile);
_remoteFile = _subSystem.getRemoteFileObject(_remoteFile.getAbsolutePath());
}
SystemEditableRemoteFile editable = new SystemEditableRemoteFile(_remoteFile);
}
catch (Exception e) {
return null;
}
if (_remoteFile.isFile() && _subSystem instanceof FileServiceSubSystem) {
IFileServiceSubSystem fileSubSystem = (IFileServiceSubSystem)_subSystem;
try {
return fileSubSystem.getFileService().getOutputStream(monitor, _remoteFile.getParentPath(), _remoteFile.getName(), true);
}
catch (SystemMessageException e) {
return null;
}
}
else {
if (_remoteFile.isDirectory()) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "This is a directory")); //$NON-NLS-1$
}
else {
return null;
}
}
/* SystemEditableRemoteFile editable = new SystemEditableRemoteFile(_remoteFile);
editable.download(monitor);
IFile localFile = editable.getLocalResource();
file = localFile.getLocation().toFile();
@ -401,7 +442,7 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto
finally {
monitor.done();
}
return null;
return null;*/
}
public IFileStore getChild(IPath path)
@ -457,11 +498,35 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto
public File toLocalFile(int options, IProgressMonitor monitor) throws CoreException
{
IResource file = null;
if (_remoteFile.exists())
{
if (_remoteFile.isFile() && _subSystem.isConnected())
if (options == EFS.CACHE) {
return super.toLocalFile(options, monitor);
}
else {
if (_remoteFile.exists() && _subSystem instanceof IFileServiceSubSystem)
{
RSEFileCache cache = RSEFileCache.getInstance();
IFileServiceSubSystem fileServiceSubSystem = (IFileServiceSubSystem)_subSystem;
InputStream inputStream = null;
try {
if (_remoteFile.isFile()) {
inputStream = fileServiceSubSystem.getFileService().getInputStream(monitor, _remoteFile.getParentRemoteFileSubSystem().getHost().getHostName(), _remoteFile.getName(), true);
}
return cache.writeToCache(_remoteFile, inputStream);
}
catch (SystemMessageException e) {
return null;
}
}
else {
return null;
}
}
/*if (_remoteFile.isFile() && _subSystem.isConnected())
{
file = (IResource)UniversalFileTransferUtility.copyRemoteResourceToWorkspace(_remoteFile, monitor);
}
@ -491,8 +556,7 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto
}
}
}
return null;
}*/
}
public void delete(int options, IProgressMonitor monitor) throws CoreException

View file

@ -819,10 +819,9 @@ public class SftpFileService extends AbstractFileService implements IFileService
String remotePath = remoteParent + '/' + remoteFile;
int mode = ChannelSftp.OVERWRITE;
MyProgressMonitor sftpMonitor = new MyProgressMonitor(monitor);
getChannel("SftpFileService.getInputStream " + remoteFile); //check the session is healthy //$NON-NLS-1$
ChannelSftp channel = (ChannelSftp)fSessionProvider.getSession().openChannel("sftp"); //$NON-NLS-1$
channel.connect();
stream = channel.get(remotePath, sftpMonitor, mode);
ChannelSftp channel = getChannel("SftpFileService.getInputStream " + remoteFile); //check the session is healthy //$NON-NLS-1$
stream = channel.get(remotePath);
Activator.trace("SftpFileService.getInputStream " + remoteFile + " ok"); //$NON-NLS-1$ //$NON-NLS-2$
}
catch (Exception e) {
@ -860,9 +859,8 @@ public class SftpFileService extends AbstractFileService implements IFileService
dst += remoteFile;
}
getChannel("SftpFileService.getOutputStream " + remoteFile); //check the session is healthy //$NON-NLS-1$
ChannelSftp channel = (ChannelSftp)fSessionProvider.getSession().openChannel("sftp"); //$NON-NLS-1$
channel.connect();
ChannelSftp channel = getChannel("SftpFileService.getOutputStream " + remoteFile); //check the session is healthy //$NON-NLS-1$
stream = channel.put(dst, sftpMonitor, mode);
Activator.trace("SftpFileService.getOutputStream " + remoteFile + " ok"); //$NON-NLS-1$ //$NON-NLS-2$
}

View file

@ -110,7 +110,15 @@ public class SystemFileTransferModeRegistry
// editor registry. We can be out of sync because we may not have
// been listening for editor registry changes (e.g. if our plugin wasn't
// started while those changes were made).
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbench wb = null;
try {
wb = PlatformUI.getWorkbench();
}
catch (Exception e) {
wb = null;
}
if (wb != null)
{
IEditorRegistry registry = wb.getEditorRegistry();