Commits

jjacky committed ff941c3

Adds support for $PACKAGES in command-line for AUR upgrades

On the command line to be executed on AUR upgrades, a variable $PACKAGES can now be used. It will be replaced by the list (space separated) of all AUR packages for which an upgrade if available.

Also, replaced uses of g_thread_create (deprecated) with g_thread_try_new

Comments (0)

Files changed (3)

 }
 
 static void
-run_cmdline (const char *cmdline)
+run_cmdline (char *cmdline)
 {
     GError *error = NULL;
     
         /* check again, to refresh the state (since an upgrade was probably just done) */
         kalu_check (TRUE);
     }
+    
+    if (cmdline != config->cmdline && cmdline != config->cmdline_aur)
+    {
+        free (cmdline);
+    }
 }
 
 void
-action_upgrade (NotifyNotification *notification, const char *action, gpointer data _UNUSED_)
+action_upgrade (NotifyNotification *notification, const char *action, gchar *_cmdline)
 {
-    char *cmdline = NULL;
+    char *cmdline = (_cmdline) ? strdup (_cmdline) : NULL;
     
     notify_notification_close (notification, NULL);
     
-    if (strcmp ("do_updates", action) == 0)
+    if (!cmdline)
     {
-        #ifndef DISABLE_UPDATER
-        if (config->action == UPGRADE_ACTION_KALU)
+        if (strcmp ("do_updates", action) == 0)
         {
-            run_updater ();
+            #ifndef DISABLE_UPDATER
+            if (config->action == UPGRADE_ACTION_KALU)
+            {
+                run_updater ();
+            }
+            else /* if (config->action == UPGRADE_ACTION_CMDLINE) */
+            {
+            #endif
+                cmdline = config->cmdline;
+            #ifndef DISABLE_UPDATER
+            }
+            #endif
         }
-        else /* if (config->action == UPGRADE_ACTION_CMDLINE) */
+        else /* if (strcmp ("do_updates_aur", action) == 0) */
         {
-        #endif
-            cmdline = config->cmdline;
-        #ifndef DISABLE_UPDATER
+            cmdline = config->cmdline_aur;
         }
-        #endif
-    }
-    else /* if (strcmp ("do_updates_aur", action) == 0) */
-    {
-        cmdline = config->cmdline_aur;
     }
     
     if (cmdline)
     {
         /* run in a separate thread, to not block/make GUI unresponsive */
-        g_thread_create ((GThreadFunc) run_cmdline, (gpointer) cmdline, FALSE, NULL);
+        g_thread_unref (g_thread_try_new ("action_upgrade",
+                                          (GThreadFunc) run_cmdline,
+                                          (gpointer) cmdline,
+                                          NULL));
     }
 }
 
     set_kalpm_busy (TRUE);
     
     /* run in a separate thread, to not block/make GUI unresponsive */
-    g_thread_create ((GThreadFunc) kalu_check_work, GINT_TO_POINTER (is_auto), FALSE, NULL);
+    g_thread_unref (g_thread_try_new ("kalu_check_work",
+                                      (GThreadFunc) kalu_check_work,
+                                      GINT_TO_POINTER (is_auto),
+                                      NULL));
 }
 
 void
     {
     #endif
         /* run in a separate thread, to not block/make GUI unresponsive */
-        g_thread_create ((GThreadFunc) run_cmdline, (gpointer) config->cmdline, FALSE, NULL);
+        g_thread_unref (g_thread_try_new ("cmd_sysupgrade",
+                                          (GThreadFunc) run_cmdline,
+                                          (gpointer) config->cmdline,
+                                          NULL));
     #ifndef DISABLE_UPDATER
     }
     #endif
 show_error_cmdline (gchar *arg[]);
 
 void
-action_upgrade (NotifyNotification *notification, const char *action, gpointer data);
+action_upgrade (NotifyNotification *notification, const char *action, gchar *_cmdline);
 
 void
 action_watched (NotifyNotification *notification, char *action, alpm_list_t *packages);
     const char *unit;
     double      size_h;
     replacement_t *replacements[7];
+    GString    *string_pkgs = NULL;     /* list of AUR packages */
+    gchar      *cmdline;                /* cmdline w/ $PACKAGES replaced */
     
     #ifdef DISABLE_GUI
     (void) xml_news;
     else if (type & CHECK_AUR)
     {
         tt = config->tpl_aur;
+        /* if needed, init the string that will hold the list of packages */
+        if (config->cmdline_aur)
+        {
+            string_pkgs = g_string_sized_new (255);
+        }
     }
     else if (type & CHECK_WATCHED_AUR)
     {
                    pkg->new_version,
                    (int) pkg->dl_size,
                    (int) pkg->new_size);
+            
+            /* construct list of packages, for use in cmdline */
+            if (string_pkgs)
+            {
+                string_pkgs = g_string_append (string_pkgs, pkg->name);
+                string_pkgs = g_string_append_c (string_pkgs, ' ');
+            }
         }
     }
     
     {
         if (config->cmdline_aur)
         {
-            notify_notification_add_action (notification, "do_updates_aur",
-                "Update AUR packages...", (NotifyActionCallback) action_upgrade,
-                NULL, NULL);
+            if (string_pkgs)
+            {
+                /* if we have a list of pkgs, update the cmdline */
+                cmdline = strreplace (config->cmdline_aur, "$PACKAGES", string_pkgs->str);
+                g_string_free (string_pkgs, TRUE);
+            }
+            else
+            {
+                /* else no user data, so it'll default to config->cmdline_aur
+                 * So we'll always be able to call free (cmdline) in action_upgrade */
+                cmdline = NULL;
+            }
+            
+            notify_notification_add_action (notification,
+                                            "do_updates_aur",
+                                            "Update AUR packages...",
+                                            (NotifyActionCallback) action_upgrade,
+                                            cmdline,
+                                            (GFreeFunc) free);
         }
     }
     else if (type & CHECK_WATCHED)