/pidgin/main: 0160b6fea88e: MXit: If a file read/write error occ...

Andrew Victor andrew.victor at mxit.com
Mon Apr 1 06:33:51 EDT 2013


Changeset: 0160b6fea88ec8fee17d5314fb1e691964b6d5cf
Author:	 Andrew Victor <andrew.victor at mxit.com>
Date:	 2013-04-01 12:25 +0200
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/0160b6fea88e

Description:

MXit: If a file read/write error occurs during a file-transfer, then report it to the user and cancel the transfer.
Otherwise it may incorrectly look like it succeeded.

diffstat:

 libpurple/protocols/mxit/filexfer.c |  37 ++++++++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 13 deletions(-)

diffs (63 lines):

diff --git a/libpurple/protocols/mxit/filexfer.c b/libpurple/protocols/mxit/filexfer.c
--- a/libpurple/protocols/mxit/filexfer.c
+++ b/libpurple/protocols/mxit/filexfer.c
@@ -153,7 +153,6 @@ static void mxit_xfer_start( PurpleXfer*
 {
 	goffset			filesize;
 	unsigned char*	buffer;
-	int				size;
 	int				wrote;
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_xfer_start\n" );
@@ -166,12 +165,18 @@ static void mxit_xfer_start( PurpleXfer*
 		 */
 		filesize = purple_xfer_get_bytes_remaining( xfer );
 		buffer = g_malloc( filesize );
-		size = fread( buffer, filesize, 1, xfer->dest_fp );
-		// TODO: If (size != 1) -> file read error
 
-		wrote = purple_xfer_write( xfer, buffer, filesize );
-		if ( wrote > 0 )
-			purple_xfer_set_bytes_sent( xfer, wrote );
+		if ( fread( buffer, filesize, 1, xfer->dest_fp ) > 0 ) {
+			/* send data */
+			wrote = purple_xfer_write( xfer, buffer, filesize );
+			if ( wrote > 0 )
+				purple_xfer_set_bytes_sent( xfer, wrote );
+		}
+		else {
+			/* file read error */
+			purple_xfer_error( purple_xfer_get_type( xfer ), purple_xfer_get_account( xfer ), purple_xfer_get_remote_user( xfer ), _( "Unable to access the local file" ) );
+			purple_xfer_cancel_local( xfer );
+		}
 
 		/* free the buffer */
 		g_free( buffer );
@@ -436,14 +441,20 @@ void mxit_xfer_rx_file( struct MXitSessi
 		/* this is the transfer we have been looking for */
 		purple_xfer_ref( xfer );
 		purple_xfer_start( xfer, -1, NULL, 0 );
-		fwrite( data, datalen, 1, xfer->dest_fp );
-		// TODO: Handle error from fwrite()
-		purple_xfer_unref( xfer );
-		purple_xfer_set_completed( xfer, TRUE );
-		purple_xfer_end( xfer );
 
-		/* inform MXit that file was successfully received */
-		mxit_send_file_received( session, fileid, RECV_STATUS_SUCCESS );
+		if ( fwrite( data, datalen, 1, xfer->dest_fp ) > 0 ) {
+			purple_xfer_unref( xfer );
+			purple_xfer_set_completed( xfer, TRUE );
+			purple_xfer_end( xfer );
+
+			/* inform MXit that file was successfully received */
+			mxit_send_file_received( session, fileid, RECV_STATUS_SUCCESS );
+		}
+		else {
+			/* file write error */
+			purple_xfer_error( purple_xfer_get_type( xfer ), purple_xfer_get_account( xfer ), purple_xfer_get_remote_user( xfer ), _( "Unable to save the file" ) );
+			purple_xfer_cancel_local( xfer );
+		}
 	}
 	else {
 		/* file transfer not found */



More information about the Commits mailing list