Finding out if a directory is empty ...

Steve Langasek vorlon at netexpress.net
Tue Mar 27 05:42:29 GMT 2001


On Tue, 27 Mar 2001, Kenichi Okuyama wrote:

> Okey. But! At least, what you should first do is rmdir().

> If you succeed, then it's case 4. No doubt.
> If errno == 'EPERM', then it's write permission that you didn't have.
> This is one of the case 3.
> If errno == 'EFAULT' or 'ENOENT' then it's case 5.
> If errno != 'EACCESS' than it's case 6.

> Now we get to point where we have to decide whether it's case 1 or
> 2.
> But according to whay you've mentioned, we do not really have to
> check if it's case 1 or 2, for ether cases, we're going to return
> "ENOTEMPTY".

> # Am I reading your sentence correctly?

But you need to distinguish between cases 2 and 3: you've suggested returning
EACCES whenever the user does not have permission to delete the directory, but
Richard says he needs to ONLY return EACCES when the user does not have
permission to delete the directory AND the directory is truly empty.  If the
directory is not empty, he returns a different error, so clearly he needs to
know if the directory is empty or not.

Steve Langasek
postmodern programmer





More information about the samba-technical mailing list