Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 240704
Collapse All | Expand All

(-)src/org/eclipse/rse/tests/subsystems/files/FileSubsystemConsistencyTestCase.java (+27 lines)
Lines 11-16 Link Here
11
 * David McKnight   (IBM)        - [210109] store constants in IFileService rather than IFileServiceConstants
11
 * David McKnight   (IBM)        - [210109] store constants in IFileService rather than IFileServiceConstants
12
 * Martin Oberhuber (Wind River) - organize, enable and tag test cases
12
 * Martin Oberhuber (Wind River) - organize, enable and tag test cases
13
 * Martin Oberhuber (Wind River) - [240729] More flexible disabling of testcases
13
 * Martin Oberhuber (Wind River) - [240729] More flexible disabling of testcases
14
 * Martin Oberhuber (Wind River) - [240704] Protect against illegal API use of getRemoteFileObject() with relative path as name
14
 *******************************************************************************/
15
 *******************************************************************************/
15
package org.eclipse.rse.tests.subsystems.files;
16
package org.eclipse.rse.tests.subsystems.files;
16
17
Lines 471-474 Link Here
471
		}
472
		}
472
	}
473
	}
473
474
475
	public void testGetRemoteFileRelativePath() throws Exception {
476
		// for bug 240704
477
		// -test-author-:MartinOberhuber
478
		if (isTestDisabled())
479
			return;
480
		setupConnections();
481
		for (int i = 0; i < _subSystems.size(); i++) {
482
			IRemoteFileSubSystem ss = (IRemoteFileSubSystem) _subSystems.get(i);
483
			ss.checkIsConnected(getDefaultProgressMonitor());
484
			IRemoteFile homeDir = ss.getRemoteFileObject(".", getDefaultProgressMonitor());
485
			assertTrue(homeDir.exists());
486
			assertTrue(homeDir.isDirectory());
487
			String sep = homeDir.getSeparator();
488
			String relativePath = "rsetest" + System.currentTimeMillis() + sep + "foo" + sep + "bar";
489
			try {
490
				IRemoteFile subDir = ss.getRemoteFileObject(homeDir, relativePath, getDefaultProgressMonitor());
491
				assertTrue(subDir.isDescendantOf(homeDir));
492
				assertEquals("bar", subDir.getName());
493
				assertFalse(subDir.exists());
494
				assertFalse(subDir.isDirectory());
495
			} catch (IllegalArgumentException e) {
496
				// Expected here: IllegalArgumentException is OK
497
			}
498
		}
499
	}
500
474
}
501
}
(-)build.properties (+4 lines)
Lines 7-12 Link Here
7
#
7
#
8
# Contributors:
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
# Martin Oberhuber (Wind River) - [240704] Protect against illegal API use of getRemoteFileObject() with relative path as name
10
###############################################################################
11
###############################################################################
11
bin.includes = META-INF/,\
12
bin.includes = META-INF/,\
12
               about.html,\
13
               about.html,\
Lines 15-19 Link Here
15
               .
16
               .
16
source.. = src/
17
source.. = src/
17
output.. = bin/
18
output.. = bin/
19
20
javacSource=1.4
21
javacTarget=1.4
18
src.includes = about.html,\
22
src.includes = about.html,\
19
               schema/
23
               schema/
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 2-8 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.rse.subsystems.files.core;singleton:=true
4
Bundle-SymbolicName: org.eclipse.rse.subsystems.files.core;singleton:=true
5
Bundle-Version: 3.0.0.qualifier
5
Bundle-Version: 3.0.1.qualifier
6
Bundle-Activator: org.eclipse.rse.internal.subsystems.files.core.Activator
6
Bundle-Activator: org.eclipse.rse.internal.subsystems.files.core.Activator
7
Bundle-Localization: plugin
7
Bundle-Localization: plugin
8
Require-Bundle: org.eclipse.ui,
8
Require-Bundle: org.eclipse.ui,
(-).settings/org.eclipse.jdt.core.prefs (-2 / +2 lines)
Lines 1-7 Link Here
1
#Fri Mar 28 14:14:24 CET 2008
1
#Fri Mar 28 14:14:24 CET 2008
2
eclipse.preferences.version=1
2
eclipse.preferences.version=1
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
5
org.eclipse.jdt.core.compiler.compliance=1.4
5
org.eclipse.jdt.core.compiler.compliance=1.4
6
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
6
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
7
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
7
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
Lines 68-71 Link Here
68
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
68
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
69
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
69
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
70
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
70
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
71
org.eclipse.jdt.core.compiler.source=1.3
71
org.eclipse.jdt.core.compiler.source=1.4
(-)src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java (-24 / +41 lines)
Lines 41-46 Link Here
41
 * Martin Oberhuber (Wind River) - [234038] Mark IRemoteFile stale when changing permissions
