svn commit: samba r9629 - in branches/SOC/SAMBA_3_0/source/client: .

Kalim M kmoghul at gmail.com
Fri Aug 26 13:44:12 GMT 2005


On 8/26/05, derrell at samba.org <derrell at samba.org> wrote:
> kalim at samba.org writes:
> 
> > +                    /* test if the directory exists by opening it */
> > +                    if (!((dh=smbc_opendir(rname)) < 0)) {
> > +                        smbc_closedir(dh);
> > +                        continue;
> > +                    }
> 
> > +                    /* directory does not exist, try making it */
> > +                    if (!(smbc_mkdir(rname, 755) < 0))
> > +                        continue;
> 
> Be careful of this.  I haven't had a chance to check out all of your code to
> see what you're doing, but if you're really just trying to see if the
> directory exists, smbc_opendir() is a *really* slow way of doing it.  The
> current implementation of smbc_opendir() retrieves the entire list of files in
> the directory being opened!  It caches that information and returns entries as
> they are requested by smbc_readdir() or smbc_getdents().

Good point. I read through the opendir() code and realized it is doing
a lot of stuff to enumerate the files. I really just wanted to do a
simple check to see if it exists.

> It would be better not first to check whether the directory exists.  You're
> creating a race condition by doing so (i.e. what if the directory is created
> by someone else immediately after you checked to see if it exists?).  Instead,
> just issue your smbc_mkdir() call and check the return code.  Although there
> are some not-so-meaningful errno values that occasionally get returned by
> libsmbclient, I think you'll get back EEXISTS if the directory already
> existed.  If it already existed, you could _then_ issue your smbc_opendir()
> call if you need to enumerate the contents.

I think the mkdir() test would be good enough.
 
> Derrell
> 

Thanks!

-Kalim


More information about the samba-technical mailing list