Changeset 10573


Ignore:
Timestamp:
May 1, 2010, 4:06:58 AM (11 years ago)
Author:
charles
Message:

(1.9x libT) backport r10495 for #3154 "crash when saving a blocklist to disk when the disk is full"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.9x/libtransmission/rpcimpl.c

    r10288 r10573  
    1313#include <assert.h>
    1414#include <ctype.h> /* isdigit */
     15#include <errno.h>
    1516#include <stdlib.h> /* strtol */
    1617#include <string.h> /* strcmp */
     
    899900                     response_code, tr_webGetResponseStr( response_code ) );
    900901    }
    901     else /* success */
    902     {
    903         int ruleCount;
    904         char * filename = tr_buildPath( tr_sessionGetConfigDir( session ), "blocklist.tmp", NULL );
    905         FILE * fp;
    906 
    907         /* download a new blocklist */
    908         fp = fopen( filename, "w+" );
    909         fwrite( response, 1, response_byte_count, fp );
    910         fclose( fp );
    911 
    912         /* feed it to the session */
    913         ruleCount = tr_blocklistSetContent( session, filename );
    914 
    915         /* give the client a response */
    916         tr_bencDictAddInt( data->args_out, "blocklist-size", ruleCount );
    917         tr_snprintf( result, sizeof( result ), "success" );
     902    else /* successfully fetched the blocklist... */
     903    {
     904        const char * configDir = tr_sessionGetConfigDir( session );
     905        char * filename = tr_buildPath( configDir, "blocklist.tmp", NULL );
     906        FILE * fp = fopen( filename, "w+" );
     907
     908        if( fp == NULL )
     909        {
     910            tr_snprintf( result, sizeof( result ),
     911                         _( "Couldn't save file \"%1$s\": %2$s" ),
     912                         filename, tr_strerror( errno ) );
     913        }
     914        else
     915        {
     916            const size_t n = fwrite( response, 1, response_byte_count, fp );
     917            fclose( fp );
     918
     919            if( n != response_byte_count )
     920            {
     921                tr_snprintf( result, sizeof( result ),
     922                             _( "Couldn't save file \"%1$s\": %2$s" ),
     923                             filename, tr_strerror( errno ) );
     924            }
     925            else
     926            {
     927                /* feed it to the session */
     928                const int ruleCount = tr_blocklistSetContent( session, filename );
     929
     930                /* give the client a response */
     931                tr_bencDictAddInt( data->args_out, "blocklist-size", ruleCount );
     932                tr_snprintf( result, sizeof( result ), "success" );
     933            }
     934
     935            /* cleanup */
     936            unlink( filename );
     937        }
    918938
    919939        /* cleanup */
    920         unlink( filename );
    921940        tr_free( filename );
    922941    }
Note: See TracChangeset for help on using the changeset viewer.