title: Call of system(...) to process file created by curl_easy_perform fails randomly?
body: <p>I am using libcurl to get some archive file from an URL and write it to disk with a simple C++ wrapper that does nothing but <code>curl_easy_setopt</code> into <code>curl_easy_perform</code>.
  This call is immediately followed by</p>
  
  <pre><code>std::this_thread::sleep_for(std::chrono::milliseconds(500));
  system("bash -c 'unpack \"path_to_archive\"'");
  </code></pre>
  
  <p>Where bash is on Windows 10 in cygwin, but not sure if this is relevant. I have been using this for a while and it works, but only <em>almost</em> always.. Sometimes, the <code>unpack</code> will fail and print an error, but the even more curious thing is that if I then go to the directory myself, and manually call <code>unpack</code> from a terminal on the same file written by curl, it works.</p>
  
  <p>So there is no write error, and as far as I can tell, I did not suppress any errors in the code. In my wrapper I have</p>
  
  <pre><code>if(curl_easy_perform(handle)) throw std::runtime_error("CURL error")
  </code></pre>
  
  <p>which never throws. I could only imagine a few causes:</p>
  
  <ul>
  <li>The code leaves <code>curl_easy_perform</code> before it actually finishes writing the file (it is supposed to be synchronous..?). This makes <code>unpack</code> fail on an incomplete file, but shortly after the write is completed</li>
  <li>Similar, but somehow the write to disk, which may have some asychronous low level calls (it really shouldn't ..?), does not "finalize" the file properly (whatever that would mean?) before the call to <code>unpack</code></li>
  <li>???</li>
  </ul>
  
  <p>I am stuck here because it only fails rarely. I did some tests with larger files to try and reproduce the error more frequently, but it did not seem to make any difference. So it is hard to test as each run takes very long and I have no better guesses than the two above..
  For the first guess writing larger files should have made a difference, and in the second I have no idea how to try and fix it aside from inserting an even longer sleep than there already is.</p>
  
  <p>Any ideas?</p>