Boost C++ Libraries: Ticket #4741: filesystem V3 : remove_all by remove_all_aux problem https://svn.boost.org/trac10/ticket/4741 <p> Hi everyone, </p> <p> First of all, I want to thanks boost::filesystem contributors for their amazing work. I use it, and it makes me learn a lot about library design. </p> <p> In the filesystem V3, I found the following issue. </p> <p> when using </p> <pre class="wiki">boost::uintmax_t remove_all(const path&amp; p, system::error_code* ec=0); </pre><p> like this : </p> <pre class="wiki">remove_all("C:\\test_path_to_delete"); </pre><p> the <em>C:\test_path_to_delete</em> (and its descendent) is successfully deleted (as described in documentation) </p> <p> but when I use it like this : </p> <pre class="wiki">boost::system::error_code ec; remove_all("C:\\test_path_to_delete", ec); </pre><p> <strong>The directory (and it descendent) aren't removed at all.</strong> </p> <p> I have investigated and, I found the following : </p> <p> file: <em>boost_1_44_0/libs/filesystem/v3/src/operation.cpp</em><br /> function: <em>boost::uintmax_t remove_all_aux(const path&amp; p, fs::file_status sym_stat, error_code* ec);</em> </p> <pre class="wiki">boost::uintmax_t remove_all_aux(const path&amp; p, fs::file_status sym_stat, error_code* ec) { boost::uintmax_t count = 1; if (!fs::is_symlink(sym_stat)// don't recurse symbolic links &amp;&amp; fs::is_directory(sym_stat)) { for (fs::directory_iterator itr(p); itr != end_dir_itr; ++itr) { fs::file_status tmp_sym_stat = fs::symlink_status(itr-&gt;path(), *ec); HERE=&gt; if (ec != 0 &amp;&amp; ec) return count; count += remove_all_aux(itr-&gt;path(), tmp_sym_stat, ec); } } remove_file_or_directory(p, sym_stat, ec); return count; } </pre><p> This function is called by <em>remove_all</em>. </p> <p> Here, ec is passed by address. </p> <p> When </p> <pre class="wiki">remove_all("C:\\test_path_to_delete"); </pre><p> is called, <em>&amp;ec = 0</em> (default argument) </p> <p> so the check <em>if (ec != 0 &amp;&amp; ec)</em> <strong>will never hit</strong>. </p> <p> But when called with </p> <pre class="wiki">remove_all("C:\\test_path_to_delete", ec); </pre><p> ec is allocated and <em>&amp;ec != 0</em>, the check <em>if (ec != 0 &amp;&amp; ec)</em> <strong>is allways true, and the function returns at the first iteration.</strong> </p> <p> I'm maybe wrong, but, isn't this what you meant to do? </p> <pre class="wiki">if (ec != 0 &amp;&amp; *ec) return count; </pre><p> Thanks again. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4741 Trac 1.4.3 Beman Dawes Fri, 15 Oct 2010 18:50:41 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4741#comment:1 https://svn.boost.org/trac10/ticket/4741#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">duplicate</span> </li> </ul> <p> Thanks for the report, but I think this is essentially a duplicate of <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4799" title="#4799: Bugs: Linker error in math library - rint() missing on MS windows platform (closed: fixed)">#4799</a> which was fixed October, 5th. See changeset 65765. </p> <p> --Beman </p> Ticket