1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Fix extended plugin handling PR

Fixes problems found in PR #999
This commit is contained in:
Philip Flohr 2018-08-02 07:51:13 +02:00 committed by Dmitry Podgorny
parent a5a7db9e2b
commit 054267d738
3 changed files with 25 additions and 19 deletions

View File

@ -6625,7 +6625,7 @@ cmd_plugins_install(ProfWin *window, const char *const command, gchar **args)
cons_show("Failed to install plugin: %s. %s", plugin_name, error_message->str); cons_show("Failed to install plugin: %s. %s", plugin_name, error_message->str);
} }
g_free(plugin_name); g_free(plugin_name);
g_string_free(error_message, TRUE);
free(path); free(path);
return TRUE; return TRUE;
} }
@ -6699,24 +6699,31 @@ cmd_plugins_update(ProfWin *window, const char *const command, gchar **args)
GString* error_message = g_string_new(NULL); GString* error_message = g_string_new(NULL);
gchar *plugin_name = g_path_get_basename(path); gchar *plugin_name = g_path_get_basename(path);
gboolean result = plugins_unload(plugin_name); if (plugins_unload(plugin_name)) {
result |= plugins_uninstall(plugin_name); if (plugins_uninstall(plugin_name)) {
result |= plugins_install(plugin_name, path, error_message); if (plugins_install(plugin_name, path, error_message)) {
if (result) { cons_show("Plugin installed: %s", plugin_name);
cons_show("Plugin installed: %s", plugin_name); } else {
cons_show("Failed to install plugin: %s. %s", plugin_name, error_message->str);
}
} else {
cons_show("Failed to uninstall plugin: %s.", plugin_name);
}
} else { } else {
cons_show("Failed to install plugin: %s. %s", plugin_name, error_message->str); cons_show("Failed to unload plugin: %s.", plugin_name);
} }
g_free(plugin_name); g_free(plugin_name);
g_string_free(error_message, TRUE);
free(path); free(path);
return TRUE; return TRUE;
} }
if (is_dir(path)) { if (is_dir(path)) {
free(path);
return FALSE; return FALSE;
} }
free(path);
cons_show("Argument must be a file or directory."); cons_show("Argument must be a file or directory.");
return TRUE; return TRUE;
} }

View File

@ -111,16 +111,10 @@ copy_file(const char *const sourcepath, const char *const targetpath, const gboo
GFile *source = g_file_new_for_path(sourcepath); GFile *source = g_file_new_for_path(sourcepath);
GFile *dest = g_file_new_for_path(targetpath); GFile *dest = g_file_new_for_path(targetpath);
GError *error = NULL; GError *error = NULL;
gboolean success = false; GFileCopyFlags flags = overwrite_existing ? G_FILE_COPY_OVERWRITE : G_FILE_COPY_NONE;
gboolean success = g_file_copy (source, dest, flags, NULL, NULL, NULL, &error);
if (overwrite_existing) g_object_unref(source);
{ g_object_unref(dest);
success = g_file_copy (source, dest, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error);
}
else
{
success = g_file_copy (source, dest, G_FILE_COPY_NONE, NULL, NULL, NULL, &error);
}
return success; return success;
} }

View File

@ -162,6 +162,7 @@ plugins_install_all(const char *const path)
} }
} }
curr = g_slist_next(curr); curr = g_slist_next(curr);
g_string_free(error_message, TRUE);
} }
g_slist_free_full(contents, g_free); g_slist_free_full(contents, g_free);
@ -180,7 +181,11 @@ plugins_uninstall(const char *const plugin_name)
g_string_append(target_path, plugin_name); g_string_append(target_path, plugin_name);
GFile *file = g_file_new_for_path(target_path->str); GFile *file = g_file_new_for_path(target_path->str);
GError *error = NULL; GError *error = NULL;
return g_file_delete(file, NULL, &error); gboolean result = g_file_delete(file, NULL, &error);
g_object_unref(file);
g_error_free(error);
g_string_free(target_path, TRUE);
return result;
} }
gboolean gboolean