Commit 849481a8 authored by Michael Natterer's avatar Michael Natterer 😴

Clean up code around calls to g_file_replace()

- use G_FILE_CREATE_NONE instead of 0
- don't put "Could not open <file> for writing: <error>" around the
  returned error, the returned message is already verbose
parent 98c184f0
......@@ -132,8 +132,7 @@ gimp_tags_user_install (void)
NULL, &error));
if (! output)
{
g_printerr (_("Could not open '%s' for writing: %s"),
gimp_file_get_utf8_name (file), error->message);
g_printerr ("%s\n", error->message);
result = FALSE;
}
else if (! g_output_stream_write_all (output,
......
......@@ -554,12 +554,6 @@ gimp_data_save (GimpData *data,
g_object_unref (output);
}
else
{
g_prefix_error (error,
_("Could not open '%s' for writing: "),
gimp_file_get_utf8_name (private->file));
}
}
if (success)
......
......@@ -137,15 +137,9 @@ gimp_gradient_save_pov (GimpGradient *gradient,
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, &my_error));
NULL, error));
if (! output)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"),
gimp_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
return FALSE;
}
return FALSE;
string = g_string_new ("/* color_map file created by GIMP */\n"
"/* http://www.gimp.org/ */\n"
......
......@@ -433,14 +433,13 @@ gimp_tag_cache_save (GimpTagCache *cache)
NULL, &error));
if (! output)
{
g_printerr (_("Could not open '%s' for writing: %s"),
gimp_file_get_utf8_name (file), error->message);
g_printerr ("%s\n", error->message);
}
else if (! g_output_stream_write_all (output, buf->str, buf->len,
NULL, NULL, &error) ||
! g_output_stream_close (output, NULL, &error))
{
g_printerr (_("Error writing '%s': %s"),
g_printerr (_("Error writing '%s': %s\n"),
gimp_file_get_utf8_name (file), error->message);
}
......
......@@ -271,9 +271,7 @@ themes_apply_theme (Gimp *gimp,
NULL, &error));
if (! output)
{
gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR,
_("Could not open '%s' for writing: %s"),
gimp_file_get_utf8_name (themerc), error->message);
gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
g_clear_error (&error);
}
else
......
......@@ -219,12 +219,10 @@ gimp_image_map_tool_settings_export (GimpSettingsBox *box,
NULL, &error));
if (! output)
{
gimp_message (GIMP_TOOL (tool)->tool_info->gimp,
G_OBJECT (gimp_tool_gui_get_dialog (tool->gui)),
GIMP_MESSAGE_ERROR,
_("Could not open '%s' for writing: %s"),
gimp_file_get_utf8_name (file),
error->message);
gimp_message_literal (GIMP_TOOL (tool)->tool_info->gimp,
G_OBJECT (gimp_tool_gui_get_dialog (tool->gui)),
GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
return FALSE;
}
......
......@@ -74,16 +74,9 @@ gimp_vectors_export_file (const GimpImage *image,
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, &my_error));
NULL, error));
if (! output)
{
g_set_error (error, my_error->domain, my_error->code,
_("Could not open '%s' for writing: %s"),
gimp_file_get_utf8_name (file),
my_error->message);
g_clear_error (&my_error);
return FALSE;
}
return FALSE;
string = gimp_vectors_export (image, vectors);
......
......@@ -1486,15 +1486,9 @@ gimp_text_buffer_save (GimpTextBuffer *buffer,
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, &my_error));
NULL, error));
if (! output)
{
g_set_error (error, my_error->domain, my_error->code,
_("Could not open '%s' for writing: %s"),
gimp_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
return FALSE;
}
return FALSE;
if (selection_only)
gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer),
......
......@@ -382,8 +382,9 @@ xcf_save_invoker (GimpProcedure *procedure,
#endif
filename = g_file_get_parse_name (file);
info.output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL,
&my_error));
info.output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, &my_error));
if (info.output)
{
......@@ -420,12 +421,6 @@ xcf_save_invoker (GimpProcedure *procedure,
if (progress)
gimp_progress_end (progress);
}
else
{
g_propagate_prefixed_error (error, my_error,
_("Could not open '%s' for writing: "),
filename);
}
g_free (filename);
g_object_unref (file);
......
......@@ -170,37 +170,30 @@ gimp_config_writer_new_gfile (GFile *file,
{
GimpConfigWriter *writer;
GOutputStream *output;
GError *my_error = NULL;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (atomic)
{
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE,
G_FILE_CREATE_NONE,
NULL, &my_error));
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, error));
if (! output)
g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
_("Could not create temporary file for '%s': %s"),
gimp_file_get_utf8_name (file), my_error->message);
g_prefix_error (error,
_("Could not create temporary file for '%s': "),
gimp_file_get_utf8_name (file));
}
else
{
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE,
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE,
G_FILE_CREATE_REPLACE_DESTINATION,
NULL, &my_error));
if (! output)
g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
_("Could not open '%s' for writing: %s"),
gimp_file_get_utf8_name (file), my_error->message);
NULL, error));
}
if (! output)
{
g_clear_error (&my_error);
return NULL;
}
return NULL;
writer = g_slice_new0 (GimpConfigWriter);
......
......@@ -445,7 +445,9 @@ save_image (GFile *file,
gint x, y, pad, n_bytes, bpp;
gint drawable_bpp;
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, error));
if (output)
{
GOutputStream *buffered;
......
......@@ -673,7 +673,9 @@ save_image (GFile *file,
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, error));
if (! output)
return FALSE;
......
......@@ -1292,7 +1292,9 @@ gih_save_image (GFile *file,
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, error));
if (! output)
return FALSE;
......
......@@ -517,7 +517,9 @@ save_image (GFile *file,
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, error));
if (! output)
return FALSE;
......
......@@ -536,7 +536,9 @@ save_image (GFile *file,
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, error));
if (! output)
return FALSE;
......
......@@ -1046,7 +1046,9 @@ save_image (GFile *file,
g_file_get_parse_name (file));
/* open the file */
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, error));
if (! output)
return FALSE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment