about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorPhilip Flohr <philip.flohr@student.kit.edu>2018-08-02 07:51:13 +0200
committerDmitry Podgorny <pasis.ua@gmail.com>2018-09-06 19:54:29 +0300
commit054267d738af1799ed47704d24626b2dab4f962f (patch)
tree7c2f858d85b1cd24854423151e6d615ac238a366 /src
parenta5a7db9e2b63c5748dea312d23aafbb89d660667 (diff)
downloadprofani-tty-054267d738af1799ed47704d24626b2dab4f962f.tar.gz
Fix extended plugin handling PR
Fixes problems found in PR #999
Diffstat (limited to 'src')
-rw-r--r--src/command/cmd_funcs.c23
-rw-r--r--src/common.c14
-rw-r--r--src/plugins/plugins.c7
3 files changed, 25 insertions, 19 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index fa675309..9cc7b881 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -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);
         }
         g_free(plugin_name);
-
+        g_string_free(error_message, TRUE);
         free(path);
         return TRUE;
     }
@@ -6699,24 +6699,31 @@ cmd_plugins_update(ProfWin *window, const char *const command, gchar **args)
 
         GString* error_message = g_string_new(NULL);
         gchar *plugin_name = g_path_get_basename(path);
-        gboolean result = plugins_unload(plugin_name);
-        result |= plugins_uninstall(plugin_name);
-        result |= plugins_install(plugin_name, path, error_message);
-        if (result) {
-            cons_show("Plugin installed: %s", plugin_name);
+        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 install plugin: %s. %s", plugin_name, error_message->str);
+            cons_show("Failed to unload plugin: %s.", plugin_name);
         }
         g_free(plugin_name);
-
+        g_string_free(error_message, TRUE);
         free(path);
         return TRUE;
     }
 
     if (is_dir(path)) {
+        free(path);
         return FALSE;
     }
 
+    free(path);
     cons_show("Argument must be a file or directory.");
     return TRUE;
 }
diff --git a/src/common.c b/src/common.c
index 251eddc6..1f37b664 100644
--- a/src/common.c
+++ b/src/common.c
@@ -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 *dest = g_file_new_for_path(targetpath);
     GError *error = NULL;
-    gboolean success = false;
-    
-    if (overwrite_existing)
-    {
-        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);
-    }
+    GFileCopyFlags flags = overwrite_existing ? G_FILE_COPY_OVERWRITE : G_FILE_COPY_NONE;
+    gboolean success = g_file_copy (source, dest, flags, NULL, NULL, NULL, &error);
+    g_object_unref(source);
+    g_object_unref(dest);
     return success;
 }
 
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c
index 5b60b398..3e07af4d 100644
--- a/src/plugins/plugins.c
+++ b/src/plugins/plugins.c
@@ -162,6 +162,7 @@ plugins_install_all(const char *const path)
             }
         }
         curr = g_slist_next(curr);
+        g_string_free(error_message, TRUE);
     }
 
     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);
     GFile *file = g_file_new_for_path(target_path->str);
     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