mirror of
https://github.com/transmission/transmission
synced 2025-03-10 14:13:23 +00:00
(trunk libT) fix #2332: filesystem-based error messages lack context
This commit is contained in:
parent
d08d53d8ed
commit
11717de1d0
6 changed files with 57 additions and 46 deletions
|
@ -155,11 +155,11 @@ tr_ioFindFileLocation( const tr_torrent * tor,
|
|||
|
||||
/* returns 0 on success, or an errno on failure */
|
||||
static int
|
||||
readOrWritePiece( const tr_torrent * tor,
|
||||
readOrWritePiece( tr_torrent * tor,
|
||||
int ioMode,
|
||||
tr_piece_index_t pieceIndex,
|
||||
uint32_t pieceOffset,
|
||||
uint8_t * buf,
|
||||
uint8_t * buf,
|
||||
size_t buflen )
|
||||
{
|
||||
int err = 0;
|
||||
|
@ -185,27 +185,33 @@ readOrWritePiece( const tr_torrent * tor,
|
|||
buflen -= bytesThisPass;
|
||||
++fileIndex;
|
||||
fileOffset = 0;
|
||||
|
||||
if( err ) {
|
||||
char * path = tr_buildPath( tor->downloadDir, file->name, NULL );
|
||||
tr_torrentSetLocalError( tor, "%s (%s)", tr_strerror( err ), path );
|
||||
tr_free( path );
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int
|
||||
tr_ioRead( const tr_torrent * tor,
|
||||
tr_ioRead( tr_torrent * tor,
|
||||
tr_piece_index_t pieceIndex,
|
||||
uint32_t begin,
|
||||
uint32_t len,
|
||||
uint8_t * buf )
|
||||
uint8_t * buf )
|
||||
{
|
||||
return readOrWritePiece( tor, TR_IO_READ, pieceIndex, begin, buf, len );
|
||||
}
|
||||
|
||||
int
|
||||
tr_ioWrite( const tr_torrent * tor,
|
||||
tr_ioWrite( tr_torrent * tor,
|
||||
tr_piece_index_t pieceIndex,
|
||||
uint32_t begin,
|
||||
uint32_t len,
|
||||
const uint8_t * buf )
|
||||
const uint8_t * buf )
|
||||
{
|
||||
return readOrWritePiece( tor, TR_IO_WRITE, pieceIndex, begin,
|
||||
(uint8_t*)buf,
|
||||
|
@ -217,11 +223,11 @@ tr_ioWrite( const tr_torrent * tor,
|
|||
****/
|
||||
|
||||
static tr_bool
|
||||
recalculateHash( const tr_torrent * tor,
|
||||
recalculateHash( tr_torrent * tor,
|
||||
tr_piece_index_t pieceIndex,
|
||||
void * buffer,
|
||||
size_t buflen,
|
||||
uint8_t * setme )
|
||||
uint8_t * setme )
|
||||
{
|
||||
size_t bytesLeft;
|
||||
uint32_t offset = 0;
|
||||
|
@ -263,7 +269,7 @@ recalculateHash( const tr_torrent * tor,
|
|||
}
|
||||
|
||||
tr_bool
|
||||
tr_ioTestPiece( const tr_torrent * tor,
|
||||
tr_ioTestPiece( tr_torrent * tor,
|
||||
tr_piece_index_t pieceIndex,
|
||||
void * buffer,
|
||||
size_t buflen )
|
||||
|
|
|
@ -28,21 +28,21 @@ struct tr_torrent;
|
|||
* Reads the block specified by the piece index, offset, and length.
|
||||
* @return 0 on success, or an errno value on failure.
|
||||
*/
|
||||
int tr_ioRead( const struct tr_torrent * tor,
|
||||
tr_piece_index_t pieceIndex,
|
||||
uint32_t offset,
|
||||
uint32_t len,
|
||||
uint8_t * setme );
|
||||
int tr_ioRead( struct tr_torrent * tor,
|
||||
tr_piece_index_t pieceIndex,
|
||||
uint32_t offset,
|
||||
uint32_t len,
|
||||
uint8_t * setme );
|
||||
|
||||
/**
|
||||
* Writes the block specified by the piece index, offset, and length.
|
||||
* @return 0 on success, or an errno value on failure.
|
||||
*/
|
||||
int tr_ioWrite( const struct tr_torrent * tor,
|
||||
tr_piece_index_t pieceIndex,
|
||||
uint32_t offset,
|
||||
uint32_t len,
|
||||
const uint8_t * writeme );
|
||||
int tr_ioWrite( struct tr_torrent * tor,
|
||||
tr_piece_index_t pieceIndex,
|
||||
uint32_t offset,
|
||||
uint32_t len,
|
||||
const uint8_t * writeme );
|
||||
|
||||
/**
|
||||
* @brief Test to see if the piece matches its metainfo's SHA1 checksum.
|
||||
|
@ -51,7 +51,7 @@ int tr_ioWrite( const struct tr_torrent * tor,
|
|||
* get best performance by providing a buffer with
|
||||
* tor->info.pieceSize bytes.
|
||||
*/
|
||||
tr_bool tr_ioTestPiece( const tr_torrent * tor,
|
||||
tr_bool tr_ioTestPiece( tr_torrent * tor,
|
||||
tr_piece_index_t piece,
|
||||
void * optionalBuffer,
|
||||
size_t optionalBufferLen );
|
||||
|
|
|
@ -1164,27 +1164,16 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt )
|
|||
}
|
||||
|
||||
case TR_PEER_ERROR:
|
||||
if( e->err == EINVAL )
|
||||
{
|
||||
addStrike( t, peer );
|
||||
peer->doPurge = 1;
|
||||
tordbg( t, "setting %s doPurge flag because we got an EINVAL error", tr_peerIoAddrStr( &peer->addr, peer->port ) );
|
||||
}
|
||||
else if( ( e->err == ERANGE )
|
||||
|| ( e->err == EMSGSIZE )
|
||||
|| ( e->err == ENOTCONN ) )
|
||||
if( ( e->err == ERANGE ) || ( e->err == EMSGSIZE ) || ( e->err == ENOTCONN ) )
|
||||
{
|
||||
/* some protocol error from the peer */
|
||||
peer->doPurge = 1;
|
||||
tordbg( t, "setting %s doPurge flag because we got an ERANGE, EMSGSIZE, or ENOTCONN error", tr_peerIoAddrStr( &peer->addr, peer->port ) );
|
||||
tordbg( t, "setting %s doPurge flag because we got an ERANGE, EMSGSIZE, or ENOTCONN error",
|
||||
tr_peerIoAddrStr( &peer->addr, peer->port ) );
|
||||
}
|
||||
else /* a local error, such as an IO error */
|
||||
else
|
||||
{
|
||||
t->tor->error = TR_STAT_LOCAL_ERROR;
|
||||
tr_strlcpy( t->tor->errorString,
|
||||
tr_strerror( e->err ),
|
||||
sizeof( t->tor->errorString ) );
|
||||
tr_torrentStop( t->tor );
|
||||
tordbg( t, "unhandled error: %s", tr_strerror( e->err ) );
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -2615,6 +2604,12 @@ bandwidthPulse( void * vmgr )
|
|||
}
|
||||
}
|
||||
|
||||
/* possibly stop torrents that have an error */
|
||||
tor = NULL;
|
||||
while(( tor = tr_torrentNext( mgr->session, tor )))
|
||||
if( tor->isRunning && (( tor->error == TR_STAT_TRACKER_ERROR ) || ( tor->error == TR_STAT_LOCAL_ERROR )))
|
||||
tr_torrentStop( tor );
|
||||
|
||||
managerUnlock( mgr );
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -1347,12 +1347,7 @@ readBtPiece( tr_peermsgs * msgs,
|
|||
msgs->incoming.block = evbuffer_new( );
|
||||
req->length = 0;
|
||||
msgs->state = AWAITING_BT_LENGTH;
|
||||
if( !err )
|
||||
return READ_NOW;
|
||||
else {
|
||||
fireError( msgs, err );
|
||||
return READ_ERR;
|
||||
}
|
||||
return err ? READ_ERR : READ_NOW;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1764,7 +1759,6 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now )
|
|||
|
||||
if( err )
|
||||
{
|
||||
fireError( msgs, err );
|
||||
bytesWritten = 0;
|
||||
msgs = NULL;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <assert.h>
|
||||
#include <limits.h> /* INT_MAX */
|
||||
#include <math.h> /* fabs */
|
||||
#include <stdarg.h>
|
||||
#include <string.h> /* memcmp */
|
||||
#include <stdlib.h> /* qsort */
|
||||
|
||||
|
@ -262,10 +263,23 @@ tr_torrentGetSeedRatio( const tr_torrent * tor, double * ratio )
|
|||
****
|
||||
***/
|
||||
|
||||
void
|
||||
tr_torrentSetLocalError( tr_torrent * tor, const char * fmt, ... )
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
assert( tr_isTorrent( tor ) );
|
||||
|
||||
va_start( ap, fmt );
|
||||
tor->error = TR_STAT_LOCAL_ERROR;
|
||||
evutil_vsnprintf( tor->errorString, sizeof( tor->errorString ), fmt, ap );
|
||||
va_end( ap );
|
||||
}
|
||||
|
||||
static void
|
||||
onTrackerResponse( void * tracker UNUSED,
|
||||
void * vevent,
|
||||
void * user_data )
|
||||
void * vevent,
|
||||
void * user_data )
|
||||
{
|
||||
tr_torrent * tor = user_data;
|
||||
tr_tracker_event * event = vevent;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "completion.h" /* tr_completion */
|
||||
#include "ratecontrol.h" /* tr_ratecontrol */
|
||||
#include "session.h" /* tr_globalLock(), tr_globalUnlock() */
|
||||
#include "utils.h" /* tr_bitfield */
|
||||
#include "utils.h" /* TR_GNUC_PRINTF */
|
||||
|
||||
struct tr_bandwidth;
|
||||
struct tr_ratecontrol;
|
||||
|
@ -121,6 +121,8 @@ void tr_torrentCheckSeedRatio( tr_torrent * tor );
|
|||
/** save a torrent's .resume file if it's changed since the last time it was saved */
|
||||
void tr_torrentSave( tr_torrent * tor );
|
||||
|
||||
void tr_torrentSetLocalError( tr_torrent * tor, const char * fmt, ... ) TR_GNUC_PRINTF( 2, 3 );
|
||||
|
||||
|
||||
|
||||
typedef enum
|
||||
|
|
Loading…
Add table
Reference in a new issue