Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 311147 - IRemoteFile.exists() method does not reflect exact state, once the existence of the remote file changed after the creation of the instance.
Summary: IRemoteFile.exists() method does not reflect exact state, once the existence ...
Status: NEW
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: dsdp.tm.rse-inbox CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-30 05:25 EDT by Loganathan CLA
Modified: 2010-04-30 10:46 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Loganathan CLA 2010-04-30 05:25:21 EDT
Build Identifier:  M20080911-1700

I made an instance of a remote file by using, IRemoteFileSubSystem.getRemoteFileObject(IRemoteFile parent, String folderName). Here parent actually exists, but the folder name not. My intention is to have the handle of the folder name to use it at future after creating it by running a script. So after creating the file by running my script, I called the IRemoteFile.exists() on that handle, but it returns false even if that file actually exists. This misses the basic functionality of the method.

Reproducible: Always

Steps to Reproduce:
1.Create a IRemoteFile handle to a non-existing folder/file
2.Create the remote folder/file manually.
3.Check the IRemoteFile.exists() on the handle.
Comment 1 David McKnight CLA 2010-04-30 08:30:20 EDT
To avoid performance problems due to redundant remote queries, the IRemoteFile instances are cached.  If you create an IRemoteFile handle, then manually create the file, you'll need to first do the following before you'll have an up-to-date version with an accurate IRemoteFile.exists():

  // make the cached file stale
  remoteFile.markStale(true); 

  // requery it to obtain a fresh version
  remoteFile =fs.getRemoteFileObject(remoteFile.getAbsolutePath(), monitor);
Comment 2 Loganathan CLA 2010-04-30 09:30:10 EDT
(In reply to comment #1)
> To avoid performance problems due to redundant remote queries, the IRemoteFile
> instances are cached.  If you create an IRemoteFile handle, then manually
> create the file, you'll need to first do the following before you'll have an
> up-to-date version with an accurate IRemoteFile.exists():
> 
>   // make the cached file stale
>   remoteFile.markStale(true); 
> 
>   // requery it to obtain a fresh version
>   remoteFile =fs.getRemoteFileObject(remoteFile.getAbsolutePath(), monitor);

Thanks..

As per my case, I create many the remote file/folder handles, which I'm supposed to create manually(actually running a script) which may or many not be created.

So the method IRemoteFile.exists() becomes not affordable and un-usable because I don't know which which remote files/folders are actually created, and I need to create and use my own 'exists' method in MyRemoteUtil..

public static boolean IsRemoteFileExists(IRemoteFile remoteFile) {
   // make the cached file stale
   remoteFile.markStale(true); 
 
   // requery it to obtain a fresh version
   remoteFile =fs.getRemoteFileObject(remoteFile.getAbsolutePath(), monitor);

  return remoteFile.exists();
}

and should not use the IRemoteFile.exists().

My suggestion is either to make IRemoteFile.exists() as transparent or provide an additional method to provide the transparent result.

But I know that this is up to you developer/maintainer's decision..

Thanks..
Comment 3 David McKnight CLA 2010-04-30 09:46:40 EDT
I'm not sure whether this will help in your multiple handles scenario, but I'll pass this on just in case.  The file subsystem has the following method that can be used to query multiple files in one call:

	/**
	 * Given a set of fully qualified file or folder names, return an ISystemResourceSet object for it.
	 * @param folderOrFileNames Fully qualified folder or file names
	 * @param monitor the progress monitor
	 *
	 * @return the set of resources
	 * @since 3.0
	 */
	public IRemoteFile[] getRemoteFileObjects(String[] folderOrFileNames, IProgressMonitor monitor) throws SystemMessageException;

Of course, if files don't exist at the time of the query, then none of the handles will return true for IRemoteFile.exists().  Is there any reason why you can't run the script first and then query the files?
Comment 4 Loganathan CLA 2010-04-30 10:01:58 EDT
(In reply to comment #3)
> I'm not sure whether this will help in your multiple handles scenario, but I'll
> pass this on just in case.  The file subsystem has the following method that
> can be used to query multiple files in one call:
> 
>     /**
>      * Given a set of fully qualified file or folder names, return an
> ISystemResourceSet object for it.
>      * @param folderOrFileNames Fully qualified folder or file names
>      * @param monitor the progress monitor
>      *
>      * @return the set of resources
>      * @since 3.0
>      */
>     public IRemoteFile[] getRemoteFileObjects(String[] folderOrFileNames,
> IProgressMonitor monitor) throws SystemMessageException;
> 
> Of course, if files don't exist at the time of the query, then none of the
> handles will return true for IRemoteFile.exists().  Is there any reason why you
> can't run the script first and then query the files?

Hi, thanks..

Of course, I can find a way to re-write my code flow to query the files after running the script. But there should be the proper documentation for the IRemoteFile.exists() method saying that it is not usable for files that don't exist, or should not allow to create the handle or return null or exception while creating the handle for a non-existing resource.. without which it took half a day for me to find the cause.

Thanks..
Comment 5 David McKnight CLA 2010-04-30 10:46:11 EDT
(In reply to comment #4)
> (In reply to comment #3)
> > I'm not sure whether this will help in your multiple handles scenario, but I'll
> > pass this on just in case.  The file subsystem has the following method that
> > can be used to query multiple files in one call:
> > 
> >     /**
> >      * Given a set of fully qualified file or folder names, return an
> > ISystemResourceSet object for it.
> >      * @param folderOrFileNames Fully qualified folder or file names
> >      * @param monitor the progress monitor
> >      *
> >      * @return the set of resources
> >      * @since 3.0
> >      */
> >     public IRemoteFile[] getRemoteFileObjects(String[] folderOrFileNames,
> > IProgressMonitor monitor) throws SystemMessageException;
> > 
> > Of course, if files don't exist at the time of the query, then none of the
> > handles will return true for IRemoteFile.exists().  Is there any reason why you
> > can't run the script first and then query the files?
> 
> Hi, thanks..
> 
> Of course, I can find a way to re-write my code flow to query the files after
> running the script. But there should be the proper documentation for the
> IRemoteFile.exists() method saying that it is not usable for files that don't
> exist, or should not allow to create the handle or return null or exception
> while creating the handle for a non-existing resource.. without which it took
> half a day for me to find the cause.
> 
> Thanks..

Fair enough, further documentation should be added to mention that IRemoteFile handles are created whether the files exist or not and that, in order to get an updated version of a file's state, the remote file needs to first be marked stale and then requeried.