(trunk libT) possible fix for benc/json saving issues reported in 1.70. This is a guess from rb07's post in the forums about bencode.c, and from John Clay's comments in irc

This commit is contained in:
Charles Kerr 2009-06-06 19:30:32 +00:00
parent d0ae679a2f
commit 38a032b1bf
1 changed files with 8 additions and 13 deletions

View File

@ -1544,22 +1544,17 @@ tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
} }
else else
{ {
struct evbuffer * buf = evbuffer_new( ); int len;
tr_bencToBuf( top, mode, buf ); char * str = tr_bencToStr( top, mode, &len );
while( !err && EVBUFFER_LENGTH( buf ) ) if( fwrite( str, 1, len, fp ) == (size_t)len )
{ tr_dbg( "tr_bencToFile saved \"%s\"", filename );
if( evbuffer_write( buf, fileno(fp) ) == -1 ) else {
{ err = errno;
err = errno; tr_err( _( "Couldn't save file \"%1$s\": %2$s" ), filename, tr_strerror( errno ) );
tr_err( _( "Couldn't save file \"%1$s\": %2$s" ),
filename, tr_strerror( errno ) );
}
} }
if( !err ) tr_free( str );
tr_dbg( "tr_bencToFile saved \"%s\"", filename );
evbuffer_free( buf );
fclose( fp ); fclose( fp );
} }