Boost C++ Libraries: Ticket #2925: boost::filesystem cannot atomically copy file if target exists https://svn.boost.org/trac10/ticket/2925 <p> The following code leads to race conditions, i.e. can fail with 'file exists' if another process interferes (pseudo code) </p> <pre class="wiki">void copy (std::string src, std::string target, int flags) { if ( (flags &amp; Overwrite) &amp;&amp; boost::fs::exists (tgt) ) { boost::fs::remove (tgt); } // second process can create file again here boost::fs::copy_file (src, tgt); } </pre><p> I think similar problems are obvious for other boost::fs operations. </p> <p> A solution would be to allow flags for boost's operations, and forward them to open (that is where the current code bails out I think). Other solutions are possible, too, like adding another call which allows overwrite. </p> <p> Thanks, Andre. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2925 Trac 1.4.3 Beman Dawes Sat, 12 Jun 2010 19:52:15 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2925#comment:1 https://svn.boost.org/trac10/ticket/2925#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">fixed</span> </li> </ul> <p> The overwrite_if_exists option takes care of this. It has been available for several releases - I should have closed the ticket at the time it was added. </p> <p> Thanks, </p> <p> --Beman </p> Ticket anonymous Thu, 03 May 2018 16:33:58 GMT summary changed https://svn.boost.org/trac10/ticket/2925#comment:2 https://svn.boost.org/trac10/ticket/2925#comment:2 <ul> <li><strong>summary</strong> <span class="trac-field-old">boost::filesystem cannot atomically copy file if tarteg exists</span> → <span class="trac-field-new">boost::filesystem cannot atomically copy file if target exists</span> </li> </ul> Ticket