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

[235360][ftp][ssh][local] Return proper "Root" IHostFile

This commit is contained in:
Martin Oberhuber 2008-06-03 23:24:51 +00:00
parent aa2297c58b
commit 06bb64c597
6 changed files with 142 additions and 88 deletions

View file

@ -22,6 +22,7 @@
* Martin Oberhuber (Wind River) - [204669] Fix ftp path concatenation on systems using backslash separator * Martin Oberhuber (Wind River) - [204669] Fix ftp path concatenation on systems using backslash separator
* Javier Montalvo Orus (Symbian) - [198692] FTP should mark files starting with "." as hidden * Javier Montalvo Orus (Symbian) - [198692] FTP should mark files starting with "." as hidden
* David McKnight (IBM) - [209593] [api] add support for "file permissions" and "owner" properties for unix files * 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
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.internal.services.files.ftp; package org.eclipse.rse.internal.services.files.ftp;
@ -39,7 +40,7 @@ import org.eclipse.rse.services.files.IHostFilePermissionsContainer;
public class FTPHostFile implements IHostFile, IHostFilePermissionsContainer public class FTPHostFile implements IHostFile, IHostFilePermissionsContainer
{ {
private String _name; private String _name;
private String _parentPath; private String _parentPath;
private boolean _isDirectory; private boolean _isDirectory;
@ -53,11 +54,14 @@ public class FTPHostFile implements IHostFile, IHostFilePermissionsContainer
private boolean _exists; private boolean _exists;
private IHostFilePermissions _permissions; private IHostFilePermissions _permissions;
private FTPFile _ftpFile; private FTPFile _ftpFile;
public FTPHostFile(String parentPath, String name, boolean isDirectory, boolean isRoot, long lastModified, long size, boolean exists) public FTPHostFile(String parentPath, String name, boolean isDirectory, boolean isRoot, long lastModified, long size, boolean exists)
{ {
_parentPath = parentPath; _parentPath = parentPath;
_name = name; _name = name;
if (name == null || name.length() == 0) {
throw new IllegalArgumentException();
}
_isDirectory = isDirectory; _isDirectory = isDirectory;
_lastModified = lastModified; _lastModified = lastModified;
_size = size; _size = size;
@ -72,52 +76,52 @@ public class FTPHostFile implements IHostFile, IHostFilePermissionsContainer
{ {
_parentPath = parentPath; _parentPath = parentPath;
_ftpFile = ftpFile; _ftpFile = ftpFile;
_name = ftpFile.getName(); _name = ftpFile.getName();
_isDirectory = ftpFile.isDirectory(); _isDirectory = ftpFile.isDirectory();
_isLink = ftpFile.isSymbolicLink(); _isLink = ftpFile.isSymbolicLink();
_lastModified = ftpFile.getTimestamp().getTimeInMillis(); _lastModified = ftpFile.getTimestamp().getTimeInMillis();
_size = ftpFile.getSize(); _size = ftpFile.getSize();
_isArchive = internalIsArchive(); _isArchive = internalIsArchive();
_canRead = ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION); _canRead = ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION);
_canWrite = ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION); _canWrite = ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION);
_isRoot = false; _isRoot = false;
_exists = true; _exists = true;
initPermissions(ftpFile); initPermissions(ftpFile);
} }
public long getSize() public long getSize()
{ {
return _size; return _size;
} }
public boolean isDirectory() public boolean isDirectory()
{ {
return _isDirectory; return _isDirectory;
} }
public boolean isFile() public boolean isFile()
{ {
return !(_isDirectory || _isRoot); return !(_isDirectory || _isRoot);
} }
public boolean isLink() public boolean isLink()
{ {
return _isLink; return _isLink;
} }
public String getName() public String getName()
{ {
return _name; return _name;
} }
public boolean canRead() { public boolean canRead() {
return _canRead; return _canRead;
} }
@ -170,35 +174,46 @@ public class FTPHostFile implements IHostFile, IHostFilePermissionsContainer
public boolean isRoot() { public boolean isRoot() {
return _isRoot; return _isRoot;
} }
public String getParentPath() { public String getParentPath() {
return _parentPath; return _parentPath;
} }
public void renameTo(String newAbsolutePath) public void renameTo(String newAbsolutePath)
{ {
int i = newAbsolutePath.lastIndexOf("/"); //$NON-NLS-1$ int i = newAbsolutePath.lastIndexOf("/"); //$NON-NLS-1$
if (i == -1) if (i == -1) {
{ //Rename inside the same parent folder.
//FIXME is this really what was desired here? Or would we rename Roots?
//Renaming Roots isn't possible, I'd think.
_name = newAbsolutePath; _name = newAbsolutePath;
} }
else else if (i == 0) {
{ // Renaming a root folder
if (newAbsolutePath.length()==1) {
//rename to root "/" -- should this work?
_parentPath = null;
_isRoot = true;
_name = newAbsolutePath;
} else {
_parentPath = "/"; //$NON-NLS-1$
_name = newAbsolutePath.substring(i + 1);
}
} else {
_parentPath = newAbsolutePath.substring(0, i); _parentPath = newAbsolutePath.substring(0, i);
_name = newAbsolutePath.substring(i+1); _name = newAbsolutePath.substring(i+1);
} }
_isArchive = internalIsArchive(); _isArchive = internalIsArchive();
} }
public int getUserPermissions() public int getUserPermissions()
{ {
int userRead = 0; int userRead = 0;
int userWrite = 0; int userWrite = 0;
int userExec = 0; int userExec = 0;
//user //user
if(_ftpFile!=null) if(_ftpFile!=null)
{ {
@ -211,18 +226,18 @@ public class FTPHostFile implements IHostFile, IHostFilePermissionsContainer
userRead = _canRead ? 1 : 0; userRead = _canRead ? 1 : 0;
userWrite = _canWrite ? 1 : 0; userWrite = _canWrite ? 1 : 0;
userExec = 0; userExec = 0;
} }
return userRead << 2 | userWrite << 1 | userExec; return userRead << 2 | userWrite << 1 | userExec;
} }
public int getGroupPermissions() public int getGroupPermissions()
{ {
int groupRead = 0; int groupRead = 0;
int groupWrite = 0; int groupWrite = 0;
int groupExec = 0; int groupExec = 0;
//group //group
if(_ftpFile!=null) if(_ftpFile!=null)
{ {
@ -230,16 +245,16 @@ public class FTPHostFile implements IHostFile, IHostFilePermissionsContainer
groupWrite = _ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION) ? 1 : 0; groupWrite = _ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION) ? 1 : 0;
groupExec = _ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION) ? 1 : 0; groupExec = _ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION) ? 1 : 0;
} }
return groupRead << 2 | groupWrite << 1 | groupExec; return groupRead << 2 | groupWrite << 1 | groupExec;
} }
public int getOtherPermissions() public int getOtherPermissions()
{ {
int otherRead = 0; int otherRead = 0;
int otherWrite = 0; int otherWrite = 0;
int otherExec = 0; int otherExec = 0;
//other //other
if(_ftpFile!=null) if(_ftpFile!=null)
{ {
@ -247,28 +262,28 @@ public class FTPHostFile implements IHostFile, IHostFilePermissionsContainer
otherWrite = _ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION) ? 1 : 0; otherWrite = _ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION) ? 1 : 0;
otherExec = _ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION) ? 1 : 0; otherExec = _ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION) ? 1 : 0;
} }
return otherRead << 2 | otherWrite << 1 | otherExec; return otherRead << 2 | otherWrite << 1 | otherExec;
} }
protected boolean internalIsArchive() protected boolean internalIsArchive()
{ {
return ArchiveHandlerManager.getInstance().isArchive(new File(getAbsolutePath())) return ArchiveHandlerManager.getInstance().isArchive(new File(getAbsolutePath()))
&& !ArchiveHandlerManager.isVirtual(getAbsolutePath()); && !ArchiveHandlerManager.isVirtual(getAbsolutePath());
} }
public void setIsDirectory(boolean isDirectory) public void setIsDirectory(boolean isDirectory)
{ {
_isDirectory = isDirectory; _isDirectory = isDirectory;
} }
public String getClassification() { public String getClassification() {
String result; String result;
String linkTarget; String linkTarget;
if (isLink()) { if (isLink()) {
result = "symbolic link"; //$NON-NLS-1$ result = "symbolic link"; //$NON-NLS-1$
if ((linkTarget = _ftpFile.getLink()) !=null) { if ((linkTarget = _ftpFile.getLink()) !=null) {
@ -304,13 +319,13 @@ public class FTPHostFile implements IHostFile, IHostFilePermissionsContainer
_permissions.setPermission(IHostFilePermissions.PERM_GROUP_EXECUTE, ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)); _permissions.setPermission(IHostFilePermissions.PERM_GROUP_EXECUTE, ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
_permissions.setPermission(IHostFilePermissions.PERM_OTHER_READ, ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)); _permissions.setPermission(IHostFilePermissions.PERM_OTHER_READ, ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
_permissions.setPermission(IHostFilePermissions.PERM_OTHER_WRITE, ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION)); _permissions.setPermission(IHostFilePermissions.PERM_OTHER_WRITE, ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
_permissions.setPermission(IHostFilePermissions.PERM_OTHER_EXECUTE, ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)); _permissions.setPermission(IHostFilePermissions.PERM_OTHER_EXECUTE, ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
_permissions.setUserOwner(ftpFile.getUser()); _permissions.setUserOwner(ftpFile.getUser());
_permissions.setGroupOwner(ftpFile.getGroup()); _permissions.setGroupOwner(ftpFile.getGroup());
} }
public IHostFilePermissions getPermissions() { public IHostFilePermissions getPermissions() {
return _permissions; return _permissions;
} }
@ -318,5 +333,5 @@ public class FTPHostFile implements IHostFile, IHostFilePermissionsContainer
public void setPermissions(IHostFilePermissions permissions) { public void setPermissions(IHostFilePermissions permissions) {
_permissions = permissions; _permissions = permissions;
} }
} }

View file

@ -77,6 +77,7 @@
* Martin Oberhuber (Wind River) - [218040] FTP should support permission modification * Martin Oberhuber (Wind River) - [218040] FTP should support permission modification
* Martin Oberhuber (Wind River) - [234045] FTP Permission Error Handling * Martin Oberhuber (Wind River) - [234045] FTP Permission Error Handling
* Martin Oberhuber (Wind River) - [235463][ftp][dstore] Incorrect case sensitivity reported on windows-remote * Martin Oberhuber (Wind River) - [235463][ftp][dstore] Incorrect case sensitivity reported on windows-remote
* Martin Oberhuber (Wind River) - [235360][ftp][ssh][local] Return proper "Root" IHostFile
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.internal.services.files.ftp; package org.eclipse.rse.internal.services.files.ftp;
@ -321,6 +322,8 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
* @throws SystemMessageException if information is lost * @throws SystemMessageException if information is lost
*/ */
protected String checkEncoding(String s) throws SystemMessageException { protected String checkEncoding(String s) throws SystemMessageException {
if (s == null || s.length() == 0)
return s;
String encoding = _controlEncoding!=null ? _controlEncoding : getFTPClient().getControlEncoding(); String encoding = _controlEncoding!=null ? _controlEncoding : getFTPClient().getControlEncoding();
try { try {
byte[] bytes = s.getBytes(encoding); byte[] bytes = s.getBytes(encoding);
@ -574,6 +577,12 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
*/ */
protected FTPHostFile getFileInternal(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException protected FTPHostFile getFileInternal(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException
{ {
boolean isRoot = (remoteParent == null || remoteParent.length() == 0);
if (isRoot) {
// FTP doesn't really support getting properties of Roots yet. For
// now, return the root and claim it's existing.
return new FTPHostFile(remoteParent, fileName, true, true, 0, 0, true);
}
remoteParent = checkEncoding(remoteParent); remoteParent = checkEncoding(remoteParent);
fileName = checkEncoding(fileName); fileName = checkEncoding(fileName);
if (monitor!=null){ if (monitor!=null){
@ -999,7 +1008,7 @@ public class FTPService extends AbstractFileService implements IFTPService, IFil
//Returning null in this case is safest, see also SftpFileService. //Returning null in this case is safest, see also SftpFileService.
return null; return null;
} }
return new FTPHostFile("",_userHome,true,true,0,0,true); //$NON-NLS-1$ return new FTPHostFile(null, _userHome, true, true, 0, 0, true);
} }
/* /*

View file

@ -39,6 +39,7 @@
* David McKnight (IBM) - [231211] Local xml file not opened when workspace encoding is different from local system encoding * David McKnight (IBM) - [231211] Local xml file not opened when workspace encoding is different from local system encoding
* Radoslav Gerganov (ProSyst) - [230919] IFileService.delete() should not return a boolean * Radoslav Gerganov (ProSyst) - [230919] IFileService.delete() should not return a boolean
* Martin Oberhuber (Wind River) - [233993] Improve EFS error reporting * Martin Oberhuber (Wind River) - [233993] Improve EFS error reporting
* Martin Oberhuber (Wind River) - [235360][ftp][ssh][local] Return proper "Root" IHostFile
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.internal.services.local.files; package org.eclipse.rse.internal.services.local.files;
@ -782,7 +783,7 @@ public class LocalFileService extends AbstractFileService implements ILocalServi
{ {
String userHome =System.getProperty("user.home"); //$NON-NLS-1$ String userHome =System.getProperty("user.home"); //$NON-NLS-1$
File userHomeFile = new File(userHome); File userHomeFile = new File(userHome);
return new LocalHostFile(userHomeFile); return new LocalHostFile(userHomeFile, (userHomeFile.getParent() == null));
} }
@ -831,7 +832,8 @@ public class LocalFileService extends AbstractFileService implements ILocalServi
boolean isVirtualParent = false; boolean isVirtualParent = false;
boolean isArchiveParent = false; boolean isArchiveParent = false;
if (remoteParent != null) { boolean isRoot = (remoteParent == null || remoteParent.length() == 0);
if (!isRoot) {
File remoteParentFile = new File(remoteParent); File remoteParentFile = new File(remoteParent);
if (!remoteParentFile.exists()) { if (!remoteParentFile.exists()) {
isVirtualParent = ArchiveHandlerManager.isVirtual(remoteParent); isVirtualParent = ArchiveHandlerManager.isVirtual(remoteParent);
@ -841,8 +843,8 @@ public class LocalFileService extends AbstractFileService implements ILocalServi
} }
if (!isVirtualParent && !isArchiveParent) if (!isVirtualParent && !isArchiveParent)
{ {
File file = remoteParent==null ? new File(name) : new File(remoteParent, name); File file = isRoot ? new File(name) : new File(remoteParent, name);
return new LocalHostFile(file); return new LocalHostFile(file, isRoot);
} }
else else
{ {

View file

@ -31,6 +31,7 @@
* Martin Oberhuber (Wind River) - [218042] Support UNIX permission modification on ssh * Martin Oberhuber (Wind River) - [218042] Support UNIX permission modification on ssh
* Martin Oberhuber (Wind River) - [233651] Make ssh delete throw proper exceptions * 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) - [235477][ssh] SftpFileService.createFolder() fails for file named "a?*"
* Martin Oberhuber (Wind River) - [235360][ftp][ssh][local] Return proper "Root" IHostFile
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.internal.services.ssh.files; package org.eclipse.rse.internal.services.ssh.files;
@ -446,6 +447,10 @@ public class SftpFileService extends AbstractFileService implements ISshService,
*/ */
protected String concat(String parentDir, String fileName) { protected String concat(String parentDir, String fileName) {
// See also {@link SftpHostFile#getAbsolutePath()} // See also {@link SftpHostFile#getAbsolutePath()}
if (parentDir == null || parentDir.length() == 0) {
// Looking at a Root
return fileName;
}
StringBuffer path = new StringBuffer(parentDir); StringBuffer path = new StringBuffer(parentDir);
if (!parentDir.endsWith("/")) //$NON-NLS-1$ if (!parentDir.endsWith("/")) //$NON-NLS-1$
{ {
@ -483,7 +488,8 @@ public class SftpFileService extends AbstractFileService implements ISshService,
throw new SystemLockTimeoutException(Activator.PLUGIN_ID); throw new SystemLockTimeoutException(Activator.PLUGIN_ID);
} }
if (node==null) { if (node==null) {
node = new SftpHostFile(remoteParent, fileName, false, false, false, 0, 0); boolean isRoot = (remoteParent == null || remoteParent.length() == 0);
node = new SftpHostFile(remoteParent, fileName, false, isRoot, false, 0, 0);
node.setExists(false); node.setExists(false);
} }
return node; return node;
@ -566,8 +572,9 @@ public class SftpFileService extends AbstractFileService implements ISshService,
SftpATTRS attrsTarget = attrs; SftpATTRS attrsTarget = attrs;
String linkTarget=null; String linkTarget=null;
String canonicalPath = null; String canonicalPath = null;
if (attrs.isLink()) { boolean isRoot = (parentPath == null || parentPath.length() == 0);
//check if the link points to a directory if (attrs.isLink() && !isRoot) {
//check if the link points to a directory. Roots cannot be Links.
try { try {
String fullPath = concat(parentPath, fileName); String fullPath = concat(parentPath, fileName);
boolean readlinkDone = false; boolean readlinkDone = false;
@ -615,8 +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(parentPath, fileName, attrsTarget.isDir(), false, attrs.isLink(), 1000L * attrs.getMTime(), attrs.getSize());
if (linkTarget!=null) { if (linkTarget!=null) {
node.setLinkTarget(linkTarget); node.setLinkTarget(linkTarget);
} }
@ -848,7 +854,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
//Returning the home path as a Root is the safest we can do, since it will //Returning the home path as a Root is the safest we can do, since it will
//let users know what the home path is, and the "My Home" filter will be //let users know what the home path is, and the "My Home" filter will be
//set to correct target. See also bug 204710. //set to correct target. See also bug 204710.
return new SftpHostFile("", fUserHome, true, true, false, 0, 0); //$NON-NLS-1$ return new SftpHostFile(null, fUserHome, true, true, false, 0, 0);
} }
} }
//Bug 203490, bug 204710: Could not determine user home //Bug 203490, bug 204710: Could not determine user home
@ -856,7 +862,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
} }
public IHostFile[] getRoots(IProgressMonitor monitor) { public IHostFile[] getRoots(IProgressMonitor monitor) {
IHostFile root = new SftpHostFile("/", "/", true, true, false, 0, 0); //$NON-NLS-1$ //$NON-NLS-2$ IHostFile root = new SftpHostFile(null, "/", true, true, false, 0, 0); //$NON-NLS-1$
return new IHostFile[] { root }; return new IHostFile[] { root };
} }

View file

@ -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:
* Martin Oberhuber (Wind River) - Adapted from FTPHostFile. * Martin Oberhuber (Wind River) - Adapted from FTPHostFile.
* David McKnight (IBM) - [209593] [api] add support for "file permissions" and "owner" properties for unix files * 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
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.internal.services.ssh.files; package org.eclipse.rse.internal.services.ssh.files;
@ -42,13 +43,16 @@ public class SftpHostFile implements IHostFile, IHostFilePermissionsContainer {
private String fLinkTarget; private String fLinkTarget;
private String fCanonicalPath; private String fCanonicalPath;
private String[] fExtended = null; private String[] fExtended = null;
private IHostFilePermissions _permissions = null; private IHostFilePermissions _permissions = null;
//TODO just re-use or extend FTPHostFile instead of copying here? //TODO just re-use or extend FTPHostFile instead of copying here?
public SftpHostFile(String parentPath, String name, boolean isDirectory, boolean isRoot, boolean isLink, long lastModified, long size) { public SftpHostFile(String parentPath, String name, boolean isDirectory, boolean isRoot, boolean isLink, long lastModified, long size) {
fParentPath = parentPath; fParentPath = parentPath;
fName = name; fName = name;
if (name == null || name.length() == 0) {
throw new IllegalArgumentException();
}
fIsDirectory = isDirectory; fIsDirectory = isDirectory;
fIsRoot = isRoot; fIsRoot = isRoot;
fLastModified = lastModified; fLastModified = lastModified;
@ -58,34 +62,34 @@ public class SftpHostFile implements IHostFile, IHostFilePermissionsContainer {
} }
public String getName() { public String getName() {
return fName; return fName;
} }
public boolean isHidden() { public boolean isHidden() {
String name = getName(); String name = getName();
return name.charAt(0) == '.'; return name.charAt(0) == '.';
} }
public String getParentPath() { public String getParentPath() {
return fParentPath; return fParentPath;
} }
public boolean isDirectory() { public boolean isDirectory() {
return fIsDirectory; return fIsDirectory;
} }
public boolean isFile() { public boolean isFile() {
return !(fIsDirectory || fIsRoot); return !(fIsDirectory || fIsRoot);
} }
public boolean isRoot() { public boolean isRoot() {
return fIsRoot; return fIsRoot;
} }
public void setExists(boolean b) { public void setExists(boolean b) {
fExists = b; fExists = b;
} }
public boolean exists() { public boolean exists() {
return fExists; return fExists;
} }
@ -115,9 +119,25 @@ public class SftpHostFile implements IHostFile, IHostFilePermissionsContainer {
public void renameTo(String newAbsolutePath) { public void renameTo(String newAbsolutePath) {
int i = newAbsolutePath.lastIndexOf("/"); //$NON-NLS-1$ int i = newAbsolutePath.lastIndexOf("/"); //$NON-NLS-1$
if (i == -1) { if (i == -1) {
//Rename inside the same parent folder.
//FIXME is this really what was desired here? Or would we rename Roots?
//Renaming Roots isn't possible, I'd think.
fName = newAbsolutePath; fName = newAbsolutePath;
} }
else { else if (i == 0) {
// Renaming a root folder
if (newAbsolutePath.length()==1) {
//rename to root "/" -- should this work?
fParentPath = null;
fIsRoot = true;
fName = newAbsolutePath;
} else {
fParentPath = "/"; //$NON-NLS-1$
fName = newAbsolutePath.substring(i + 1);
}
fParentPath = "/"; //$NON-NLS-1$
fName = newAbsolutePath.substring(i + 1);
} else {
fParentPath = newAbsolutePath.substring(0, i); fParentPath = newAbsolutePath.substring(0, i);
fName = newAbsolutePath.substring(i+1); fName = newAbsolutePath.substring(i+1);
} }
@ -125,30 +145,30 @@ public class SftpHostFile implements IHostFile, IHostFilePermissionsContainer {
} }
protected boolean internalIsArchive() { protected boolean internalIsArchive() {
return ArchiveHandlerManager.getInstance().isArchive(new File(getAbsolutePath())) return ArchiveHandlerManager.getInstance().isArchive(new File(getAbsolutePath()))
&& !ArchiveHandlerManager.isVirtual(getAbsolutePath()); && !ArchiveHandlerManager.isVirtual(getAbsolutePath());
} }
public boolean isArchive() { public boolean isArchive() {
return fIsArchive; return fIsArchive;
} }
public boolean isLink() { public boolean isLink() {
return fIsLink; return fIsLink;
} }
public void setLinkTarget(String linkTarget) { public void setLinkTarget(String linkTarget) {
fLinkTarget = linkTarget; fLinkTarget = linkTarget;
} }
public String getLinkTarget() { public String getLinkTarget() {
return fLinkTarget; return fLinkTarget;
} }
public void setCanonicalPath(String canonicalPath) { public void setCanonicalPath(String canonicalPath) {
fCanonicalPath = canonicalPath; fCanonicalPath = canonicalPath;
} }
public String getCanonicalPath() { public String getCanonicalPath() {
if (fCanonicalPath==null) { if (fCanonicalPath==null) {
return getAbsolutePath(); return getAbsolutePath();
@ -156,10 +176,10 @@ public class SftpHostFile implements IHostFile, IHostFilePermissionsContainer {
return fCanonicalPath; return fCanonicalPath;
} }
} }
/** /**
* Set Extended data as key,value pairs. * Set Extended data as key,value pairs.
* *
* The data is maintained as a String array, where every element * The data is maintained as a String array, where every element
* with an even index refers to a key, and the next element * with an even index refers to a key, and the next element
* refers to its value. Example * refers to its value. Example
@ -167,17 +187,17 @@ public class SftpHostFile implements IHostFile, IHostFilePermissionsContainer {
* extended[1] = "joe,tim" * extended[1] = "joe,tim"
* extended[2] = "version" * extended[2] = "version"
* extended[3] = "/main/3" * extended[3] = "/main/3"
* *
* @param extended String[] array of key,value pairs * @param extended String[] array of key,value pairs
*/ */
public void setExtendedData(String[] extended) { public void setExtendedData(String[] extended) {
fExtended = extended; fExtended = extended;
} }
/** /**
* Return extended data as name,value pairs. * Return extended data as name,value pairs.
* @see #setExtendedData(String[]) * @see #setExtendedData(String[])
* *
* @return String[] array of key,value pairs * @return String[] array of key,value pairs
*/ */
public String[] getExtendedData() { public String[] getExtendedData() {
@ -234,12 +254,12 @@ public class SftpHostFile implements IHostFile, IHostFilePermissionsContainer {
public boolean canExecute() { public boolean canExecute() {
return fIsExecutable; return fIsExecutable;
} }
public IHostFilePermissions getPermissions() { public IHostFilePermissions getPermissions() {
return _permissions; return _permissions;
} }
public void setPermissions(IHostFilePermissions permissions) { public void setPermissions(IHostFilePermissions permissions) {
_permissions = permissions; _permissions = permissions;
} }
} }

View file

@ -39,6 +39,7 @@
* Martin Oberhuber (Wind River) - [221211] Fix markStale() for delete() operation with exceptions * Martin Oberhuber (Wind River) - [221211] Fix markStale() for delete() operation with exceptions
* David Dykstal (IBM) - [230821] fix IRemoteFileSubSystem API to be consistent with IFileService * David Dykstal (IBM) - [230821] fix IRemoteFileSubSystem API to be consistent with IFileService
* Martin Oberhuber (Wind River) - [234038] Mark IRemoteFile stale when changing permissions * Martin Oberhuber (Wind River) - [234038] Mark IRemoteFile stale when changing permissions
* Martin Oberhuber (Wind River) - [235360][ftp][ssh][local] Return proper "Root" IHostFile
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.subsystems.files.core.servicesubsystem; package org.eclipse.rse.subsystems.files.core.servicesubsystem;
@ -326,8 +327,9 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe
} }
IRemoteFile parent = null; IRemoteFile parent = null;
if (!userHome.getParentPath().equals(".")) //$NON-NLS-1$ if (!".".equals(userHome.getParentPath())) //$NON-NLS-1$
{ {
//note: parent path can be "null" if userHome is a Root
try try
{ {
//parent = getRemoteFileObject(userHome.getParentPath()); //parent = getRemoteFileObject(userHome.getParentPath());