about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJohn Hernandez <129467592+H3rnand3zzz@users.noreply.github.com>2023-04-19 03:29:23 +0200
committerJohn Hernandez <129467592+H3rnand3zzz@users.noreply.github.com>2023-04-19 03:29:23 +0200
commita54e5413cadfa57e4b55b994939f01f02b04b5de (patch)
tree6eca02fe32bdb850ef051654c5cdf97219f06968 /src/command
parent96f9a84f019d234ad91bd99409cd170c63aec4fc (diff)
downloadprofani-tty-a54e5413cadfa57e4b55b994939f01f02b04b5de.tar.gz
Fix `/plugins update`
Before it tried to unload the plugin first and check the output.
But if broken plugin was loaded, then it couldn't unload it,
so before it require uninstall and install after it,
making update useless for plugin development purposes.

Unload is part of the uninstall so no unload is needed inside of the cmd function.

Refactoring of cmd_plugins_update.
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_funcs.c53
1 files changed, 22 insertions, 31 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 507a8ccd..454dbda7 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -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;
 }