Finding out if a directory is empty ...

Richard Sharpe sharpe at ns.aus.com
Tue Mar 27 05:30:16 GMT 2001


At 01:52 PM 3/27/01 +0900, Kenichi Okuyama wrote:
>Dear Sharpe,
>
>>>>>> "RS" == Richard Sharpe <sharpe at ns.aus.com> writes:
>RS> I need to find out whether or not a directory is empty in order to
properly
>RS> handle an error case for smbc_unlinkdir ...
>
>Why don't you simply call rmdir() system call?
>
>If directory is empty, you'll succeed.
>If it's not, you'll fail.

Ummm, no. The situations are:

1. Directory is not empty, and you do not have sufficient access to remove it
2. Directory is not empty, and you do have sufficient access to remove it
3. Directory is empty, and you do not have sufficient access to remove it
4. Directory is empty, and you do have sufficient access to remove it.

I have to return the following:

1. ENOTEMPTY
2. ENOTEMPTY
3. EACCES
4. 0

As you say, if I try to delete the directory, and it is not empty, I get
back EACCES from a Samba mapping function, but I then have to determine if
the problem was an empty directory to which the caller truly does not have
access or the directory is not empty.

>If you fail, look at errno, they'll give you the reason why.
># Though you might need errno mapping table for each OS,
># this is lot faster and simpler way than any other way.
>----
>Kenichi Okuyama @Tokyo Research Lab. IBM-Japan. Co.
>

Regards
-------
Richard Sharpe, sharpe at ns.aus.com
Samba (Team member, www.samba.org), Ethereal (Team member, www.ethereal.com)
Contributing author, SAMS Teach Yourself Samba in 24 Hours
Author, Special Edition, Using Samba






More information about the samba-technical mailing list