Commit 4569fdd3 authored by Ell's avatar Ell

app: explicitly close output stream when saving internal data

According to some bug reports, it seems that under some (unknown)
conditions we might save an empty custom gradient file on exit (for
equally unknown reasons).  The only difference in the way we save
internal data files, such as the custom gradient, compared to
gimp_data_save(), is the fact that we currently don't explicitly
close the output stream, but rather only unref it.

The output stream should be implicitly closed (and hence flushed)
upon destruction, but maybe the unreffing is not enough to
guarantee that it's actually destroyed (maybe it spawns an extra
reference for some reason, who knows.)  Anyway, let's just
explicitly close it, which also gives us a chance to catch and
report any errors occursing during flushing/closing (which,
altenatively, might be the culprit).

Additionally, a few more error-reporting improvements, to match
gimp_data_save().

(cherry picked from commit a72f7f1a)
parent 80efa4a7
......@@ -258,10 +258,12 @@ gimp_internal_data_save_data_file (Gimp *gimp,
G_FILE_CREATE_NONE,
NULL, error));
g_object_unref (file);
if (! output)
return FALSE;
{
g_object_unref (file);
return FALSE;
}
data = data_file->get_func (gimp);
......@@ -276,7 +278,31 @@ gimp_internal_data_save_data_file (Gimp *gimp,
gimp_assert (GIMP_DATA_GET_CLASS (data)->save);
success = GIMP_DATA_GET_CLASS (data)->save (data, output, error);
if (success)
{
if (! g_output_stream_close (output, NULL, error))
{
g_prefix_error (error,
_("Error saving '%s': "),
gimp_file_get_utf8_name (file));
success = FALSE;
}
}
else if (error && *error)
{
g_prefix_error (error,
_("Error saving '%s': "),
gimp_file_get_utf8_name (file));
}
else
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
_("Error saving '%s'"),
gimp_file_get_utf8_name (file));
}
g_object_unref (output);
g_object_unref (file);
return success;
}
......
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