This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 271244 - [sftp files] "My Home" filter not working
Summary: [sftp files] "My Home" filter not working
Status: RESOLVED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.1 M7   Edit
Assignee: David McKnight CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 272882
  Show dependency tree
 
Reported: 2009-04-05 05:14 EDT by Uwe Stieber CLA
Modified: 2009-04-20 08:49 EDT (History)
2 users (show)

See Also:


Attachments
patch to connect() if there is no user home variable set (3.00 KB, patch)
2009-04-06 12:59 EDT, David McKnight CLA
no flags Details | Diff
patch to call connect() on initService() (1.64 KB, patch)
2009-04-07 12:45 EDT, David McKnight CLA
no flags Details | Diff
patch to call connect() on initService() and to detect root parent in getUserHome() (2.06 KB, patch)
2009-04-08 03:54 EDT, Uwe Stieber CLA
no flags Details | Diff
patch with updated javadoc for IService (1.61 KB, patch)
2009-04-16 12:43 EDT, David McKnight CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Uwe Stieber CLA 2009-04-05 05:14:59 EDT
Expanding the "My Home" filter node is leading to an error. Expanding the "Root" filter works fine.

org.eclipse.rse.services.clientserver.messages.SystemMessageException: An unexpected error occurred.
	at org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem.getRemoteFileObject(FileServiceSubSystem.java:264)
	at org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystem.internalResolveFilterString(RemoteFileSubSystem.java:645)
	at org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystem.internalResolveFilterStrings(RemoteFileSubSystem.java:468)
	at org.eclipse.rse.core.subsystems.SubSystem.resolveFilterStrings(SubSystem.java:2281)
	at org.eclipse.rse.internal.ui.view.SystemViewFilterReferenceAdapter.internalGetChildren(SystemViewFilterReferenceAdapter.java:464)
	at org.eclipse.rse.internal.ui.view.SystemViewFilterReferenceAdapter.getChildren(SystemViewFilterReferenceAdapter.java:283)
	at org.eclipse.rse.internal.ui.view.SystemViewFilterReferenceAdapter.getChildren(SystemViewFilterReferenceAdapter.java:291)
	at org.eclipse.rse.ui.operations.SystemFetchOperation.execute(SystemFetchOperation.java:431)
	at org.eclipse.rse.ui.operations.SystemFetchOperation.run(SystemFetchOperation.java:179)
	at org.eclipse.rse.ui.view.AbstractSystemViewAdapter.fetchDeferredChildren(AbstractSystemViewAdapter.java:2290)
	at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:234)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Comment 1 Uwe Stieber CLA 2009-04-05 05:18:20 EDT
Pressing "F5" after the expand failed now leads to the error node "File 'root' not found" below the "My Home" filter.
Comment 2 David McKnight CLA 2009-04-06 12:59:44 EDT
Created attachment 131017 [details]
patch to connect() if there is no user home variable set

I'm not all that familiar with the SftpFileService code so I don't know whether this is the best way to go about fixing this but, from what I can see, fUserHome isn't set because connect() has never been called.  So one way to deal with this problem is to call connect().  Martin, is there a better way to fix this?
Comment 3 Uwe Stieber CLA 2009-04-07 04:35:01 EDT
Hi David,
I've applied the patch and now it prints "File 'root' not found" directly.

The output to the console is:

getUserHome
user home=/root
get file
getting channel

So it should have the correct home "/root"?

Cheers, Uwe :)
Comment 4 David McKnight CLA 2009-04-07 10:56:49 EDT
(In reply to comment #3)
> Hi David,
> I've applied the patch and now it prints "File 'root' not found" directly.
> 
> The output to the console is:
> 
> getUserHome
> user home=/root
> get file
> getting channel
> 
> So it should have the correct home "/root"?
> 
> Cheers, Uwe :)
> 


In your case, the user home is supposed to be "/root"?  Are you able to expand /root via the "Root" filter?
Comment 5 Uwe Stieber CLA 2009-04-07 11:54:43 EDT
>In your case, the user home is supposed to be "/root"?

Yes.

>Are you able to expand /root via the "Root" filter?

Yes. It works via the "Root" filter even if the subsystem haven't been connected already.
Comment 6 David McKnight CLA 2009-04-07 12:45:36 EDT
Created attachment 131147 [details]
patch to call connect() on initService()

Here's a different patch that calls SftpFileService.connect() from initService(), which was the original behaviour.  The connect() code had previously been commented out due to bug 227135.  

Martin, could you explain why connect() needed to be taken out?
Comment 7 Uwe Stieber CLA 2009-04-08 03:54:45 EDT
Created attachment 131228 [details]
patch to call connect() on initService() and to detect root parent in getUserHome()

Combinded patch for missing connect() in initService() and wrong parent detection in getUserHome()
Comment 8 Uwe Stieber CLA 2009-04-08 03:55:05 EDT
Hi David,
it still shows "File 'root' not found" if expanding the "My Home" filter. The connect() in initService() is called.

In SftpFileService#getUserHome(), fUserHome is correctly "/root", but in lines 862/863, the leading / is removed. This leads to name="root" and parent="". IMO, the parent is incorrect here too and is contributing to the problem. If changing to code to detect "/" as parent additionally to the initService() fix, it works fine.

I've attached a patch combinding both fixes for review.
Comment 9 Martin Oberhuber CLA 2009-04-08 06:16:26 EDT
(In reply to comment #6)
> Martin, could you explain why connect() needed to be taken out?  

Javadocs of initService() explicitly specify that initService() is *not* meant to connect. I'd appreciate finding a different solution for the problem.

I'll not be able to look at this before next week because I'm currently out of office.
Comment 10 David McKnight CLA 2009-04-08 08:20:52 EDT
(In reply to comment #9)
> (In reply to comment #6)
> > Martin, could you explain why connect() needed to be taken out?  
> 
> Javadocs of initService() explicitly specify that initService() is *not* meant
> to connect. I'd appreciate finding a different solution for the problem.
> 
This method gets called for each service after the connector service has connected.  At this point in time, I would expect the service to be connected and functional.  You wrote the javadoc for IService.initService() which states "not yet expected to open a connection to a particular remote system" but it's not clear whether you're referring to the connector service being connected or something else.  Perhaps the javadocs need to be revisited.

  
Comment 11 David McKnight CLA 2009-04-16 12:43:20 EDT
Created attachment 132103 [details]
patch with updated javadoc for IService

As per discussion in the committer meeting, I've committed the patch for SftpFileService.  Here I've attached updated javadoc for IService.  The description is pretty simple but I'm not sure anything more needs to be said.
Comment 12 David McKnight CLA 2009-04-16 12:45:53 EDT
Marking this as fixed.
Comment 13 Uwe Stieber CLA 2009-04-16 13:05:08 EDT
Dave, the commit is incomplete. It missing the change to SftpFileService, line 864.

From 
			String parent = fUserHome.substring(0, lastSlash);

To

			String parent = lastSlash > 0 ? fUserHome.substring(0, lastSlash) : lastSlash == 0 ? "/" : ""; //$NON-NLS-1$ //$NON-NLS-2$

The connect alone does not solve the issue. As said before, only both changes together are doing the trick. Do you want me to commit this change directly?
Comment 14 Martin Oberhuber CLA 2009-04-16 13:18:54 EDT
Hm... in the lastSlash < 0 case, we have e.g.
   file = "fooBar"
so what would we expect the parent of such a path to be? An empty parent ("") seems odd to me. Either "/" or "." would make more sense I'd guess. What is the semantics of such a relative path anyways?
Comment 15 David McKnight CLA 2009-04-16 15:00:29 EDT
(In reply to comment #13)
> Dave, the commit is incomplete. It missing the change to SftpFileService, line
> 864.
> 
> From 
>                         String parent = fUserHome.substring(0, lastSlash);
> 
> To
> 
>                         String parent = lastSlash > 0 ? fUserHome.substring(0,
> lastSlash) : lastSlash == 0 ? "/" : ""; //$NON-NLS-1$ //$NON-NLS-2$
> 
> The connect alone does not solve the issue. As said before, only both changes
> together are doing the trick. Do you want me to commit this change directly?
> 
Oh right! Thanks from reminding me. I've added this line and committed the change.
Comment 16 Uwe Stieber CLA 2009-04-18 03:15:18 EDT
Dave, thanks. I've just verified that it works now.

Martin, In reply to Comment #14:

>Hm... in the lastSlash < 0 case, we have e.g. file = "fooBar"
>so what would we expect the parent of such a path to be? An empty parent ("?) seems odd to me. Either ?/?or ?." would make more sense I?d guess. 

I don't know what a good default for lastSlash < 0 would be. Most logical seems ".". However, this case had not been handled before, substring would have been thrown an IndexOutOfBoundsException. As there are no bugzillas regarding such an exception, it might not run into this case at all.
Comment 17 Martin Oberhuber CLA 2009-04-20 05:50:03 EDT
(In reply to comment #16)
> ".". However, this case had not been handled before, substring would have been
> thrown an IndexOutOfBoundsException. As there are no bugzillas regarding such
> an exception, it might not run into this case at all.

I guess then I'd like to have an exception thrown (assertionFailed or IndexOutOfBounds) in order to make sure that invalid input (i.e. relative path) is cought as early as possible.