cURL / Mailing Lists / curl-library / Single Mail

curl-library

is CURLOPT_FILE operation atomic?

From: German Escallon <germane_at_adtecinc.com>
Date: Thu, 04 Nov 2010 13:29:39 -0400

Hello all,

My application continuously downloads several XML files through cURL FTP
methods at a certain interval (say once every hour).
Also, another process reads those files and performs operations on them
(read, mv, cp, etc) at a different interval.

Does anyone know if the WRITE_DATA operation is atomic?
In other words. Is it safe to assume that if I'm downloading file X,
and another process is trying to access X while curl_easy_perform is
writing to it, the other process will not get a corrupted or partial file?
I'm attaching some sample code. Thank you in advance.

....
..
//open local file in write mode
   pFile = fopen(localSchPath.c_str(), "w");

   //verify that file opened correctly
   if(pFile == NULL)
      {
      logMgr.logf(LOG_GENERAL_BASE, "Error: Opening of schedule file
\"%s\" failed.", localSchPath.c_str());
      return FAILURE;
      }

   //set cURL options
   if(
      ((retCode = curl_easy_setopt(mp_curlConnection, CURLOPT_URL,
remoteSchPath.c_str())) != CURLE_OK) || //set url of file to be downloaded
      ((retCode = curl_easy_setopt(mp_curlConnection, CURLOPT_FILE,
pFile)) != CURLE_OK) ||//set file where data will be stored
      ((retCode = curl_easy_setopt(mp_curlConnection,
CURLOPT_DIRLISTONLY, 0)) != CURLE_OK) //Disable
directory listing option to retrieve entire contents of the file
      )
      {
      logMgr.logf(LOG_GENERAL_BASE, "cURL: Error: Setting options to
download file \"%s\".", localSchPath.c_str());
      return FAILURE;
      }

   //execute download
   if(curl_easy_perform(mp_curlConnection))
      {
      logMgr.logf(LOG_GENERAL_BASE, "cURL: Error: Downloading of
schedule file \"%s\" failed.", remoteSchPath.c_str());
      return FAILURE;
      }

   fclose(pFile); //close file stream.
...
..
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-11-04