summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2019-07-12 13:17:22 +0000
committerJason Woodward2019-07-21 15:28:02 -0400
commitcdb85eafa5c0b5ff08fda052657c891e60155f53 (patch)
tree99b03bf39883a54a63280a7d452b29a5da0f25f0
parent398563160dd50027c1a38b9ea44936d81f4337dd (diff)
downloadslapt-update-service-cdb85eafa5c0b5ff08fda052657c891e60155f53.tar.gz
port to slapt-get 0.11.1
-rw-r--r--config.h.in11
-rw-r--r--configure.ac2
-rw-r--r--src/client.c316
-rw-r--r--src/server.c82
-rw-r--r--src/slaptService.c171
-rw-r--r--src/slaptService.h45
6 files changed, 308 insertions, 319 deletions
diff --git a/config.h.in b/config.h.in
index 855d63b..b08eeca 100644
--- a/config.h.in
+++ b/config.h.in
@@ -24,6 +24,14 @@
/* Define to 1 if you have the `bind_textdomain_codeset' function. */
#undef HAVE_BIND_TEXTDOMAIN_CODESET
+/* Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the
+ CoreFoundation framework. */
+#undef HAVE_CFLOCALECOPYCURRENT
+
+/* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in
+ the CoreFoundation framework. */
+#undef HAVE_CFPREFERENCESCOPYAPPVALUE
+
/* Define to 1 if you have the `dcgettext' function. */
#undef HAVE_DCGETTEXT
@@ -66,9 +74,6 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
-/* Define to 1 if your C compiler doesn't accept -c and -o together. */
-#undef NO_MINUS_C_MINUS_O
-
/* Name of package */
#undef PACKAGE
diff --git a/configure.ac b/configure.ac
index a55d381..0561954 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,7 +36,7 @@ AC_CHECK_LIB(gpgme,gpgme_new, [
[AC_DEFINE(SLAPT_HAS_GPGME, 1, [libslapt has builtin gpgme support])],
[AC_MSG_WARN(libslapt does not have gpgme support)])
], [AC_MSG_WARN(gpg support disabled)])
-AC_CHECK_LIB(slapt,slapt_disk_space_check, [], [AC_MSG_ERROR(libslapt 0.10.2b or greater is required)])
+AC_CHECK_LIB(slapt,slapt_vector_t_init, [], [AC_MSG_ERROR(libslapt 0.11.1 or greater is required)])
PKG_CHECK_MODULES(GLIB, [glib-2.0 gobject-2.0 gthread-2.0])
AC_SUBST(GLIB_CFLAGS)
diff --git a/src/client.c b/src/client.c
index 01b3247..2acd100 100644
--- a/src/client.c
+++ b/src/client.c
@@ -15,7 +15,7 @@
* along with this program; If not, see <http://www.gnu.org/licenses/>
*/
#ifdef HAVE_CONFIG_H
-# include <config.h>
+#include <config.h>
#endif
#include "client-bindings.h"
@@ -39,249 +39,241 @@
#define NOTIFICATION_SHOW_UPDATES "show updates"
struct slapt_update_notifier {
- GtkStatusIcon *tray_icon;
- GdkPixbuf *running_pixbuf;
- GdkPixbuf *updates_pixbuf;
- GtkWidget *menu;
- DBusGConnection *bus;
- DBusGProxy *proxy;
+ GtkStatusIcon *tray_icon;
+ GdkPixbuf *running_pixbuf;
+ GdkPixbuf *updates_pixbuf;
+ GtkWidget *menu;
+ DBusGConnection *bus;
+ DBusGProxy *proxy;
};
static struct slapt_update_notifier *sun = NULL;
-static void hide_sun (void);
+static void hide_sun(void);
-static void run_gslapt (const char *action)
+static void run_gslapt(const char *action)
{
- gchar *argv[4];
+ gchar *argv[4];
#if defined(HAS_GNOMESU)
- argv[0] = "/usr/bin/gnomesu";
- argv[1] = "-c";
- if ( strcmp(action,"upgrade") == 0 ) {
- argv[2] = "/usr/sbin/gslapt --upgrade";
- } else {
- argv[2] = "/usr/sbin/gslapt";
- }
- argv[3] = NULL;
+ argv[0] = "/usr/bin/gnomesu";
+ argv[1] = "-c";
+ if (strcmp(action, "upgrade") == 0) {
+ argv[2] = "/usr/sbin/gslapt --upgrade";
+ } else {
+ argv[2] = "/usr/sbin/gslapt";
+ }
+ argv[3] = NULL;
#elif defined(HAS_GKSU)
- argv[0] = "/usr/bin/gksu";
- if ( strcmp(action,"upgrade") == 0 ) {
- argv[1] = "/usr/sbin/gslapt --upgrade";
- } else {
- argv[1] = "/usr/sbin/gslapt";
- }
- argv[2] = NULL;
+ argv[0] = "/usr/bin/gksu";
+ if (strcmp(action, "upgrade") == 0) {
+ argv[1] = "/usr/sbin/gslapt --upgrade";
+ } else {
+ argv[1] = "/usr/sbin/gslapt";
+ }
+ argv[2] = NULL;
#elif defined(HAS_KDESU)
- argv[0] = "/usr/bin/kdesu";
- if ( strcmp(action,"upgrade") == 0 ) {
- argv[1] = "/usr/sbin/gslapt --upgrade";
- } else {
- argv[1] = "/usr/sbin/gslapt";
- }
- argv[2] = NULL;
+ argv[0] = "/usr/bin/kdesu";
+ if (strcmp(action, "upgrade") == 0) {
+ argv[1] = "/usr/sbin/gslapt --upgrade";
+ } else {
+ argv[1] = "/usr/sbin/gslapt";
+ }
+ argv[2] = NULL;
#else
- #error unable to create command to run gslapt
+#error unable to create command to run gslapt
#endif
- g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL);
- hide_sun();
+ g_spawn_async(NULL, argv, NULL, 0, NULL, NULL, NULL, NULL);
+ hide_sun();
}
-void tray_clicked (GtkStatusIcon *status_icon, gpointer data)
+void tray_clicked(GtkStatusIcon *status_icon, gpointer data)
{
- run_gslapt("upgrade");
+ run_gslapt("upgrade");
}
-void tray_menu (GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer data)
+void tray_menu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer data)
{
- gtk_menu_popup(
- GTK_MENU(sun->menu),
- NULL,NULL,NULL,NULL,
- button,activate_time
- );
+ gtk_menu_popup(
+ GTK_MENU(sun->menu),
+ NULL, NULL, NULL, NULL,
+ button, activate_time);
}
#ifdef USE_LIBNOTIFY
static void notify_callback(NotifyNotification *handle, const char *action, void *user_data)
{
- GMainLoop *loop = (GMainLoop*)user_data;
-
- if ( strcmp(action,NOTIFICATION_SHOW_UPDATES) == 0 ) {
- gtk_widget_hide_all(GTK_WIDGET(sun->tray_icon));
- run_gslapt("upgrade");
- }
+ GMainLoop *loop = (GMainLoop *)user_data;
- if (handle != NULL) {
- GError *error = NULL;
- if (notify_notification_close(handle, &error) != TRUE) {
- fprintf(stderr, "failed to send notification: %s\n", error->message);
- g_error_free (error);
+ if (strcmp(action, NOTIFICATION_SHOW_UPDATES) == 0) {
+ gtk_widget_hide_all(GTK_WIDGET(sun->tray_icon));
+ run_gslapt("upgrade");
}
- }
- if (loop != NULL)
- g_main_loop_quit(loop);
+ if (handle != NULL) {
+ GError *error = NULL;
+ if (notify_notification_close(handle, &error) != TRUE) {
+ fprintf(stderr, "failed to send notification: %s\n", error->message);
+ g_error_free(error);
+ }
+ }
+ if (loop != NULL)
+ g_main_loop_quit(loop);
}
-gboolean show_notification (gpointer data)
+gboolean show_notification(gpointer data)
{
- NotifyNotification *n;
+ NotifyNotification *n;
- n = notify_notification_new (
- _("New updates available"),
- _("Click on the update icon to see the available updates"),
- "info", NULL
- );
+ n = notify_notification_new(
+ _("New updates available"),
+ _("Click on the update icon to see the available updates"),
+ "info", NULL);
- GError *error = NULL;
- if (notify_notification_show(n, &error) != TRUE)
- {
- fprintf(stderr, "failed to send notification: %s\n", error->message);
- g_error_free (error);
- }
+ GError *error = NULL;
+ if (notify_notification_show(n, &error) != TRUE) {
+ fprintf(stderr, "failed to send notification: %s\n", error->message);
+ g_error_free(error);
+ }
- g_object_unref(G_OBJECT(n));
+ g_object_unref(G_OBJECT(n));
- return FALSE;
+ return FALSE;
}
#endif
-void tray_destroy (struct slapt_update_notifier *sun)
+void tray_destroy(struct slapt_update_notifier *sun)
{
+ if (sun->updates_pixbuf)
+ g_object_unref(G_OBJECT(sun->updates_pixbuf));
+ if (sun->running_pixbuf)
+ g_object_unref(G_OBJECT(sun->running_pixbuf));
- if (sun->updates_pixbuf)
- g_object_unref(G_OBJECT(sun->updates_pixbuf));
- if (sun->running_pixbuf)
- g_object_unref(G_OBJECT(sun->running_pixbuf));
-
- gtk_widget_destroy(GTK_WIDGET(sun->tray_icon));
+ gtk_widget_destroy(GTK_WIDGET(sun->tray_icon));
}
-static void hide_sun (void)
+static void hide_sun(void)
{
#ifdef USE_LIBNOTIFY
- NotifyNotification *n = g_object_get_data(G_OBJECT(sun->tray_icon),"notification");
+ NotifyNotification *n = g_object_get_data(G_OBJECT(sun->tray_icon), "notification");
#endif
- GMainLoop *loop = g_object_get_data(G_OBJECT(sun->tray_icon), "notification_loop");
+ GMainLoop *loop = g_object_get_data(G_OBJECT(sun->tray_icon), "notification_loop");
- gtk_status_icon_set_visible(sun->tray_icon, FALSE);
+ gtk_status_icon_set_visible(sun->tray_icon, FALSE);
#ifdef USE_LIBNOTIFY
- if ( n != NULL ) {
- GError *error = NULL;
- if (notify_notification_close(n, &error) != TRUE) {
- fprintf(stderr, "failed to send notification: %s\n", error->message);
- g_error_free (error);
+ if (n != NULL) {
+ GError *error = NULL;
+ if (notify_notification_close(n, &error) != TRUE) {
+ fprintf(stderr, "failed to send notification: %s\n", error->message);
+ g_error_free(error);
+ }
}
- }
#endif
-
- if ( loop != NULL )
- g_main_loop_quit(loop);
+ if (loop != NULL)
+ g_main_loop_quit(loop);
}
-void menuitem_hide_callback (GObject *g, void *data)
+void menuitem_hide_callback(GObject *g, void *data)
{
- hide_sun();
+ hide_sun();
}
-static void check_for_updates_callback (DBusGProxy *proxy, guint OUT_count, GError *error, gpointer userdata)
+static void check_for_updates_callback(DBusGProxy *proxy, guint OUT_count, GError *error, gpointer userdata)
{
+ if (OUT_count == 0)
+ return;
- if (OUT_count == 0)
- return;
-
- if (error != NULL) {
- g_warning ("check for updates failed: %s",
- error->message);
- g_error_free (error);
- }
+ if (error != NULL) {
+ g_warning("check for updates failed: %s",
+ error->message);
+ g_error_free(error);
+ }
- gtk_status_icon_set_visible(sun->tray_icon, TRUE);
+ gtk_status_icon_set_visible(sun->tray_icon, TRUE);
#ifdef USE_LIBNOTIFY
- show_notification(NULL);
+ show_notification(NULL);
#endif
}
-static void refresh_cache_callback (DBusGProxy *proxy, GError *error, gpointer userdata)
+static void refresh_cache_callback(DBusGProxy *proxy, GError *error, gpointer userdata)
{
+ if (error != NULL) {
+ g_warning("refresh cache failed: %s",
+ error->message);
+ g_error_free(error);
+ }
- if (error != NULL) {
- g_warning ("refresh cache failed: %s",
- error->message);
- g_error_free (error);
- }
-
- /* unset working icon */
- gtk_status_icon_set_visible(sun->tray_icon, FALSE);
- gtk_status_icon_set_from_pixbuf (sun->tray_icon, sun->updates_pixbuf);
+ /* unset working icon */
+ gtk_status_icon_set_visible(sun->tray_icon, FALSE);
+ gtk_status_icon_set_from_pixbuf(sun->tray_icon, sun->updates_pixbuf);
}
-static gboolean check_for_updates (gpointer userdata)
+static gboolean check_for_updates(gpointer userdata)
{
- DBusGProxy *proxy = (DBusGProxy *)((struct slapt_update_notifier *)userdata)->proxy;
+ DBusGProxy *proxy = (DBusGProxy *)((struct slapt_update_notifier *)userdata)->proxy;
- /* set working icon */
- gtk_status_icon_set_from_pixbuf (sun->tray_icon, sun->running_pixbuf);
- gtk_status_icon_set_visible(sun->tray_icon, TRUE);
+ /* set working icon */
+ gtk_status_icon_set_from_pixbuf(sun->tray_icon, sun->running_pixbuf);
+ gtk_status_icon_set_visible(sun->tray_icon, TRUE);
- org_jaos_SlaptService_refresh_cache_async (proxy, refresh_cache_callback, NULL);
- org_jaos_SlaptService_check_for_updates_async (proxy, check_for_updates_callback, NULL);
+ org_jaos_SlaptService_refresh_cache_async(proxy, refresh_cache_callback, NULL);
+ org_jaos_SlaptService_check_for_updates_async(proxy, check_for_updates_callback, NULL);
}
-int main (int argc, char *argv[])
+int main(int argc, char *argv[])
{
- GError *error = NULL;
- guint count;
- GtkWidget *menuitem = NULL;
+ GError *error = NULL;
+ guint count;
+ GtkWidget *menuitem = NULL;
- gtk_init (&argc, &argv);
+ gtk_init(&argc, &argv);
#ifdef USE_LIBNOTIFY
- notify_init("slapt-update-notifier");
+ notify_init("slapt-update-notifier");
#endif
- sun = malloc(sizeof *sun);
- sun->tray_icon = gtk_status_icon_new ();
- sun->updates_pixbuf = gdk_pixbuf_new_from_file(SUN_UPDATE_ICON, NULL);
- sun->running_pixbuf = gdk_pixbuf_new_from_file(SUN_RUNNING_ICON, NULL);
- gtk_status_icon_set_from_pixbuf (sun->tray_icon, sun->updates_pixbuf);
- gtk_status_icon_set_tooltip (sun->tray_icon, _("Updates available"));
- gtk_status_icon_set_visible(sun->tray_icon, FALSE);
-
- g_signal_connect(G_OBJECT(sun->tray_icon), "activate", G_CALLBACK(tray_clicked), &sun);
- g_signal_connect(G_OBJECT(sun->tray_icon), "popup-menu", G_CALLBACK(tray_menu), &sun);
-
- sun->menu = gtk_menu_new();
- menuitem = gtk_menu_item_new_with_label(_("Hide"));
- gtk_menu_shell_append(GTK_MENU_SHELL(sun->menu),menuitem);
- g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(menuitem_hide_callback),sun);
- gtk_widget_show_all(sun->menu);
-
- sun->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (sun->bus == NULL) {
- g_warning ("Failed to make connection to system bus: %s",
- error->message);
- g_error_free (error);
- exit(1);
- }
+ sun = malloc(sizeof *sun);
+ sun->tray_icon = gtk_status_icon_new();
+ sun->updates_pixbuf = gdk_pixbuf_new_from_file(SUN_UPDATE_ICON, NULL);
+ sun->running_pixbuf = gdk_pixbuf_new_from_file(SUN_RUNNING_ICON, NULL);
+ gtk_status_icon_set_from_pixbuf(sun->tray_icon, sun->updates_pixbuf);
+ gtk_status_icon_set_tooltip(sun->tray_icon, _("Updates available"));
+ gtk_status_icon_set_visible(sun->tray_icon, FALSE);
+
+ g_signal_connect(G_OBJECT(sun->tray_icon), "activate", G_CALLBACK(tray_clicked), &sun);
+ g_signal_connect(G_OBJECT(sun->tray_icon), "popup-menu", G_CALLBACK(tray_menu), &sun);
+
+ sun->menu = gtk_menu_new();
+ menuitem = gtk_menu_item_new_with_label(_("Hide"));
+ gtk_menu_shell_append(GTK_MENU_SHELL(sun->menu), menuitem);
+ g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(menuitem_hide_callback), sun);
+ gtk_widget_show_all(sun->menu);
+
+ sun->bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+ if (sun->bus == NULL) {
+ g_warning("Failed to make connection to system bus: %s",
+ error->message);
+ g_error_free(error);
+ exit(1);
+ }
- sun->proxy = dbus_g_proxy_new_for_name (sun->bus, "org.jaos.SlaptService","/org/jaos/SlaptService",
- "org.jaos.SlaptService");
+ sun->proxy = dbus_g_proxy_new_for_name(sun->bus, "org.jaos.SlaptService", "/org/jaos/SlaptService",
+ "org.jaos.SlaptService");
- check_for_updates ((gpointer)sun);
+ check_for_updates((gpointer)sun);
- g_timeout_add(SUN_TIMEOUT_RECHECK,(GSourceFunc)check_for_updates,sun);
+ g_timeout_add(SUN_TIMEOUT_RECHECK, (GSourceFunc)check_for_updates, sun);
- gtk_main();
+ gtk_main();
- tray_destroy(sun);
- g_object_unref (sun->proxy);
- free(sun);
+ tray_destroy(sun);
+ g_object_unref(sun->proxy);
+ free(sun);
#ifdef USE_LIBNOTIFY
- notify_uninit();
+ notify_uninit();
#endif
- return 0;
+ return 0;
}
diff --git a/src/server.c b/src/server.c
index ed2fea4..190a76c 100644
--- a/src/server.c
+++ b/src/server.c
@@ -24,57 +24,55 @@
static GMainLoop *loop;
-int main (void)
+int main(void)
{
- DBusGConnection *bus;
- DBusGProxy *proxy;
- GError *error = NULL;
- guint32 ret;
- SlaptService *slapt_service = NULL;
- int saved_stdout = dup(1);
- FILE *newstdout = NULL;
+ DBusGConnection *bus;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ guint32 ret;
+ SlaptService *slapt_service = NULL;
+ int saved_stdout = dup(1);
+ FILE *newstdout = NULL;
- g_type_init();
+ g_type_init();
#ifdef SLAPT_HAS_GPGME
- gpgme_check_version (NULL);
+ gpgme_check_version(NULL);
#endif
- bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (bus == NULL) {
- syslog (LOG_DAEMON | LOG_INFO,
- "Failed to make connection to system bus: %s",
- error->message);
- g_error_free (error);
- exit(1);
- }
+ bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+ if (bus == NULL) {
+ syslog(LOG_DAEMON | LOG_INFO,
+ "Failed to make connection to system bus: %s",
+ error->message);
+ g_error_free(error);
+ exit(1);
+ }
- proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
- if (!org_freedesktop_DBus_request_name (proxy, SLAPT_SERVICE_NAMESPACE, 0, &ret, &error)) {
- syslog (LOG_DAEMON | LOG_INFO,
- "There was an error requesting the name: %s",
- error->message);
- g_error_free (error);
- exit(1);
- }
+ proxy = dbus_g_proxy_new_for_name(bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+ if (!org_freedesktop_DBus_request_name(proxy, SLAPT_SERVICE_NAMESPACE, 0, &ret, &error)) {
+ syslog(LOG_DAEMON | LOG_INFO,
+ "There was an error requesting the name: %s",
+ error->message);
+ g_error_free(error);
+ exit(1);
+ }
- if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
- exit(1);
+ if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+ exit(1);
- slapt_service = slapt_service_new ();
+ slapt_service = slapt_service_new();
- dbus_g_connection_register_g_object (bus,
- SLAPT_SERVICE_PATH,
- G_OBJECT (slapt_service));
+ dbus_g_connection_register_g_object(bus,
+ SLAPT_SERVICE_PATH,
+ G_OBJECT(slapt_service));
+ /* this is to silence the bad use of stdout in libslapt */
+ newstdout = freopen("/dev/null", "w", stdout);
+ if (newstdout == NULL) {
+ fprintf(stderr, "failed to close stdout\n");
+ }
- /* this is to silence the bad use of stdout in libslapt */
- newstdout = freopen("/dev/null", "w", stdout);
- if (newstdout == NULL) {
- fprintf(stderr,"failed to close stdout\n");
- }
-
-
- loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (loop);
- return 0;
+ loop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(loop);
+ return 0;
}
diff --git a/src/slaptService.c b/src/slaptService.c
index fe78c68..4b208c7 100644
--- a/src/slaptService.c
+++ b/src/slaptService.c
@@ -19,147 +19,144 @@
#include "slaptService.h"
#include "server-bindings.h"
#include "common.h"
-#define SLAPT_SERVICE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SLAPT_TYPE_SERVICE, SlaptServicePrivate))
+#define SLAPT_SERVICE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), SLAPT_TYPE_SERVICE, SlaptServicePrivate))
-struct _SlaptServicePrivate
-{
- int count; /* nothing here yet */
+struct _SlaptServicePrivate {
+ int count; /* nothing here yet */
};
-G_DEFINE_TYPE (SlaptService, slapt_service, G_TYPE_OBJECT);
+G_DEFINE_TYPE(SlaptService, slapt_service, G_TYPE_OBJECT);
static gboolean slapt_service_real_check_for_updates(SlaptService *self, guint *count, GError **error)
{
- unsigned int i;
- slapt_pkg_list_t *installed_pkgs = NULL;
- slapt_pkg_list_t *avail_pkgs = NULL;
- slapt_transaction_t *tran = NULL;
- slapt_rc_config *rc = NULL;
-
- g_assert (SLAPT_IS_SERVICE (self));
+ unsigned int i;
+ slapt_vector_t *installed_pkgs = NULL;
+ slapt_vector_t *avail_pkgs = NULL;
+ slapt_transaction_t *tran = NULL;
+ slapt_rc_config *rc = NULL;
- *count = 0;
+ g_assert(SLAPT_IS_SERVICE(self));
- rc = slapt_read_rc_config(SLAPT_SERVICE_DEFAULT_RC);
- if ((chdir(rc->working_dir)) == -1)
- goto SLAPT_SERVICE_REAL_CHECK_FOR_UPDATES_DONE;
+ *count = 0;
- installed_pkgs = slapt_get_installed_pkgs();
- avail_pkgs = slapt_get_available_pkgs();
- if ( avail_pkgs == NULL || installed_pkgs == NULL )
- goto SLAPT_SERVICE_REAL_CHECK_FOR_UPDATES_DONE;
- if ( avail_pkgs->pkg_count == 0 )
- goto SLAPT_SERVICE_REAL_CHECK_FOR_UPDATES_DONE;
+ rc = slapt_read_rc_config(SLAPT_SERVICE_DEFAULT_RC);
+ if ((chdir(rc->working_dir)) == -1)
+ goto SLAPT_SERVICE_REAL_CHECK_FOR_UPDATES_DONE;
- tran = slapt_init_transaction();
- if (tran == NULL)
- goto SLAPT_SERVICE_REAL_CHECK_FOR_UPDATES_DONE;
+ installed_pkgs = slapt_get_installed_pkgs();
+ avail_pkgs = slapt_get_available_pkgs();
+ if (avail_pkgs == NULL || installed_pkgs == NULL)
+ goto SLAPT_SERVICE_REAL_CHECK_FOR_UPDATES_DONE;
+ if (avail_pkgs->size == 0)
+ goto SLAPT_SERVICE_REAL_CHECK_FOR_UPDATES_DONE;
- for (i = 0; i < installed_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *installed_pkg = installed_pkgs->pkgs[i];
- slapt_pkg_info_t *update_pkg = NULL;
- slapt_pkg_info_t *newer_installed_pkg = NULL;
+ tran = slapt_init_transaction();
+ if (tran == NULL)
+ goto SLAPT_SERVICE_REAL_CHECK_FOR_UPDATES_DONE;
- if (slapt_is_excluded(rc,installed_pkg))
- continue;
+ slapt_vector_t_foreach(slapt_pkg_info_t *, installed_pkg, installed_pkgs) {
+ slapt_pkg_info_t *update_pkg = NULL;
+ slapt_pkg_info_t *newer_installed_pkg = NULL;
- if ((newer_installed_pkg = slapt_get_newest_pkg(installed_pkgs, installed_pkg->name)) != NULL) {
- if (slapt_cmp_pkgs(installed_pkg,newer_installed_pkg) < 0)
- continue;
- }
+ if (slapt_is_excluded(rc, installed_pkg))
+ continue;
- update_pkg = slapt_get_newest_pkg(avail_pkgs, installed_pkg->name);
- if ( update_pkg != NULL ) {
+ if ((newer_installed_pkg = slapt_get_newest_pkg(installed_pkgs, installed_pkg->name)) != NULL) {
+ if (slapt_cmp_pkgs(installed_pkg, newer_installed_pkg) < 0)
+ continue;
+ }
- if (slapt_cmp_pkgs(installed_pkg,update_pkg) < 0) {
- if (slapt_is_excluded(rc,update_pkg))
- continue;
+ update_pkg = slapt_get_newest_pkg(avail_pkgs, installed_pkg->name);
+ if (update_pkg != NULL) {
+ if (slapt_cmp_pkgs(installed_pkg, update_pkg) < 0) {
+ if (slapt_is_excluded(rc, update_pkg))
+ continue;
- slapt_add_deps_to_trans(rc,tran,avail_pkgs, installed_pkgs,update_pkg);
- slapt_add_upgrade_to_transaction(tran,installed_pkg, update_pkg);
- } /* end if newer */
+ slapt_add_deps_to_trans(rc, tran, avail_pkgs, installed_pkgs, update_pkg);
+ slapt_add_upgrade_to_transaction(tran, installed_pkg, update_pkg);
+ } /* end if newer */
- }/* end upgrade pkg found */
+ } /* end upgrade pkg found */
- } /* end for installed_pkgs */
+ } /* end for installed_pkgs */
- /* count includes new installed as well as package upgrades */
- *count += tran->upgrade_pkgs->pkg_count + tran->install_pkgs->pkg_count;
+ /* count includes new installed as well as package upgrades */
+ *count += tran->upgrade_pkgs->size + tran->install_pkgs->size;
SLAPT_SERVICE_REAL_CHECK_FOR_UPDATES_DONE:
- if (installed_pkgs != NULL)
- slapt_free_pkg_list(installed_pkgs);
- if (avail_pkgs != NULL)
- slapt_free_pkg_list(avail_pkgs);
- if (tran != NULL)
- slapt_free_transaction(tran);
- if (rc != NULL)
- slapt_free_rc_config(rc);
-
- return TRUE;
+ if (installed_pkgs != NULL)
+ slapt_vector_t_free(installed_pkgs);
+ if (avail_pkgs != NULL)
+ slapt_vector_t_free(avail_pkgs);
+ if (tran != NULL)
+ slapt_free_transaction(tran);
+ if (rc != NULL)
+ slapt_free_rc_config(rc);
+
+ return TRUE;
}
static gboolean slapt_service_real_refresh_cache(SlaptService *self)
{
- slapt_rc_config *rc = NULL;
- int r = 0;
+ slapt_rc_config *rc = NULL;
+ int r = 0;
- g_assert (SLAPT_IS_SERVICE (self));
+ g_assert(SLAPT_IS_SERVICE(self));
- rc = slapt_read_rc_config(SLAPT_SERVICE_DEFAULT_RC);
+ rc = slapt_read_rc_config(SLAPT_SERVICE_DEFAULT_RC);
- if ((chdir(rc->working_dir)) == -1)
- return FALSE;
+ if ((chdir(rc->working_dir)) == -1)
+ return FALSE;
- if (slapt_update_pkg_cache(rc) != 0)
- fprintf(stderr,"failed to update package cache... handle me\n");
+ if (slapt_update_pkg_cache(rc) != 0)
+ fprintf(stderr, "failed to update package cache... handle me\n");
- slapt_free_rc_config(rc);
+ slapt_free_rc_config(rc);
- return TRUE;
+ return TRUE;
}
gboolean slapt_service_check_for_updates(SlaptService *self, guint *count, GError **error)
{
- g_assert (SLAPT_IS_SERVICE (self));
+ g_assert(SLAPT_IS_SERVICE(self));
- return self->check_for_updates (self, count, error);
+ return self->check_for_updates(self, count, error);
}
gboolean slapt_service_refresh_cache(SlaptService *self)
{
- g_assert (SLAPT_IS_SERVICE (self));
+ g_assert(SLAPT_IS_SERVICE(self));
- return self->refresh_cache (self);
+ return self->refresh_cache(self);
}
-static void slapt_service_class_init (SlaptServiceClass *class)
+static void slapt_service_class_init(SlaptServiceClass *class)
{
- GError *error = NULL;
+ GError *error = NULL;
- g_type_class_add_private (class, sizeof (SlaptServicePrivate));
+ g_type_class_add_private(class, sizeof(SlaptServicePrivate));
- class->check_for_updates = NULL;
- class->refresh_cache = NULL;
+ class->check_for_updates = NULL;
+ class->refresh_cache = NULL;
- dbus_g_object_type_install_info (SLAPT_TYPE_SERVICE, &dbus_glib_slapt_service_object_info);
+ dbus_g_object_type_install_info(SLAPT_TYPE_SERVICE, &dbus_glib_slapt_service_object_info);
}
-static void slapt_service_init (SlaptService *self)
+static void slapt_service_init(SlaptService *self)
{
- SlaptServiceClass *class = SLAPT_SERVICE_GET_CLASS (self);
- int request_ret;
+ SlaptServiceClass *class = SLAPT_SERVICE_GET_CLASS(self);
+ int request_ret;
- SlaptServicePrivate *priv;
+ SlaptServicePrivate *priv;
- self->check_for_updates = slapt_service_real_check_for_updates;
- self->refresh_cache = slapt_service_real_refresh_cache;
+ self->check_for_updates = slapt_service_real_check_for_updates;
+ self->refresh_cache = slapt_service_real_refresh_cache;
- self->priv = priv = SLAPT_SERVICE_GET_PRIVATE (self);
- priv->count = 0;
+ self->priv = priv = SLAPT_SERVICE_GET_PRIVATE(self);
+ priv->count = 0;
}
-SlaptService *slapt_service_new (void)
+SlaptService *slapt_service_new(void)
{
- return SLAPT_SERVICE (g_object_new (SLAPT_TYPE_SERVICE, NULL));
+ return SLAPT_SERVICE(g_object_new(SLAPT_TYPE_SERVICE, NULL));
}
diff --git a/src/slaptService.h b/src/slaptService.h
index e3d5eed..8ced049 100644
--- a/src/slaptService.h
+++ b/src/slaptService.h
@@ -21,41 +21,39 @@
#include <dbus/dbus-glib-bindings.h>
#include <slapt.h>
-#define SLAPT_TYPE_SERVICE (slapt_service_get_type ())
-#define SLAPT_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SLAPT_TYPE_SERVICE, SlaptService))
-#define SLAPT_IS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SLAPT_TYPE_SERVICE))
-#define SLAPT_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SLAPT_TYPE_SERVICE, SlaptServiceClass))
-#define SLAPT_IS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SLAPT_TYPE_SERVICE))
-#define SLAPT_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SLAPT_TYPE_SERVICE, SlaptServiceClass))
-
-typedef struct _SlaptService SlaptService;
-typedef struct _SlaptServiceClass SlaptServiceClass;
+#define SLAPT_TYPE_SERVICE (slapt_service_get_type())
+#define SLAPT_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SLAPT_TYPE_SERVICE, SlaptService))
+#define SLAPT_IS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SLAPT_TYPE_SERVICE))
+#define SLAPT_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SLAPT_TYPE_SERVICE, SlaptServiceClass))
+#define SLAPT_IS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SLAPT_TYPE_SERVICE))
+#define SLAPT_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), SLAPT_TYPE_SERVICE, SlaptServiceClass))
+
+typedef struct _SlaptService SlaptService;
+typedef struct _SlaptServiceClass SlaptServiceClass;
typedef struct _SlaptServicePrivate SlaptServicePrivate;
-struct _SlaptService
-{
- GObject parent_instance;
+struct _SlaptService {
+ GObject parent_instance;
- SlaptServicePrivate *priv;
+ SlaptServicePrivate *priv;
- gboolean (*check_for_updates) (SlaptService *self, guint *count, GError **error);
- gboolean (*refresh_cache) (SlaptService *self);
+ gboolean (*check_for_updates)(SlaptService *self, guint *count, GError **error);
+ gboolean (*refresh_cache)(SlaptService *self);
};
-struct _SlaptServiceClass
-{
- GObjectClass parent_class;
+struct _SlaptServiceClass {
+ GObjectClass parent_class;
- DBusGConnection *connection;
+ DBusGConnection *connection;
- gboolean (*check_for_updates) (SlaptService *self, guint *count, GError **error);
- gboolean (*refresh_cache) (SlaptService *self);
+ gboolean (*check_for_updates)(SlaptService *self, guint *count, GError **error);
+ gboolean (*refresh_cache)(SlaptService *self);
};
/* used by SLAPT_TYPE_SERVICE */
-GType slapt_service_get_type (void);
+GType slapt_service_get_type(void);
-SlaptService *slapt_service_new (void);
+SlaptService *slapt_service_new(void);
/*
* Method definitions.
*/
@@ -63,4 +61,3 @@ gboolean slapt_service_check_for_updates(SlaptService *self, guint *count, GErro
gboolean slapt_service_refresh_cache(SlaptService *self);
#endif /* __SLAPT_SERVICE_H__ */
-