Revision: 1346 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1346&view=re... Author: colombanw Date: 2010-05-11 00:46:46 +0000 (Tue, 11 May 2010)
Log Message: ----------- GeanyGenDoc: Make option saving more robust against corrupted conffile
Do not fail saving if the original file cannot be loaded, simply overwrite with the new settings. This fixes configuration saving when the configuration file does not exist or exists but is corrupted.
Modified Paths: -------------- trunk/geanygendoc/src/ggd-options.c
Modified: trunk/geanygendoc/src/ggd-options.c =================================================================== --- trunk/geanygendoc/src/ggd-options.c 2010-05-10 22:48:42 UTC (rev 1345) +++ trunk/geanygendoc/src/ggd-options.c 2010-05-11 00:46:46 UTC (rev 1346) @@ -602,20 +602,22 @@ { gboolean success = FALSE; GKeyFile *key_file; + gchar *data; + gsize data_length;
key_file = g_key_file_new (); - if (g_key_file_load_from_file (key_file, filename, - G_KEY_FILE_KEEP_COMMENTS | - G_KEY_FILE_KEEP_TRANSLATIONS, error)) { - gchar *data; - gsize data_length; - - ggd_opt_group_write_to_key_file (group, key_file); - data = g_key_file_to_data (key_file, &data_length, error); - if (data) { - if (g_file_set_contents (filename, data, data_length, error)) { - success = TRUE; - } + /* try to load the original file but blindly ignore errors because they are + * unlikely to be interesting (the file doesn't already exist, a syntax error + * because the file exists but is empty (yes, this throws a parse error), + * etc.) */ + g_key_file_load_from_file (key_file, filename, + G_KEY_FILE_KEEP_COMMENTS | + G_KEY_FILE_KEEP_TRANSLATIONS, NULL); + ggd_opt_group_write_to_key_file (group, key_file); + data = g_key_file_to_data (key_file, &data_length, error); + if (data) { + if (g_file_set_contents (filename, data, data_length, error)) { + success = TRUE; } } g_key_file_free (key_file);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.