rmdir(2)
will fail if the directory is not empty. If another process is creating files while rm(1)
is removing them, it will not know to delete them and consequently when it comes time for rm(1)
to try to delete what it believes should be an empty directory, it will fail with the error you've posted.
One way to delete the directory in the face of concurrent file creations in the directory is to rename it:
mv a a~
rm -rf a~
It's possible that this may not work if the processes creating the files in a/b
are not doing so by path (open(2)
vs. openat(2)
).
I am assuming that the process(es) that creates files in a/b
will recreate that directory if it does not exist, or will handle failure gracefully if it does not exist. Since you are already trying to delete the directory from under other processes, that seems like a safe assumption.
rm -rf
should always succeed, short of permission issues. Ask the script to print debugging output if the removal fails.ls -laR a/b
should suffice. – Faheem Mitha May 04 '11 at 16:41