|
Boost : |
From: Beman Dawes (bdawes_at_[hidden])
Date: 2005-01-19 19:14:56
At 06:40 AM 1/19/2005, Peter Dimov 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.
Right. I'll add a test case to try to detect that happening.
>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.
Strange. I wonder if most OS X developers use readdir_r. Otherwise I would
think a serious non-compliance in readdir would have been fixed a long time
ago.
Thanks,
--Beman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk