Boost C++ Libraries: Ticket #7307: boost::filesystem::remove_all(dirname,ec) throws on write protected directories https://svn.boost.org/trac10/ticket/7307 <p> Hi there, </p> <p> according to the documentation, functions with error_code should not throw except if storage cannot be allocated. </p> <p> The following throws if directory "bla" exists but is write protected: </p> <pre class="wiki"> string bla("bla"); boost::system::error_code ec; boost::filesystem::remove_all(bla,ec); </pre><p> The bla directory looks like this: </p> <pre class="wiki">ls -l bla d--------- 2 bach bach 4096 2012-08-30 23:56 bla </pre><p> Output of the program is: </p> <p> <em>terminate called after throwing an instance of "boost::filesystem::filesystem_error" what(): boost::filesystem::directory_iterator::construct: Permission denied: "bla" Aborted </em> </p> <p> System: Ubuntu 9.10 Boost: 1.50, looking through change notes for 1.51 I did not see any entries for filesystem which could address this. </p> <p> Best, </p> <blockquote> <p> Bastien </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7307 Trac 1.4.3 viboes Tue, 18 Sep 2012 16:58:38 GMT component changed; owner set https://svn.boost.org/trac10/ticket/7307#comment:1 https://svn.boost.org/trac10/ticket/7307#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Beman Dawes</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">filesystem</span> </li> </ul> Ticket anonymous Wed, 13 Jan 2016 22:30:33 GMT <link>https://svn.boost.org/trac10/ticket/7307#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7307#comment:3</guid> <description> <p> Any update on when this will be fixed ? I am new to this code so apologies if I misunderstood anything. </p> <p> remove_all_aux() may have forgotten to pass the error_code argument to the constructor to the constructor of directory_iterator(). </p> <blockquote> <p> if (type == fs::directory_file) <em> but not a directory symlink { </em></p> <blockquote> <p> for (fs::directory_iterator itr(p); &lt;&lt;&lt;---- itr(p, ec) instead ?! </p> <blockquote> <p> itr != end_dir_itr; ++itr) </p> </blockquote> <p> { </p> </blockquote> </blockquote> </description> <category>Ticket</category> </item> <item> <author>florian jacomme <florian@…></author> <pubDate>Sun, 04 Sep 2016 09:15:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7307#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7307#comment:4</guid> <description> <p> pull request: <a class="ext-link" href="https://github.com/boostorg/filesystem/pull/33"><span class="icon">​</span>https://github.com/boostorg/filesystem/pull/33</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Beman Dawes</dc:creator> <pubDate>Wed, 23 Nov 2016 17:05:13 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7307#comment:5 https://svn.boost.org/trac10/ticket/7307#comment:5 <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">fixed</span> </li> </ul> <p> Hopefully fixed. Here is the commit message: Fix <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7307" title="#7307: Bugs: boost::filesystem::remove_all(dirname,ec) throws on write protected ... (closed: fixed)">#7307</a>, remove_all(dirname,ec) throws on write protected directories. This is a tough one to test. There are three internal function calls where errors might arise, and it would take too much time to write tests for each of those cases. Someday we will have Titus Winter's mock installable file system, but for now are relying on code inspection rather than testing. </p> <p> Thanks for the bug report! </p> <p> --Beman </p> Ticket