apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ryan Bloom" <...@covalent.net>
Subject RE: proposal to add apr_check_dir_empty() to APR
Date Tue, 02 Jul 2002 20:07:59 GMT
It isn't portable.   :-(  Comments below.

> From: Karl Fogel [mailto:kfogel@newton.ch.collab.net]
> 
> Currently, apr_check_dir_empty() is living in the Subversion source
> tree.  The implementation looks portable, though; is there any reason
> not to move this into APR?
> 
>    apr_status_t
>    apr_check_dir_empty (const char *path,
>                         apr_pool_t *pool)
>    {
>      apr_status_t apr_err, retval;
>      apr_dir_t *dir;
>      apr_finfo_t finfo;
> 
>      apr_err = apr_dir_open (&dir, path, pool);
>      if (apr_err)
>        return apr_err;
> 
>      /* All systems return "." and ".." as the first two files, so
read
>         past them unconditionally. */
>      apr_err = apr_dir_read (&finfo, APR_FINFO_NAME, dir);
>      if (apr_err) return apr_err;
>      apr_err = apr_dir_read (&finfo, APR_FINFO_NAME, dir);
>      if (apr_err) return apr_err;

This isn't portable.   POSIX specifically states that you don't need to
return "." or "..", and APR doesn't make any comments about them.

>      /* Now, there should be nothing left.  If there is something
left,
>         return EGENERAL. */
>      apr_err = apr_dir_read (&finfo, APR_FINFO_NAME, dir);
>      if (APR_STATUS_IS_ENOENT (apr_err))
>        retval = APR_SUCCESS;
>      else if (! apr_err)
>        retval = APR_EGENERAL;
>      else
>        retval = apr_err;
> 
>      apr_err = apr_dir_close (dir);
>      if (apr_err)
>        return apr_err;
> 
>      return retval;
>    }

The return code should not be EGENERAL if the directory isn't empty.
Create a new status code if you have to, but a non-empty directory is
not an error condition.

If you fix those two problems, then I am all for this going into APR.
However, can we get better performance on some platforms by using native
functions???

Ryan



Mime
View raw message