Modify

Ticket #2925 (closed Bugs: fixed)

Opened 5 years ago

Last modified 4 years ago

boost::filesystem cannot atomically copy file if tarteg exists

Reported by: andre-boost@… Owned by: bemandawes
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

Change History

comment:1 Changed 4 years ago by bemandawes

  • Status changed from new to closed
  • Resolution set to fixed

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.