From: Beman Dawes (bdawes_at_[hidden])
Date: 2005-01-19 19:08:49
At 10:58 PM 1/18/2005, Walter Landry wrote:
>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.
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.
Boost list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk