diff options
author | Alexander Larsson <alexl@src.gnome.org> | 2007-09-13 14:55:35 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2007-09-13 14:55:35 +0000 |
commit | d8fb06582e9574ebb5fb668a4ef93f797f384314 (patch) | |
tree | f4b70992a0d215f2ef51b10cabeb53cede1bcaab | |
parent | 784bbba3f9c77b5053d25cb9fd62cf855299bd25 (diff) | |
download | gvfs-d8fb06582e9574ebb5fb668a4ef93f797f384314.tar.gz |
Use g_cancellable_set_error_if_cancelled
Original git commit by Alexander Larsson <alexl@redhat.com> at 1188212811 +0200
svn path=/trunk/; revision=809
-rw-r--r-- | client/gdaemonfileinputstream.c | 20 | ||||
-rw-r--r-- | client/gdaemonfileoutputstream.c | 20 | ||||
-rw-r--r-- | client/gvfsdaemondbus.c | 26 | ||||
-rw-r--r-- | gio/gfile.c | 180 | ||||
-rw-r--r-- | gio/gfileenumerator.c | 24 | ||||
-rw-r--r-- | gio/glocalfileinputstream.c | 30 | ||||
-rw-r--r-- | gio/glocalfileoutputstream.c | 91 | ||||
-rw-r--r-- | gio/gsimpleasyncresult.c | 7 | ||||
-rw-r--r-- | gio/gsocketinputstream.c | 16 | ||||
-rw-r--r-- | gio/gsocketoutputstream.c | 16 |
10 files changed, 86 insertions, 344 deletions
diff --git a/client/gdaemonfileinputstream.c b/client/gdaemonfileinputstream.c index dd7d4624..f284fccf 100644 --- a/client/gdaemonfileinputstream.c +++ b/client/gdaemonfileinputstream.c @@ -665,14 +665,8 @@ g_daemon_file_input_stream_read (GInputStream *stream, file = G_DAEMON_FILE_INPUT_STREAM (stream); - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return -1; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return -1; /* Limit for sanity and to avoid 32bit overflow */ if (count > MAX_READ_SIZE) @@ -1167,14 +1161,8 @@ g_daemon_file_input_stream_seek (GFileInputStream *stream, return FALSE; } - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; memset (&op, 0, sizeof (op)); op.state = SEEK_STATE_INIT; diff --git a/client/gdaemonfileoutputstream.c b/client/gdaemonfileoutputstream.c index 1412a6a1..288616dc 100644 --- a/client/gdaemonfileoutputstream.c +++ b/client/gdaemonfileoutputstream.c @@ -560,14 +560,8 @@ g_daemon_file_output_stream_write (GOutputStream *stream, file = G_DAEMON_FILE_OUTPUT_STREAM (stream); - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return -1; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return -1; /* Limit for sanity and to avoid 32bit overflow */ if (count > MAX_WRITE_SIZE) @@ -927,14 +921,8 @@ g_daemon_file_output_stream_seek (GFileOutputStream *stream, return FALSE; } - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; memset (&op, 0, sizeof (op)); op.state = SEEK_STATE_INIT; diff --git a/client/gvfsdaemondbus.c b/client/gvfsdaemondbus.c index 50b32086..0b58807a 100644 --- a/client/gvfsdaemondbus.c +++ b/client/gvfsdaemondbus.c @@ -541,12 +541,8 @@ async_get_connection_response (DBusMessage *reply, /* Maybe we were canceled while setting up connection, then * avoid doing the operation */ - if (g_cancellable_is_cancelled (async_call->cancellable)) + if (g_cancellable_set_error_if_cancelled (async_call->cancellable, &async_call->io_error)) { - g_set_error (&async_call->io_error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); async_call_finish (async_call, NULL); return; } @@ -626,14 +622,8 @@ _g_vfs_daemon_call_sync (DBusMessage *message, gboolean handle_callbacks; const char *dbus_id = dbus_message_get_destination (message); - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; connection = _g_dbus_connection_get_sync (dbus_id, error); if (connection == NULL) @@ -642,14 +632,8 @@ _g_vfs_daemon_call_sync (DBusMessage *message, /* TODO: Handle errors below due to unmount and invalidate the sync connection cache */ - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; handle_callbacks = FALSE; if (callback_obj_path != NULL && callback != NULL) diff --git a/gio/gfile.c b/gio/gfile.c index 9a9ec123..f96e5644 100644 --- a/gio/gfile.c +++ b/gio/gfile.c @@ -244,14 +244,8 @@ g_file_enumerate_children (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; iface = G_FILE_GET_IFACE (file); @@ -268,14 +262,8 @@ g_file_get_info (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; iface = G_FILE_GET_IFACE (file); @@ -290,14 +278,8 @@ g_file_get_filesystem_info (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; iface = G_FILE_GET_IFACE (file); @@ -312,14 +294,8 @@ g_file_read (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; iface = G_FILE_GET_IFACE (file); @@ -333,14 +309,8 @@ g_file_append_to (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; iface = G_FILE_GET_IFACE (file); @@ -354,14 +324,8 @@ g_file_create (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; iface = G_FILE_GET_IFACE (file); @@ -377,14 +341,8 @@ g_file_replace (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; iface = G_FILE_GET_IFACE (file); @@ -946,14 +904,8 @@ g_file_copy (GFile *source, GError *my_error; gboolean res; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; if (G_OBJECT_TYPE (source) == G_OBJECT_TYPE (destination)) { @@ -1007,14 +959,8 @@ g_file_move (GFile *source, GError *my_error; gboolean res; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; if (G_OBJECT_TYPE (source) == G_OBJECT_TYPE (destination)) { @@ -1052,14 +998,8 @@ g_file_make_directory (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; iface = G_FILE_GET_IFACE (file); @@ -1074,14 +1014,8 @@ g_file_make_symbolic_link (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; iface = G_FILE_GET_IFACE (file); @@ -1095,14 +1029,8 @@ g_file_delete (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; iface = G_FILE_GET_IFACE (file); @@ -1116,14 +1044,8 @@ g_file_trash (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; iface = G_FILE_GET_IFACE (file); @@ -1155,14 +1077,8 @@ g_file_set_display_name (GFile *file, return FALSE; } - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; iface = G_FILE_GET_IFACE (file); @@ -1183,14 +1099,8 @@ g_file_query_settable_attributes (GFile *file, GError *my_error; GFileAttributeInfoList *list; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; iface = G_FILE_GET_IFACE (file); @@ -1225,14 +1135,8 @@ g_file_query_writable_namespaces (GFile *file, GError *my_error; GFileAttributeInfoList *list; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; iface = G_FILE_GET_IFACE (file); @@ -1266,14 +1170,8 @@ g_file_set_attribute (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; iface = G_FILE_GET_IFACE (file); @@ -1295,14 +1193,8 @@ g_file_set_attributes_from_info (GFile *file, { GFileIface *iface; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; g_file_info_clear_status (info); diff --git a/gio/gfileenumerator.c b/gio/gfileenumerator.c index f99d18ec..fb8f64c1 100644 --- a/gio/gfileenumerator.c +++ b/gio/gfileenumerator.c @@ -479,18 +479,10 @@ next_op_func (GIOJob *job, for (i = 0; i < op->num_files; i++) { - if (g_cancellable_is_cancelled (cancellable)) - { - info = NULL; - g_set_error (&op->op.error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - } + if (g_cancellable_set_error_if_cancelled (cancellable, &op->op.error)) + info = NULL; else - { - info = class->next_file (op->op.enumerator, cancellable, &op->op.error); - } + info = class->next_file (op->op.enumerator, cancellable, &op->op.error); if (info == NULL) { @@ -568,14 +560,8 @@ stop_op_func (GIOJob *job, StopAsyncOp *op = data; GFileEnumeratorClass *class; - if (g_cancellable_is_cancelled (cancellable)) - { - op->result = FALSE; - g_set_error (&op->op.error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - } + if (g_cancellable_set_error_if_cancelled (cancellable, &op->op.error)) + op->result = FALSE; else { class = G_FILE_ENUMERATOR_GET_CLASS (op->op.enumerator); diff --git a/gio/glocalfileinputstream.c b/gio/glocalfileinputstream.c index b4026bba..3bf8af42 100644 --- a/gio/glocalfileinputstream.c +++ b/gio/glocalfileinputstream.c @@ -109,14 +109,8 @@ g_local_file_input_stream_read (GInputStream *stream, res = -1; while (1) { - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - break; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + break; res = read (file->priv->fd, buffer, count); if (res == -1) { @@ -146,14 +140,8 @@ g_local_file_input_stream_skip (GInputStream *stream, file = G_LOCAL_FILE_INPUT_STREAM (stream); - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return -1; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return -1; start = lseek (file->priv->fd, 0, SEEK_CUR); if (start == -1) @@ -294,14 +282,8 @@ g_local_file_input_stream_get_file_info (GFileInputStream *stream, file = G_LOCAL_FILE_INPUT_STREAM (stream); - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; return _g_local_file_info_get_from_fd (file->priv->fd, attributes, diff --git a/gio/glocalfileoutputstream.c b/gio/glocalfileoutputstream.c index 55dc4871..07c54887 100644 --- a/gio/glocalfileoutputstream.c +++ b/gio/glocalfileoutputstream.c @@ -118,14 +118,8 @@ g_local_file_output_stream_write (GOutputStream *stream, while (1) { - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return -1; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return -1; res = write (file->priv->fd, buffer, count); if (res == -1) { @@ -163,14 +157,8 @@ g_local_file_output_stream_close (GOutputStream *stream, if (file->priv->backup_filename) { - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - goto err_out; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + goto err_out; #ifdef HAVE_LINK /* create original -> backup link, the original is then renamed over */ @@ -205,14 +193,8 @@ g_local_file_output_stream_close (GOutputStream *stream, } - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - goto err_out; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + goto err_out; /* tmp -> original */ if (rename (file->priv->tmp_filename, file->priv->original_filename) != 0) @@ -225,14 +207,8 @@ g_local_file_output_stream_close (GOutputStream *stream, } } - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - goto err_out; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + goto err_out; if (fstat (file->priv->fd, &final_stat) == 0) file->priv->etag = _g_local_file_info_create_etag (&final_stat); @@ -371,14 +347,8 @@ g_local_file_output_stream_truncate (GFileOutputStream *stream, { if (errno == EINTR) { - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return FALSE; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; goto restart; } @@ -403,14 +373,8 @@ g_local_file_output_stream_get_file_info (GFileOutputStream *stream, file = G_LOCAL_FILE_OUTPUT_STREAM (stream); - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; return _g_local_file_info_get_from_fd (file->priv->fd, attributes, @@ -425,14 +389,8 @@ g_local_file_output_stream_create (const char *filename, GLocalFileOutputStream *stream; int fd; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; fd = g_open (filename, O_CREAT | O_EXCL | O_WRONLY, @@ -467,14 +425,8 @@ g_local_file_output_stream_append (const char *filename, GLocalFileOutputStream *stream; int fd; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; fd = g_open (filename, O_CREAT | O_APPEND | O_WRONLY, @@ -842,15 +794,8 @@ g_local_file_output_stream_replace (const char *filename, int fd; char *temp_file; - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - return NULL; - } - + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; temp_file = NULL; /* If the file doesn't exist, create it */ diff --git a/gio/gsimpleasyncresult.c b/gio/gsimpleasyncresult.c index e338c0a0..d99579c4 100644 --- a/gio/gsimpleasyncresult.c +++ b/gio/gsimpleasyncresult.c @@ -322,12 +322,9 @@ run_in_thread (GIOJob *job, GSimpleAsyncResult *simple = data->simple; if (simple->handle_cancellation && - g_cancellable_is_cancelled (c)) + g_cancellable_set_error_if_cancelled (c, simple)) { - g_simple_async_result_set_error (simple, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); + /* PASS */ } else { diff --git a/gio/gsocketinputstream.c b/gio/gsocketinputstream.c index 305864ea..5b738d3a 100644 --- a/gio/gsocketinputstream.c +++ b/gio/gsocketinputstream.c @@ -157,14 +157,8 @@ g_socket_input_stream_read (GInputStream *stream, while (1) { - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - break; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + break; res = read (socket_stream->priv->fd, buffer, count); if (res == -1) { @@ -234,12 +228,8 @@ read_async_cb (ReadAsyncData *data, /* We know that we can read from fd once without blocking */ while (1) { - if (g_cancellable_is_cancelled (data->cancellable)) + if (g_cancellable_set_error_if_cancelled (data->cancellable, &error)) { - g_set_error (&error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); count_read = -1; break; } diff --git a/gio/gsocketoutputstream.c b/gio/gsocketoutputstream.c index 40934cff..c0394078 100644 --- a/gio/gsocketoutputstream.c +++ b/gio/gsocketoutputstream.c @@ -144,14 +144,8 @@ g_socket_output_stream_write (GOutputStream *stream, while (1) { - if (g_cancellable_is_cancelled (cancellable)) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); - break; - } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + break; res = write (socket_stream->priv->fd, buffer, count); if (res == -1) { @@ -220,12 +214,8 @@ write_async_cb (WriteAsyncData *data, while (1) { - if (g_cancellable_is_cancelled (data->cancellable)) + if (g_cancellable_set_error_if_cancelled (data->cancellable, &error)) { - g_set_error (&error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - _("Operation was cancelled")); count_written = -1; break; } |