Skip to content

Commit

Permalink
Merge pull request #1840 from H3rnand3zzz/fix/plugins-unload
Browse files Browse the repository at this point in the history
Fix `/plugins update`
  • Loading branch information
jubalh committed Apr 19, 2023
2 parents ec87d9a + a54e541 commit 3be0914
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions src/command/cmd_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7120,51 +7120,42 @@ cmd_plugins_install(ProfWin* window, const char* const command, gchar** args)
gboolean
cmd_plugins_update(ProfWin* window, const char* const command, gchar** args)
{
char* path;

if (args[1] == NULL) {
cons_bad_cmd_usage(command);
return TRUE;
} else {
path = get_expanded_path(args[1]);
}

auto_gchar gchar* path = get_expanded_path(args[1]);

if (access(path, R_OK) != 0) {
cons_show("File not found: %s", path);
free(path);
return TRUE;
}

if (is_regular_file(path)) {
if (!g_str_has_suffix(path, ".py") && !g_str_has_suffix(path, ".so")) {
cons_show("Plugins must have one of the following extensions: '.py' '.so'");
free(path);
return TRUE;
}
if (!is_regular_file(path)) {
cons_show("Argument must be a file.");
return TRUE;
}

GString* error_message = g_string_new(NULL);
gchar* plugin_name = g_path_get_basename(path);
if (plugins_unload(plugin_name)) {
if (plugins_uninstall(plugin_name)) {
if (plugins_install(plugin_name, path, error_message)) {
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 {
cons_show("Failed to unload plugin: %s.", plugin_name);
}
g_free(plugin_name);
g_string_free(error_message, TRUE);
free(path);
if (!g_str_has_suffix(path, ".py") && !g_str_has_suffix(path, ".so")) {
cons_show("Plugins must have one of the following extensions: '.py' or '.so'");
return TRUE;
}

free(path);
cons_show("Argument must be a file.");
auto_gchar gchar* plugin_name = g_path_get_basename(path);
if (!plugins_uninstall(plugin_name)) {
cons_show("Failed to uninstall plugin: %s.", plugin_name);
return TRUE;
}

GString* error_message = g_string_new(NULL);
if (plugins_install(plugin_name, path, error_message)) {
cons_show("Plugin installed: %s", plugin_name);
} else {
cons_show("Failed to install plugin: %s. %s", plugin_name, error_message->str);
}

g_string_free(error_message, TRUE);
return TRUE;
}

Expand Down

0 comments on commit 3be0914

Please sign in to comment.