41
 * Martin Oberhuber (Wind River) - [234038] Mark IRemoteFile stale when changing permissions
42
 * Martin Oberhuber (Wind River) - [235360][ftp][ssh][local] Return proper "Root" IHostFile
42
 * Martin Oberhuber (Wind River) - [235360][ftp][ssh][local] Return proper "Root" IHostFile
43
 * David McKnight   (IBM)        - [223461] [Refresh][api] Refresh expanded folder under filter refreshes Filter
43
 * David McKnight   (IBM)        - [223461] [Refresh][api] Refresh expanded folder under filter refreshes Filter
44
 * Martin Oberhuber (Wind River) - [240704] Protect against illegal API use of getRemoteFileObject() with relative path as name
44
 *******************************************************************************/
45
 *******************************************************************************/
45
46
46
package org.eclipse.rse.subsystems.files.core.servicesubsystem;
47
package org.eclipse.rse.subsystems.files.core.servicesubsystem;
Lines 54-59 Link Here
54
import org.eclipse.core.runtime.IProgressMonitor;
55
import org.eclipse.core.runtime.IProgressMonitor;
55
import org.eclipse.core.runtime.IStatus;
56
import org.eclipse.core.runtime.IStatus;
56
import org.eclipse.core.runtime.NullProgressMonitor;
57
import org.eclipse.core.runtime.NullProgressMonitor;
58
import org.eclipse.core.runtime.Status;
57
import org.eclipse.osgi.util.NLS;
59
import org.eclipse.osgi.util.NLS;
58
import org.eclipse.rse.core.RSECorePlugin;
60
import org.eclipse.rse.core.RSECorePlugin;
59
import org.eclipse.rse.core.events.ISystemRemoteChangeEvents;
61
import org.eclipse.rse.core.events.ISystemRemoteChangeEvents;
Lines 73-78 Link Here
73
import org.eclipse.rse.services.clientserver.messages.CommonMessages;
75
import org.eclipse.rse.services.clientserver.messages.CommonMessages;
74
import org.eclipse.rse.services.clientserver.messages.ICommonMessageIds;
76
import org.eclipse.rse.services.clientserver.messages.ICommonMessageIds;
75
import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage;
77
import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage;
78
import org.eclipse.rse.services.clientserver.messages.SystemElementNotFoundException;
76
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
79
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
77
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
80
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
78
import org.eclipse.rse.services.files.IFileService;
81
import org.eclipse.rse.services.files.IFileService;
Lines 174-179 Link Here
174
	 */
177
	 */
175
	public IRemoteFile getRemoteFileObject(IRemoteFile parent, String folderOrFileName, IProgressMonitor monitor) throws SystemMessageException
178
	public IRemoteFile getRemoteFileObject(IRemoteFile parent, String folderOrFileName, IProgressMonitor monitor) throws SystemMessageException
176
	{
179
	{
180
		// Consistency would be totally messed up if folderOrFileName were a relative path
181
		// Because IHostFiles would be incorrectly generated, getParent() would return wrong results etc
182
		assert folderOrFileName.indexOf(getSeparator())<0;
177
		// for bug 207095, implicit connect if the connection is not connected
183
		// for bug 207095, implicit connect if the connection is not connected
178
		checkIsConnected(monitor);
184
		checkIsConnected(monitor);
179
185
Lines 183-188 Link Here
183
		{
189
		{
184
			return file;
190
			return file;
185
		}
191
		}
192
		// Fallback in case of incorrect API usage
193
		// TODO remove this in next release for Performance,
194
		// since it is just for bad clients using the API incorrectly
195
		if (folderOrFileName.indexOf(getSeparator()) >= 0) {
196
			try {
197
				throw new IllegalArgumentException("getRemoteFileObject: folderOrFileName must not be a relative path"); //$NON-NLS-1$
198
			} catch (IllegalArgumentException e) {
199
				Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Illegal API use: " + e.getLocalizedMessage(), e)); //$NON-NLS-1$
200
			}
201
			return getRemoteFileObject(fullPath, monitor);
202
		}
186
203
187
		IHostFile node = getFile(parent.getAbsolutePath(), folderOrFileName, monitor);
204
		IHostFile node = getFile(parent.getAbsolutePath(), folderOrFileName, monitor);
188
		return getHostFileToRemoteFileAdapter().convertToRemoteFile(this, getDefaultContext(), parent, node);
205
		return getHostFileToRemoteFileAdapter().convertToRemoteFile(this, getDefaultContext(), parent, node);
Lines 420-435 Link Here
420
		}
437
		}
