Detect errors when flushing output

This commit is contained in:
Pierre Pronchery 2015-10-04 04:29:53 +02:00
parent 88637e65ff
commit 6d5bed89e7

View File

@ -465,7 +465,11 @@ static int _single_regular(Copy * copy, char const * src, char const * dst)
static gboolean _regular_channel(GIOChannel * source, GIOCondition condition, static gboolean _regular_channel(GIOChannel * source, GIOCondition condition,
gpointer data); gpointer data);
static gboolean _channel_in(Copy * copy, GIOChannel * source); static gboolean _channel_in(Copy * copy, GIOChannel * source);
static gboolean _channel_in_error(Copy * copy, GIOChannel * source,
GError * error);
static gboolean _channel_out(Copy * copy, GIOChannel * source); static gboolean _channel_out(Copy * copy, GIOChannel * source);
static gboolean _channel_out_error(Copy * copy, GIOChannel * source,
GError * error);
static void _out_rate(Copy * copy); static void _out_rate(Copy * copy);
static gboolean _regular_idle_in(gpointer data) static gboolean _regular_idle_in(gpointer data)
@ -502,16 +506,13 @@ static gboolean _channel_in(Copy * copy, GIOChannel * source)
status = g_io_channel_read_chars(source, &copy->buf[copy->buf_cnt], status = g_io_channel_read_chars(source, &copy->buf[copy->buf_cnt],
sizeof(copy->buf) - copy->buf_cnt, &read, &error); sizeof(copy->buf) - copy->buf_cnt, &read, &error);
if(status == G_IO_STATUS_ERROR) if(status == G_IO_STATUS_ERROR)
{ return _channel_in_error(copy, source, error);
_copy_filename_error(copy, copy->filev[copy->cur], 0);
g_io_channel_unref(source);
gtk_main_quit(); /* XXX ugly */
return FALSE;
}
else if(status == G_IO_STATUS_EOF) else if(status == G_IO_STATUS_EOF)
{ {
copy->eof = 1; /* reached end of input file */ copy->eof = 1; /* reached end of input file */
g_io_channel_close(source); if(g_io_channel_shutdown(source, TRUE, &error)
== G_IO_STATUS_ERROR)
return _channel_in_error(copy, source, error);
} }
else if(copy->buf_cnt + read != sizeof(copy->buf)) else if(copy->buf_cnt + read != sizeof(copy->buf))
g_idle_add(_regular_idle_in, copy); /* continue to read */ g_idle_add(_regular_idle_in, copy); /* continue to read */
@ -521,6 +522,16 @@ static gboolean _channel_in(Copy * copy, GIOChannel * source)
return FALSE; return FALSE;
} }
static gboolean _channel_in_error(Copy * copy, GIOChannel * source,
GError * error)
{
_copy_filename_error(copy, copy->filev[copy->cur], 0);
g_error_free(error);
g_io_channel_unref(source);
gtk_main_quit(); /* XXX ugly */
return FALSE;
}
static gboolean _channel_out(Copy * copy, GIOChannel * source) static gboolean _channel_out(Copy * copy, GIOChannel * source)
{ {
gsize written; gsize written;
@ -530,11 +541,7 @@ static gboolean _channel_out(Copy * copy, GIOChannel * source)
/* write data */ /* write data */
if(g_io_channel_write_chars(source, copy->buf, copy->buf_cnt, &written, if(g_io_channel_write_chars(source, copy->buf, copy->buf_cnt, &written,
&error) == G_IO_STATUS_ERROR) &error) == G_IO_STATUS_ERROR)
{ return _channel_out_error(copy, source, error);
_copy_filename_error(copy, copy->filev[copy->cur], 0);
gtk_main_quit(); /* XXX ugly */
return FALSE;
}
if(copy->buf_cnt == sizeof(copy->buf)) if(copy->buf_cnt == sizeof(copy->buf))
g_idle_add(_regular_idle_in, copy); /* read again */ g_idle_add(_regular_idle_in, copy); /* read again */
copy->buf_cnt -= written; copy->buf_cnt -= written;
@ -545,12 +552,23 @@ static gboolean _channel_out(Copy * copy, GIOChannel * source)
g_idle_add(_regular_idle_out, copy); /* continue to write */ g_idle_add(_regular_idle_out, copy); /* continue to write */
else if(copy->eof == 1) /* reached end of input */ else if(copy->eof == 1) /* reached end of input */
{ {
g_io_channel_close(copy->out_channel); if(g_io_channel_shutdown(copy->out_channel, TRUE, &error)
== G_IO_STATUS_ERROR)
return _channel_out_error(copy, source, error);
gtk_main_quit(); /* XXX ugly */ gtk_main_quit(); /* XXX ugly */
} }
return FALSE; return FALSE;
} }
static gboolean _channel_out_error(Copy * copy, GIOChannel * source,
GError * error)
{
_copy_filename_error(copy, copy->filev[copy->cur], 0);
g_error_free(error);
gtk_main_quit(); /* XXX ugly */
return FALSE;
}
static void _out_rate(Copy * copy) static void _out_rate(Copy * copy)
{ {
gdouble fraction; gdouble fraction;