cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: first 94208 bytes corrupted! (Ubuntu 14)

From: Wagner Patriota <wagner.patriota_at_gmail.com>
Date: Fri, 23 May 2014 18:24:29 -0300

I noticed I didn't check if the file handle is actually valid. Now I fixed
and I will test a little more... [in bold]
But I really don't think it's the error, once the file it's supposed to
write on is a *completely new path*, almost impossible the file handle not
be valid.

void HTTPTools::downloadFile( const string & p_url, const string &
p_filename )
{
 CURL * curl( curl_easy_init() );

if ( !curl )
 {
throw Exception( __FILE__, __LINE__, Error_DownloadRemoteFile )
 << "Could not initialize cURL for download of " << p_url;
}

SystemTools::mkdir( StringTools::stringByDeletingLastPathComponent(
p_filename ) );

string tempFilename( p_filename );
tempFilename += ".tmp";

FILE * file( fopen( tempFilename.c_str(), "wb+" ) );

* if ( !file )*
* {*
* throw Exception( __FILE__, __LINE__ ) << "Can't open file when
downloading " << StringTools::getLastPathComponent( p_filename );*
* }*

curl_easy_setopt( curl, CURLOPT_URL, p_url.c_str() );
 curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, fwrite );
curl_easy_setopt( curl, CURLOPT_WRITEDATA, file );
 curl_easy_setopt( curl, CURLOPT_FOLLOWLOCATION, true );
curl_easy_setopt( curl, CURLOPT_TIMEOUT, 0 );
 curl_easy_setopt( curl, CURLOPT_NOSIGNAL, 0L );

curl_easy_setopt( curl, CURLOPT_NOPROGRESS, 0 );
 curl_easy_setopt( curl, CURLOPT_PROGRESSFUNCTION, progressCallback );

#if 0
curl_easy_setopt( curl, CURLOPT_VERBOSE, 1 );
#endif

char errorBuffer[ CURL_ERROR_SIZE + 1 ];
curl_easy_setopt( curl, CURLOPT_ERRORBUFFER, errorBuffer );

// SSL
if ( m_certicatePath.empty() )
 {
curl_easy_setopt( curl, CURLOPT_SSL_VERIFYPEER, 0L );
 curl_easy_setopt( curl, CURLOPT_SSL_VERIFYHOST, 0L );
}
 else
{
curl_easy_setopt( curl, CURLOPT_CAINFO, m_certicatePath.c_str() );
 }

CURLcode res( curl_easy_perform( curl ) );

fclose( file );

 if ( res != CURLE_OK )
{
 curl_easy_cleanup( curl );
remove( tempFilename.c_str() );
 throw Exception( __FILE__, __LINE__, Error_DownloadRemoteFile )
<< "cURL error when downloading " << p_url << " > " << errorBuffer;
 }

long httpResponseCode( 0 );
 curl_easy_getinfo( curl, CURLINFO_RESPONSE_CODE, &httpResponseCode );
curl_easy_cleanup( curl );

if ( ( httpResponseCode / 100 ) != 2 )
{
 remove( tempFilename.c_str() );
throw Exception( __FILE__, __LINE__, Error_DownloadRemoteFile )
 << "HTTP error " << httpResponseCode << " when downloading " << p_url;
 }

SystemTools::moveFile( tempFilename, p_filename );
}

On Fri, May 23, 2014 at 5:40 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Fri, 23 May 2014, Wagner Patriota wrote:
>
> It seems that libCurl uses a buffer of 94208 bytes.... is this true?
>>
>
> No it doesn't.
>
>
> any hint on how only the first "chunk" is coming all null?
>>
>
> Not really, no. Something in your system seems severly broken.
>
>
> should I give more details? or this is a kwon bug?
>>
>
> Tell us how to repeat it.
>
> *Detail:* it only happens on Ubuntu 14. Mac works fine. Windows works
>> fine!
>>
>
> ... and of course curl works the same on all these platforms and uses the
> same buffer sizes: 16KB every time.
>
> --
>
> / daniel.haxx.se
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
>

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-05-23