421
438
422
		List hostFiles = new ArrayList(10);
439
		List hostFiles = new ArrayList(10);
423
		
440
424
		// query children via the service
441
		// query children via the service
425
		getFileService().listMultiple(parentPaths, fileNameFilters, fileTypes, hostFiles, monitor);
442
		getFileService().listMultiple(parentPaths, fileNameFilters, fileTypes, hostFiles, monitor);
426
		RemoteFileContext context = getDefaultContext();
443
		RemoteFileContext context = getDefaultContext();
427
444
428
		IHostFile[] results = (IHostFile[])hostFiles.toArray(new IHostFile[hostFiles.size()]);	
445
		IHostFile[] results = (IHostFile[])hostFiles.toArray(new IHostFile[hostFiles.size()]);
429
446
430
		// convert the IHostFiles into AbstractRemoteFiles
447
		// convert the IHostFiles into AbstractRemoteFiles
431
		AbstractRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, null, results);
448
		AbstractRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, null, results);
432
		
449
433
		// cache the results corresponding to each parent under each parent
450
		// cache the results corresponding to each parent under each parent
434
		for (int i = 0; i < parents.length; i++)
451
		for (int i = 0; i < parents.length; i++)
435
		{
452
		{
Lines 449-462 Link Here
449
					underParent.add(child);
466
					underParent.add(child);
450
				}
467
				}
451
			}
468
			}
452
			
469
453
			// update the parent with it's latest properties
470
			// update the parent with it's latest properties
454
			// null is passed for the second argument because we currently don't get the parent in our results query
471
			// null is passed for the second argument because we currently don't get the parent in our results query
455
			updateRemoteFile(parent, null, monitor);	
472
			updateRemoteFile(parent, null, monitor);
456
			
473
457
			if (underParent.size() > 0)
474
			if (underParent.size() > 0)
458
			{
475
			{
459
				Object[] qresults = underParent.toArray();				
476
				Object[] qresults = underParent.toArray();
460
				parent.setContents(RemoteChildrenContentsType.getInstance(), filter, qresults);
477
				parent.setContents(RemoteChildrenContentsType.getInstance(), filter, qresults);
461
			}
478
			}
462
		}
479
		}
Lines 483-493 Link Here
483
		getFileService().listMultiple(parentPaths, fileNameFilters, fileType, hostFiles, monitor);
500
		getFileService().listMultiple(parentPaths, fileNameFilters, fileType, hostFiles, monitor);
484
		RemoteFileContext context = getDefaultContext();
501
		RemoteFileContext context = getDefaultContext();
485
502
486
		IHostFile[] results = (IHostFile[])hostFiles.toArray(new IHostFile[hostFiles.size()]);			
503
		IHostFile[] results = (IHostFile[])hostFiles.toArray(new IHostFile[hostFiles.size()]);
487
		
504
488
		// convert the IHostFiles into AbstractRemoteFiles
505
		// convert the IHostFiles into AbstractRemoteFiles
489
		AbstractRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, null, results);
506
		AbstractRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, null, results);
490
		
507
491
		// cache the results corresponding to each parent under each parent
508
		// cache the results corresponding to each parent under each parent
492
		for (int i = 0; i < parents.length; i++)
509
		for (int i = 0; i < parents.length; i++)
