[jcifs] Some additions to SmbFile.java

Michael B. Allen mballen at erols.com
Thu Oct 18 05:11:58 EST 2001


Ok. I want to keep the SmbFile code minimalistic but this looks reasonable.

On Wed, Oct 17, 2001 at 05:11:13PM +0200, The DJ wrote:
> 
> You have to check for canonicalPath, or all directories are shares aswell.
> CanonicalPath can also be used to adapt isDirectory(). Trivial of course.
> 
> DJ
> 
> /**
>  * Tests to see if the file this <code>SmbFile</code> represents is a Share.
>  *
>  * @return <code>true</code> if this <code>SmbFile</code> is a Share
>  */
> 
>     public boolean isShare() {
>             if (this.exists() && this.isDirectory() ) {

Be carefull here though. Calling exists triggers a packet to go out on the
wire and isDirectory calls exists() so no need to do it again. Something
like:

			if( exists() && ( attributes & ATTR_DIRECTORY ) == ATTR_DIRECTORY)

might be better.

>                 if  ( url.share != null && url.canonicalPath == null)

As I mentioned in the other message, I don't think the share being null
means that there isn't one. This code might be fine regardless but be
carefull about accessing memebers of SmbURL directly. SmbFile anad SmbURL
are very tighly coupled (might as well be the same class). You'd really
have to look at SmbURL closely to see what's going on. This code is hit
pretty hard (_at least_ every time an SmbFile object is created) so adding
proper accessors and logic like share == null means no share isn't the
priority. Of course if you can come up with a better way to handle URLs
I'd be interested. The SmbURL/SmbFile relationship could be improved.

>                     return true;
>             }
>             return false;
>     }
>         
> > /**
> > * Tests to see if the file this <code>SmbFile</code> represents is a
> > Server.
> > *
> > * @return <code>true</code> if this <code>SmbFile</code> is a Server
> > */
> > 
> >   public boolean isServer() {
> >           if (this.exists() && this.isDirectory() ) {
> >               if  ( url.share == null && url.server != null)
> >                   return true;
> >           }
> >           return false;
> >   }   
> > 
> > Be aware that a share and a server remain to respond positive to
> > .isDirectory() as they do in the current implementation
> > Maybe that should be changed aswell. That would obviously affect the above
> > methods, in that isDirectory() should have to be negative.
> > 
> > I personally need this because I'm building a client and I use graphics in
> > my listing to represent the kind of service I'm listing.

-- 
May The Source be with you.




More information about the jcifs mailing list