[Boost-bugs] [Boost C++ Libraries] #2925: boost::filesystem cannot atomically copy file if tarteg exists

Subject: [Boost-bugs] [Boost C++ Libraries] #2925: boost::filesystem cannot atomically copy file if tarteg exists
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-04-08 14:58:49


#2925: boost::filesystem cannot atomically copy file if tarteg exists
------------------------------------+---------------------------------------
 Reporter: andre-boost_at_[hidden] | Owner: bemandawes
     Type: Bugs | Status: new
Milestone: Boost 1.39.0 | Component: filesystem
  Version: Boost 1.38.0 | Severity: Problem
 Keywords: |
------------------------------------+---------------------------------------
 The following code leads to race conditions, i.e. can fail with 'file
 exists' if another process interferes (pseudo code)

 {{{
 void copy (std::string src,
            std::string target,
            int flags)
 {
   if ( (flags & Overwrite) &&
        boost::fs::exists (tgt) )
   {
     boost::fs::remove (tgt);
   }

   // second process can create file again here

   boost::fs::copy_file (src, tgt);
 }
 }}}

 I think similar problems are obvious for other boost::fs operations.

 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.

 Thanks, Andre.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2925>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:00 UTC