493
		{
510
		{
Lines 510-520 Link Here
510
527
511
			// update the parent with it's latest properties
528
			// update the parent with it's latest properties
512
			// null is passed for the second argument because we currently don't get the parent in our results query
529
			// null is passed for the second argument because we currently don't get the parent in our results query
513
			updateRemoteFile(parent, null, monitor);	
530
			updateRemoteFile(parent, null, monitor);
514
			
531
515
			if (underParent.size() > 0)
532
			if (underParent.size() > 0)
516
			{
533
			{
517
				Object[] qresults = underParent.toArray();			
534
				Object[] qresults = underParent.toArray();
518
				parent.setContents(RemoteChildrenContentsType.getInstance(), filter, qresults);
535
				parent.setContents(RemoteChildrenContentsType.getInstance(), filter, qresults);
519
			}
536
			}
520
		}
537
		}
Lines 544-557 Link Here
544
					IStatus.INFO, msgTxt);
561
					IStatus.INFO, msgTxt);
545
			throw new SystemMessageException(msg);
562
			throw new SystemMessageException(msg);
546
		}
563
		}
547
				
564
548
		// query children of the parent
565
		// query children of the parent
549
		IHostFile[] results = internalList(parentPath, fileNameFilter, fileType, monitor);		
566
		IHostFile[] results = internalList(parentPath, fileNameFilter, fileType, monitor);
550
		
567
551
		// update the parent with it's latest properties
568
		// update the parent with it's latest properties
552
		// null is passed for the second argument because we currently don't get the parent in our results query
569
		// null is passed for the second argument because we currently don't get the parent in our results query
553
		updateRemoteFile(parent, null, monitor);
570
		updateRemoteFile(parent, null, monitor);
554
				
571
555
		// convert the IHostFiles to AbstractRemoteFile[]
572
		// convert the IHostFiles to AbstractRemoteFile[]
556
		AbstractRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, parent, results);
573
		AbstractRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, parent, results);
557
		if (parent != null)
574
		if (parent != null)
Lines 559-577 Link Here
559
		return farr;
576
		return farr;
560
	}
577
	}
561
578
562
	
579
563
	
580
564
	private void updateRemoteFile(IRemoteFile parent, IHostFile newHostParent, IProgressMonitor monitor) throws SystemMessageException
581
	private void updateRemoteFile(IRemoteFile parent, IHostFile newHostParent, IProgressMonitor monitor) throws SystemMessageException
565
	{		
582
	{
566
		// now newHostParent file passed in so we'll assume it wasn't returned and explicitly get it
583
		// now newHostParent file passed in so we'll assume it wasn't returned and explicitly get it
567
		if (newHostParent == null){			
584
		if (newHostParent == null){
568
			String parentParentPath = parent.getParentPath();
585
			String parentParentPath = parent.getParentPath();
569
			if (parentParentPath == null){
586
			if (parentParentPath == null){
570
				parentParentPath = ""; //$NON-NLS-1$
587
				parentParentPath = ""; //$NON-NLS-1$
571
			}
588
			}
572
			newHostParent = getFileService().getFile(parentParentPath, parent.getName(), monitor);
589
			newHostParent = getFileService().getFile(parentParentPath, parent.getName(), monitor);
573
		}
590
		}
574
		
591
575
		if (newHostParent != null){
592
		if (newHostParent != null){
576
			IHostFile oldHostParent = parent.getHostFile();
593
			IHostFile oldHostParent = parent.getHostFile();
577
			if (!newHostParent.equals(oldHostParent)){
594
			if (!newHostParent.equals(oldHostParent)){
Lines 581-587 Link Here
581
		}
598
		}
582
	}
599
	}
583
600
584
	
601
585
	public IRemoteFile[] listRoots(IRemoteFileContext context, IProgressMonitor monitor) throws InterruptedException
602
	public IRemoteFile[] listRoots(IRemoteFileContext context, IProgressMonitor monitor) throws InterruptedException
586
	{
603
	{
587
		IHostFile[] roots = null;
604
		IHostFile[] roots = null;
Lines 907-913 Link Here
907
924
908
	public IRemoteFile createFolders(IRemoteFile folderToCreate, IProgressMonitor monitor) throws SystemMessageException
925
	public IRemoteFile createFolders(IRemoteFile folderToCreate, IProgressMonitor monitor) throws SystemMessageException
909
	{
926
	{
910
		return createFolder(folderToCreate, monitor);
927
			return createFolder(folderToCreate, monitor);
911
	}
928
	}
912
929
913
	/**
930
	/**

Return to bug 240704