title: Ensure that the export of multiple files is atomic
body: <p>I have to implement an exporter library in C++, that can format and export different kinds of data to different kinds of file formats (csv, xml, ...).</p>
  
  <p>Each export may consists of a bunch of files and directories:</p>
  
  <pre><code>data
  |-- person
  |    |-- joepublic 
  |    |    +-- File1.xml
  |    |    +-- Annotation.csv
  |    |    +-- Annotation2.csv
  |    |-- mrsmith
  |    |    +-- Balance.bin
  </code></pre>
  
  <p>Now it might happen under a multitude of circumstances that the export fails in one of these files. Let's assume, that I was unable to write Balance.bin, as the format was incorrect or I ran out of disk space. </p>
  
  <p>Now I'm left with an inconsistent set of files, that might crash another application while reading them. </p>
  
  <p>How can I prevent myself from such inconsistent exports and at the same time reduce the amount of necessary code. Are there some standard procedures or libraries around? </p>
  
  <p>My first attempt for a solution would be to export all files firstly to the temp directory and after successfully writing them to move them to the correct target directory.</p>