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

derrell at samba.org derrell at samba.org
Fri Aug 26 13:28:04 GMT 2005


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().

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.

Derrell


More information about the samba-technical mailing list