From 55018268b07570e9cf8fb8de23d2cbe9d1ef95a8 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Mon, 14 Jul 2008 22:37:24 +0000 Subject: [PATCH] [235472] [ssh] Fix Properties of the file system root --- .../services/ssh/files/SftpFileService.java | 16 ++++++++++++---- .../services/ssh/files/SftpHostFile.java | 9 +++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java index c2bc18910c7..a2126e97a88 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java @@ -32,6 +32,7 @@ * Martin Oberhuber (Wind River) - [233651] Make ssh delete throw proper exceptions * Martin Oberhuber (Wind River) - [235477][ssh] SftpFileService.createFolder() fails for file named "a?*" * Martin Oberhuber (Wind River) - [235360][ftp][ssh][local] Return proper "Root" IHostFile + * David McKnight (IBM) - [235472] [ssh] RSE doesn't show correct properties of the file system root ("/") *******************************************************************************/ package org.eclipse.rse.internal.services.ssh.files; @@ -89,7 +90,6 @@ import org.eclipse.rse.services.files.IHostFilePermissions; import org.eclipse.rse.services.files.IHostFilePermissionsContainer; import org.eclipse.rse.services.files.RemoteFileIOException; import org.eclipse.rse.services.files.RemoteFileSecurityException; - public class SftpFileService extends AbstractFileService implements ISshService, IFilePermissionsService { @@ -489,7 +489,7 @@ public class SftpFileService extends AbstractFileService implements ISshService, } if (node==null) { boolean isRoot = (remoteParent == null || remoteParent.length() == 0); - node = new SftpHostFile(remoteParent, fileName, false, isRoot, false, 0, 0); + node = new SftpHostFile(isRoot ? null : remoteParent, fileName, false, isRoot, false, 0, 0); node.setExists(false); } return node; @@ -622,7 +622,7 @@ public class SftpFileService extends AbstractFileService implements ISshService, } } - SftpHostFile node = new SftpHostFile(parentPath, fileName, attrsTarget.isDir(), isRoot, attrs.isLink(), 1000L * attrs.getMTime(), attrs.getSize()); + SftpHostFile node = new SftpHostFile(isRoot ? null : parentPath, fileName, attrsTarget.isDir(), isRoot, attrs.isLink(), 1000L * attrs.getMTime(), attrs.getSize()); if (linkTarget!=null) { node.setLinkTarget(linkTarget); } @@ -862,7 +862,15 @@ public class SftpFileService extends AbstractFileService implements ISshService, } public IHostFile[] getRoots(IProgressMonitor monitor) { - IHostFile root = new SftpHostFile(null, "/", true, true, false, 0, 0); //$NON-NLS-1$ + IHostFile root = null; + try { + root = getFile(null, "/", monitor); + } + catch (SystemMessageException e){ + } + if (root == null){ + root = new SftpHostFile(null, "/", true, true, false, 0, 0); //$NON-NLS-1$ + } return new IHostFile[] { root }; } diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpHostFile.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpHostFile.java index 775a5c2205d..4aac4984978 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpHostFile.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpHostFile.java @@ -15,6 +15,7 @@ * Martin Oberhuber (Wind River) - Adapted from FTPHostFile. * David McKnight (IBM) - [209593] [api] add support for "file permissions" and "owner" properties for unix files * Martin Oberhuber (Wind River) - [235360][ftp][ssh][local] Return proper "Root" IHostFile + * Martin Oberhuber (Wind River) - [235472] [ssh] RSE doesn't show correct properties of the file system root ("/") *******************************************************************************/ package org.eclipse.rse.internal.services.ssh.files; @@ -52,6 +53,14 @@ public class SftpHostFile implements IHostFile, IHostFilePermissionsContainer { fName = name; if (name == null || name.length() == 0) { throw new IllegalArgumentException(); + } else if (parentPath == null || isRoot) { + //Root files must be consistent + if (parentPath !=null || !isRoot /* || !isDirectory */) { + throw new IllegalArgumentException(); + } + } else if (name.indexOf('/')>=0) { + //Non-root files must not have a relative path as name, or it would break parent/child relationships + throw new IllegalArgumentException(); } fIsDirectory = isDirectory; fIsRoot = isRoot;