189
199
g_propagate_error (&async->saver->priv->error, error);
191
200
remote_save_completed_or_failed (async->saver, async);
205
* This fixes an issue in GOutputStream that applies the atomic replace
206
* save strategy. The stream moves the written file to the original file
207
* when the stream is closed. However, there is no way currently to tell
208
* the stream that the save should be aborted (there could be a
209
* conversion error). The patch explicitly closes the output stream
210
* in all these cases with a GCancellable in the cancelled state, causing
211
* the output stream to close, but not move the file. This makes use
212
* of an implementation detail in the local gio file stream and should be
213
* properly fixed by adding the appropriate API in gio. Until then, at least
214
* we prevent data corruption for now.
216
* Relevant bug reports:
218
* Bug 615110 - write file ignore encoding errors (gedit)
219
* https://bugzilla.gnome.org/show_bug.cgi?id=615110
221
* Bug 602412 - g_file_replace does not restore original file when there is
222
* errors while writing (glib/gio)
223
* https://bugzilla.gnome.org/show_bug.cgi?id=602412
226
cancel_output_stream_ready_cb (GOutputStream *stream,
227
GAsyncResult *result,
232
g_output_stream_close_finish (stream, result, NULL);
234
/* check cancelled state manually */
235
if (g_cancellable_is_cancelled (async->cancellable) || async->error == NULL)
237
async_data_free (async);
241
error = async->error;
244
async_failed (async, error);
248
cancel_output_stream (AsyncData *async)
250
GCancellable *cancellable;
252
gedit_debug_message (DEBUG_SAVER, "Cancel output stream");
254
cancellable = g_cancellable_new ();
255
g_cancellable_cancel (cancellable);
257
g_output_stream_close_async (async->saver->priv->stream,
260
(GAsyncReadyCallback)cancel_output_stream_ready_cb,
263
g_object_unref (cancellable);
267
cancel_output_stream_and_fail (AsyncData *async,
271
gedit_debug_message (DEBUG_SAVER, "Cancel output stream and fail");
273
g_propagate_error (&async->error, error);
274
cancel_output_stream (async);
195
282
remote_get_info_cb (GFile *source,
196
283
GAsyncResult *res,
283
370
async->cancellable, &error))
285
372
gedit_debug_message (DEBUG_SAVER, "Closing input stream error: %s", error->message);
286
async_failed (async, error);
373
cancel_output_stream_and_fail (async, error);