$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Walter Landry (wlandry_at_[hidden])
Date: 2005-01-18 22:58:33
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.
Cheers,
Walter Landry
wlandry_at_[hidden]
--- /home/boo/arx/arx/src/boost/_arx/++cache/wlandry_at_ucsd.edu--arx/boost/1/32/,4/libs/filesystem/src/operations_posix_windows.cpp	2005-01-04 14:11:44.000000000 -0500
+++ /home/boo/arx/arx/src/boost/libs/filesystem/src/operations_posix_windows.cpp	2005-01-18 21:16:49.000000000 -0500
@@ -28,6 +28,7 @@
 #include <boost/throw_exception.hpp>
 #include <boost/detail/workaround.hpp>
 #include <cstring>
+#include <list>
 
 #ifdef BOOST_NO_STDC_NAMESPACE
 namespace std { using ::strcmp; using ::remove; using ::rename; }
@@ -191,11 +192,23 @@
     if ( !fs::symbolic_link_exists( ph ) // don't recurse symbolic links
       && fs::is_directory( ph ) )
     {
+      std::list<fs::path> dir_list;
       for ( fs::directory_iterator itr( ph );
             itr != end_itr; ++itr )
       {
-        count += remove_all_aux( *itr );
+        if(!fs::symbolic_link_exists( ph ) // don't recurse symbolic links
+           && fs::is_directory( ph ) )
+          {
+            dir_list.push_back(*itr);
+          }
+        else
+          {
+            count += remove( *itr );
+          }
       }
+      for(std::list<fs::path>::iterator i=dir_list.begin();
+          i!=dir_list.end(); ++i)
+        count+=remove_all_aux(*i);
     }
     fs::remove( ph );
     return count;