From: Walter Landry (wlandry_at_[hidden])
Date: 2005-01-19 18:03:13
"Peter Dimov" <pdimov_at_[hidden]> wrote:
> 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.
> This patch would only fix remove_all, but the general case remains broken. A
> filesystem iterator should not be affected by another filesystem iterator.
The only fix for that is readdir_r. There is a comment in the docs
that readdir_r might not always be available. This is one of those
cases where an autoconf macro would come in handy.
> By the way, POSIX says that readdir can only overwrite the result of readdir
> on the same directory stream, so OS X seems to be buggy in this regard.
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