title: How to be sure that boost::filesystem::remove does not try to delete a file that is used by another process?
body: <p>I want to upload a file to AWS S3 bucket. Before doing this I create a .gz file from it to reduce its storage. After uploading it I want to delete the .gz file again with boost::filesystem::remove.</p>
  
  <p>It seems like that the upload is blocking the file it is uploading and I wasn't able to find a way to wait for the complete result so the file wouldn't be locked anymore.</p>
  
  <p>The removing works with a different call in the main(). Directly after the uploading call it does not work and boost operations.hpp throws an exception.</p>
  
  <p>The exception says that the file is already used by another process.</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  boost::filesystem::path path{ C:/Development/test.gz };
  
  //deletes the file correctly if called
  //boost::filesystem::remove(path); 
  
  //upload file first, then delete it
  putObject(path)
  }
  
  void putObject(path, s3client)
  {
  auto input_data = Aws::MakeShared&lt;Aws::FStream&gt;("", path.string(),
  std::ios_base::in | std::ios_base::binary);
  
  auto request = Aws::S3::Model::PutObjectRequest();
  request.WithBucket("bucketName").WithKey(key);
  request.SetBody(input_data);
  request.SetMetadata(metadata);
  
      //upload file to s3 bucket
  s3client-&gt;PutObject(request);
  
  //throws exception if called - file is in use
  boost::filesystem::remove(path);
  
  }
  </code></pre>
  
  <hr>
  
  <p>boost operations.hpp that throws the exception (line 664):</p>
  
  <pre><code>inline
  // For standardization, if the committee doesn't like "remove", consider  
  "eliminate"
  bool remove(const path&amp; p)           {return detail::remove(p);}
  </code></pre>
  
  <p>Is there a way to be sure that the file will be deleted if it isn't blocked anymore?</p>