2008-05-18 [colin] 3.4.0cvs51
[claws.git] / src / common / plugin.c
index ae72652433429d1ab839e14a6b1eada79dbc80c8..b1983c125dfae81c78391ce0c43dcbfbd0719240 100644 (file)
@@ -33,6 +33,8 @@
 #include "plugin.h"
 #include "prefs.h"
 #include "claws.h"
+#include "timing.h"
+
 #ifdef HAVE_VALGRIND
 #include "valgrind.h"
 #endif
@@ -99,7 +101,7 @@ void plugin_save_list(void)
        PrefFile *pfile;
        GSList *type_cur, *plugin_cur;
        Plugin *plugin;
-
+       
        for (type_cur = plugin_types; type_cur != NULL; type_cur = g_slist_next(type_cur)) {
                rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
 #ifdef G_OS_WIN32
@@ -122,7 +124,8 @@ void plugin_save_list(void)
                                continue;
 
                        if (!strcmp(plugin->type(), type_cur->data))
-                               fprintf(pfile->fp, "%s\n", plugin->filename);
+                               if (fprintf(pfile->fp, "%s\n", plugin->filename) < 0)
+                                       goto revert;
                }
                for (plugin_cur = unloaded_plugins; plugin_cur != NULL; plugin_cur = g_slist_next(plugin_cur)) {
                        plugin = (Plugin *) plugin_cur->data;
@@ -131,14 +134,25 @@ void plugin_save_list(void)
                                continue;
                        
                        if (!strcmp(plugin->type(), type_cur->data))
-                               fprintf(pfile->fp, "%s\n", plugin->filename);
+                               if (fprintf(pfile->fp, "%s\n", plugin->filename) < 0)
+                                       goto revert;
                }
-               fprintf(pfile->fp, "\n");
+               if (fprintf(pfile->fp, "\n") < 0)
+                       goto revert;
 
                if (prefs_file_close(pfile) < 0)
                        g_warning("failed to write plugin list\n");
 
                g_free(rcpath); 
+               
+               continue;
+
+revert:
+               g_warning("failed to write plugin list\n");
+               if (prefs_file_close_revert(pfile) < 0)
+                       g_warning("failed to revert plugin list\n");
+
+               g_free(rcpath); 
        }
 }
 
@@ -200,6 +214,7 @@ static gint plugin_load_deps(const gchar *filename, gchar **error)
                        dep_plugin = plugin_load(path, error);
                        if (dep_plugin == NULL) {
                                g_free(path);
+                               fclose(fp);
                                return -1;
                        }
                }
@@ -294,9 +309,8 @@ Plugin *plugin_load(const gchar *filename, gchar **error)
        const gchar *(*plugin_type)(void);
        const gchar *(*plugin_licence)(void);
        struct PluginFeature *(*plugin_provides)(void);
-
        gint ok;
-
+       START_TIMING((filename?filename:"NULL plugin"));
        g_return_val_if_fail(filename != NULL, NULL);
        g_return_val_if_fail(error != NULL, NULL);
 
@@ -348,7 +362,7 @@ init_plugin:
        
        if (strcmp(plugin_licence(), "GPL2+") && strncmp(plugin_licence(), "GPL3", strlen("GPL3"))
        &&  strncmp(plugin_licence(), "GPL2+-compatible", strlen("GPL2+-compatible"))) {
-               *error = g_strdup(_("This module is not licenced under a GPL v2 or later compatible licence."));
+               *error = g_strdup(_("This module is not licensed under a GPL v2 or later compatible license."));
                if (plugin->unloaded_hidden)
                        return NULL;
                g_module_close(plugin->module);
@@ -393,7 +407,7 @@ init_plugin:
        plugin->unloaded_hidden = FALSE;
 
        debug_print("Plugin %s (from file %s) loaded\n", plugin->name(), filename);
-
+       END_TIMING();
        return plugin;
 }
 
@@ -450,6 +464,8 @@ void plugin_load_all(const gchar *type)
        if ((pfile = prefs_read_open(rcpath)) == NULL ||
            (prefs_set_block_label(pfile, block) < 0)) {
                g_free(rcpath);
+               if (pfile)
+                       prefs_file_close(pfile);
                return;
        }
        g_free(block);