
At 10:58 PM 1/18/2005, Walter Landry wrote:
Greetings,
I have discovered a bug in the implementation of remove_all. remove_all works by reading through a directory and deleting entries along the way. If it comes across a subdirectory, it immediately recurses into that subdirectory. However, boost::filesystem uses readdir, which on some platforms (including OS X, apparently) uses a static data area that can be overwritten on each call to readdir. This messes up the original directory iteration, ending up with some entries not being deleted.
A solution is to not recurse the directory immediately, but to make a list of them. Once you have gone through all of the entries in a directory, then you recurse into the subdirectories. A patch is below, although it could probably be improved.
Walter, Thanks for the report. As Peter pointed out, that isn't supposed to happen on a POSIX compliant system. Is it possible the bug is actually in the remove_all code or your code? I've had a "to do" item for a month or so to change readdir to readdir_r on systems which support it. My guess is that almost all modern POSIX operating systems support readdir_r, but there is a configuration macro so the code can adapt to what is available. I'm not sure my guesses about POSIX are worth anything, however, since I would have guessed every modern POSIX OS implements readdir correctly:-( Anyhow, readdir_r should solve this problem so I'll accelerate that fix. --Beman