Changeset 10495


Ignore:
Timestamp:
Apr 19, 2010, 4:18:12 PM (11 years ago)
Author:
charles
Message:

(trunk libT) #3154 "crash when saving a blocklist to disk when the disk is full" -- fixed in trunk for 2.00

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/rpcimpl.c

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