Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-01-19 06:40:55


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.

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, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk