Modify

Opened 9 years ago

Closed 7 years ago

#2925 closed Bugs (fixed)

boost::filesystem cannot atomically copy file if tarteg exists

Reported by: andre-boost@… Owned by: Beman Dawes
Milestone: Boost 1.39.0 Component: filesystem
Version: Boost 1.38.0 Severity: Problem
Keywords: Cc:

Description

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.

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by Beman Dawes

Resolution: fixed
Status: newclosed

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.

Thanks,

--Beman

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Beman Dawes.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.