diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/.settings/org.eclipse.jdt.core.prefs b/rse/plugins/org.eclipse.rse.subsystems.files.core/.settings/org.eclipse.jdt.core.prefs index 381fc6eb064..138063a1c19 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.core/.settings/org.eclipse.jdt.core.prefs +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,7 @@ #Fri Mar 28 14:14:24 CET 2008 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4 org.eclipse.jdt.core.compiler.compliance=1.4 org.eclipse.jdt.core.compiler.doc.comment.support=enabled org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning @@ -68,4 +68,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 +org.eclipse.jdt.core.compiler.source=1.4 diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF index b7fbcced114..cd98929162d 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.rse.subsystems.files.core;singleton:=true -Bundle-Version: 3.0.0.qualifier +Bundle-Version: 3.0.1.qualifier Bundle-Activator: org.eclipse.rse.internal.subsystems.files.core.Activator Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/build.properties b/rse/plugins/org.eclipse.rse.subsystems.files.core/build.properties index 6d2c5357acd..6492a2ef7b9 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.core/build.properties +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/build.properties @@ -7,6 +7,7 @@ # # Contributors: # IBM Corporation - initial API and implementation +# Martin Oberhuber (Wind River) - [240704] Protect against illegal API use of getRemoteFileObject() with relative path as name ############################################################################### bin.includes = META-INF/,\ about.html,\ @@ -15,5 +16,8 @@ bin.includes = META-INF/,\ . source.. = src/ output.. = bin/ + +javacSource=1.4 +javacTarget=1.4 src.includes = about.html,\ schema/ diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java index 139d1b78270..6678de17240 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java @@ -41,6 +41,7 @@ * Martin Oberhuber (Wind River) - [234038] Mark IRemoteFile stale when changing permissions * Martin Oberhuber (Wind River) - [235360][ftp][ssh][local] Return proper "Root" IHostFile * David McKnight (IBM) - [223461] [Refresh][api] Refresh expanded folder under filter refreshes Filter + * Martin Oberhuber (Wind River) - [240704] Protect against illegal API use of getRemoteFileObject() with relative path as name *******************************************************************************/ package org.eclipse.rse.subsystems.files.core.servicesubsystem; @@ -54,6 +55,7 @@ import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; import org.eclipse.osgi.util.NLS; import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.events.ISystemRemoteChangeEvents; @@ -73,6 +75,7 @@ import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; import org.eclipse.rse.services.clientserver.messages.CommonMessages; import org.eclipse.rse.services.clientserver.messages.ICommonMessageIds; import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage; +import org.eclipse.rse.services.clientserver.messages.SystemElementNotFoundException; import org.eclipse.rse.services.clientserver.messages.SystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.services.files.IFileService; @@ -174,6 +177,9 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe */ public IRemoteFile getRemoteFileObject(IRemoteFile parent, String folderOrFileName, IProgressMonitor monitor) throws SystemMessageException { + // Consistency would be totally messed up if folderOrFileName were a relative path + // Because IHostFiles would be incorrectly generated, getParent() would return wrong results etc + assert folderOrFileName.indexOf(getSeparator())<0; // for bug 207095, implicit connect if the connection is not connected checkIsConnected(monitor); @@ -183,6 +189,17 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe { return file; } + // Fallback in case of incorrect API usage + // TODO remove this in next release for Performance, + // since it is just for bad clients using the API incorrectly + if (folderOrFileName.indexOf(getSeparator()) >= 0) { + try { + throw new IllegalArgumentException("getRemoteFileObject: folderOrFileName must not be a relative path"); //$NON-NLS-1$ + } catch (IllegalArgumentException e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Illegal API use: " + e.getLocalizedMessage(), e)); //$NON-NLS-1$ + } + return getRemoteFileObject(fullPath, monitor); + } IHostFile node = getFile(parent.getAbsolutePath(), folderOrFileName, monitor); return getHostFileToRemoteFileAdapter().convertToRemoteFile(this, getDefaultContext(), parent, node); @@ -420,16 +437,16 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe } List hostFiles = new ArrayList(10); - + // query children via the service getFileService().listMultiple(parentPaths, fileNameFilters, fileTypes, hostFiles, monitor); RemoteFileContext context = getDefaultContext(); - IHostFile[] results = (IHostFile[])hostFiles.toArray(new IHostFile[hostFiles.size()]); + IHostFile[] results = (IHostFile[])hostFiles.toArray(new IHostFile[hostFiles.size()]); // convert the IHostFiles into AbstractRemoteFiles AbstractRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, null, results); - + // cache the results corresponding to each parent under each parent for (int i = 0; i < parents.length; i++) { @@ -449,14 +466,14 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe underParent.add(child); } } - + // update the parent with it's latest properties // null is passed for the second argument because we currently don't get the parent in our results query - updateRemoteFile(parent, null, monitor); - + updateRemoteFile(parent, null, monitor); + if (underParent.size() > 0) { - Object[] qresults = underParent.toArray(); + Object[] qresults = underParent.toArray(); parent.setContents(RemoteChildrenContentsType.getInstance(), filter, qresults); } } @@ -483,11 +500,11 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe getFileService().listMultiple(parentPaths, fileNameFilters, fileType, hostFiles, monitor); RemoteFileContext context = getDefaultContext(); - IHostFile[] results = (IHostFile[])hostFiles.toArray(new IHostFile[hostFiles.size()]); - + IHostFile[] results = (IHostFile[])hostFiles.toArray(new IHostFile[hostFiles.size()]); + // convert the IHostFiles into AbstractRemoteFiles AbstractRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, null, results); - + // cache the results corresponding to each parent under each parent for (int i = 0; i < parents.length; i++) { @@ -510,11 +527,11 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe // update the parent with it's latest properties // null is passed for the second argument because we currently don't get the parent in our results query - updateRemoteFile(parent, null, monitor); - + updateRemoteFile(parent, null, monitor); + if (underParent.size() > 0) { - Object[] qresults = underParent.toArray(); + Object[] qresults = underParent.toArray(); parent.setContents(RemoteChildrenContentsType.getInstance(), filter, qresults); } } @@ -544,14 +561,14 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe IStatus.INFO, msgTxt); throw new SystemMessageException(msg); } - + // query children of the parent - IHostFile[] results = internalList(parentPath, fileNameFilter, fileType, monitor); - + IHostFile[] results = internalList(parentPath, fileNameFilter, fileType, monitor); + // update the parent with it's latest properties // null is passed for the second argument because we currently don't get the parent in our results query updateRemoteFile(parent, null, monitor); - + // convert the IHostFiles to AbstractRemoteFile[] AbstractRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, parent, results); if (parent != null) @@ -559,19 +576,19 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe return farr; } - - + + private void updateRemoteFile(IRemoteFile parent, IHostFile newHostParent, IProgressMonitor monitor) throws SystemMessageException - { + { // now newHostParent file passed in so we'll assume it wasn't returned and explicitly get it - if (newHostParent == null){ + if (newHostParent == null){ String parentParentPath = parent.getParentPath(); if (parentParentPath == null){ parentParentPath = ""; //$NON-NLS-1$ } newHostParent = getFileService().getFile(parentParentPath, parent.getName(), monitor); } - + if (newHostParent != null){ IHostFile oldHostParent = parent.getHostFile(); if (!newHostParent.equals(oldHostParent)){ @@ -581,7 +598,7 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe } } - + public IRemoteFile[] listRoots(IRemoteFileContext context, IProgressMonitor monitor) throws InterruptedException { IHostFile[] roots = null; @@ -907,7 +924,7 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe public IRemoteFile createFolders(IRemoteFile folderToCreate, IProgressMonitor monitor) throws SystemMessageException { - return createFolder(folderToCreate, monitor); + return createFolder(folderToCreate, monitor); } /** diff --git a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileSubsystemConsistencyTestCase.java b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileSubsystemConsistencyTestCase.java index ae902ac24ef..1592c43adae 100644 --- a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileSubsystemConsistencyTestCase.java +++ b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileSubsystemConsistencyTestCase.java @@ -11,6 +11,7 @@ * David McKnight (IBM) - [210109] store constants in IFileService rather than IFileServiceConstants * Martin Oberhuber (Wind River) - organize, enable and tag test cases * Martin Oberhuber (Wind River) - [240729] More flexible disabling of testcases + * Martin Oberhuber (Wind River) - [240704] Protect against illegal API use of getRemoteFileObject() with relative path as name *******************************************************************************/ package org.eclipse.rse.tests.subsystems.files; @@ -471,4 +472,30 @@ public class FileSubsystemConsistencyTestCase extends RSEBaseConnectionTestCase } } + public void testGetRemoteFileRelativePath() throws Exception { + // for bug 240704 + // -test-author-:MartinOberhuber + if (isTestDisabled()) + return; + setupConnections(); + for (int i = 0; i < _subSystems.size(); i++) { + IRemoteFileSubSystem ss = (IRemoteFileSubSystem) _subSystems.get(i); + ss.checkIsConnected(getDefaultProgressMonitor()); + IRemoteFile homeDir = ss.getRemoteFileObject(".", getDefaultProgressMonitor()); + assertTrue(homeDir.exists()); + assertTrue(homeDir.isDirectory()); + String sep = homeDir.getSeparator(); + String relativePath = "rsetest" + System.currentTimeMillis() + sep + "foo" + sep + "bar"; + try { + IRemoteFile subDir = ss.getRemoteFileObject(homeDir, relativePath, getDefaultProgressMonitor()); + assertTrue(subDir.isDescendantOf(homeDir)); + assertEquals("bar", subDir.getName()); + assertFalse(subDir.exists()); + assertFalse(subDir.isDirectory()); + } catch (IllegalArgumentException e) { + // Expected here: IllegalArgumentException is OK + } + } + } + }