From 00618412f6db4570b9708f9e4ee61bb64ce37c1b Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 6 Sep 2011 10:57:44 +0100 Subject: another bug found within the apt-menuitem --- src/apt-watcher.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/apt-watcher.c') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index 480e174..167b847 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -380,11 +380,17 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy, gchar* current = NULL; g_debug ("ActiveTransactionsChanged"); - //gchar** queued = NULL; g_variant_get(value, "s", ¤t); + if (g_str_has_prefix (current, "/org/debian/apt/transaction/") == TRUE){ g_debug ("ActiveTransactionsChanged - current is %s", current); + // Cancel all existing operations. + if (self->reboot_query != 0){ + g_source_remove (self->reboot_query); + self->reboot_query = 0; + } + if (self->current_transaction != NULL) { g_object_unref (G_OBJECT(self->current_transaction)); -- cgit v1.2.3 From 46db1068e1684293f02125872361f75204399e8f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 6 Sep 2011 17:59:18 +0100 Subject: refactor the apt state callback because the use case of real and simulation were proving far too disparate --- src/apt-watcher.c | 95 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 32 deletions(-) (limited to 'src/apt-watcher.c') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index 167b847..b0d9688 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -66,6 +66,13 @@ static void apt_watcher_signal_cb (GDBusProxy* proxy, static void apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id); static gboolean apt_watcher_query_reboot_status (gpointer self); +static void apt_watcher_transaction_state_simulation_update_cb (AptTransaction* trans, + gint update, + gpointer user_data); +static void apt_watcher_transaction_state_real_update_cb (AptTransaction* trans, + gint update, + gpointer user_data); + @@ -245,34 +252,23 @@ apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, } static void -apt_watcher_transaction_state_update_cb (AptTransaction* trans, - gint update, - gpointer user_data) +apt_watcher_transaction_state_real_update_cb (AptTransaction* trans, + gint update, + gpointer user_data) { g_debug ("apt-watcher -transaction update %i", update); g_return_if_fail (APT_IS_WATCHER (user_data)); AptWatcher* self = APT_WATCHER (user_data); AptState state = (AptState)update; - if (state == UP_TO_DATE){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Software Up to Date")); - // Simulations don't send a finished signal for some reason - // Anyway from a simulation we just need one state update - // (updates available or not) - if (apt_transaction_get_transaction_type (self->current_transaction) - == SIMULATION){ - g_object_unref (G_OBJECT(self->current_transaction)); - self->current_transaction = NULL; - } if (self->reboot_query != 0){ g_source_remove (self->reboot_query); self->reboot_query = 0; } - // Wait a sec before querying for reboot status, - // race condition with Apt has been observed. self->reboot_query = g_timeout_add_seconds (1, apt_watcher_query_reboot_status, self); @@ -281,27 +277,15 @@ apt_watcher_transaction_state_update_cb (AptTransaction* trans, dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Updates Available…")); - // Simulations don't send a finished signal for some reason - // Anyway from a simulation we just need one state update - // (updates available or not) - if (apt_transaction_get_transaction_type (self->current_transaction) - == SIMULATION){ - g_object_unref (G_OBJECT(self->current_transaction)); - self->current_transaction = NULL; - } + self->current_state = state; } else if (state == UPGRADE_IN_PROGRESS){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Updates Installing…")); + self->current_state = state; } else if (state == FINISHED){ - g_object_unref (G_OBJECT(self->current_transaction)); - self->current_transaction = NULL; - - if (self->current_state == UPDATES_AVAILABLE){ - return; - } if (self->reboot_query != 0){ g_source_remove (self->reboot_query); @@ -312,11 +296,57 @@ apt_watcher_transaction_state_update_cb (AptTransaction* trans, self->reboot_query = g_timeout_add_seconds (1, apt_watcher_query_reboot_status, self); + } + + self->current_state = state; + + if (self->current_state != UPGRADE_IN_PROGRESS){ + g_object_unref (G_OBJECT(self->current_transaction)); + self->current_transaction = NULL; + } +} + + +static void +apt_watcher_transaction_state_simulation_update_cb (AptTransaction* trans, + gint update, + gpointer user_data) +{ + g_debug ("apt-watcher -transaction update %i", update); + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* self = APT_WATCHER (user_data); + + AptState state = (AptState)update; + + if (state == UP_TO_DATE){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Software Up to Date")); + if (self->reboot_query != 0){ + g_source_remove (self->reboot_query); + self->reboot_query = 0; + } + self->reboot_query = g_timeout_add_seconds (1, + apt_watcher_query_reboot_status, + self); + } + else if (state == UPDATES_AVAILABLE){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, - _("Finished Updating…")); + _("Updates Available…")); } + else if (state == UPGRADE_IN_PROGRESS){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Updates Installing…")); + } + self->current_state = state; + + if (self->current_state != UPGRADE_IN_PROGRESS){ + g_object_unref (G_OBJECT(self->current_transaction)); + self->current_transaction = NULL; + } } static void @@ -326,7 +356,7 @@ apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id) self->current_transaction = apt_transaction_new (transaction_id, SIMULATION); g_signal_connect (G_OBJECT(self->current_transaction), "state-update", - G_CALLBACK(apt_watcher_transaction_state_update_cb), self); + G_CALLBACK(apt_watcher_transaction_state_simulation_update_cb), self); } } @@ -359,6 +389,7 @@ apt_watcher_query_reboot_status (gpointer data) DBUSMENU_MENUITEM_PROP_DISPOSITION, DBUSMENU_MENUITEM_DISPOSITION_ALERT); session_dbus_restart_required (self->session_dbus_interface); + self->current_state = RESTART_NEEDED; } self->reboot_query = 0; return FALSE; @@ -384,7 +415,7 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy, if (g_str_has_prefix (current, "/org/debian/apt/transaction/") == TRUE){ g_debug ("ActiveTransactionsChanged - current is %s", current); - + // Cancel all existing operations. if (self->reboot_query != 0){ g_source_remove (self->reboot_query); @@ -400,7 +431,7 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy, self->current_transaction = apt_transaction_new (current, REAL); g_signal_connect (G_OBJECT(self->current_transaction), "state-update", - G_CALLBACK(apt_watcher_transaction_state_update_cb), self); + G_CALLBACK(apt_watcher_transaction_state_real_update_cb), self); } } g_variant_unref (parameters); -- cgit v1.2.3 From d0d4fd57cf3a25547c570139cc6a311ce05eed44 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Sep 2011 12:04:16 +0100 Subject: more revelations with regards the behaviour of the apt dbus 'api' --- src/apt-watcher.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/apt-watcher.c') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index b0d9688..1f88868 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -269,7 +269,7 @@ apt_watcher_transaction_state_real_update_cb (AptTransaction* trans, g_source_remove (self->reboot_query); self->reboot_query = 0; } - self->reboot_query = g_timeout_add_seconds (1, + self->reboot_query = g_timeout_add_seconds (2, apt_watcher_query_reboot_status, self); } @@ -277,27 +277,27 @@ apt_watcher_transaction_state_real_update_cb (AptTransaction* trans, dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Updates Available…")); - self->current_state = state; } else if (state == UPGRADE_IN_PROGRESS){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Updates Installing…")); - self->current_state = state; } else if (state == FINISHED){ - - if (self->reboot_query != 0){ - g_source_remove (self->reboot_query); - self->reboot_query = 0; + // Only query if the previous state was an upgrade. + if (self->current_state == UPGRADE_IN_PROGRESS){ + if (self->reboot_query != 0){ + g_source_remove (self->reboot_query); + self->reboot_query = 0; + } + // Wait a sec before querying for reboot status, + // race condition with Apt has been observed. + self->reboot_query = g_timeout_add_seconds (2, + apt_watcher_query_reboot_status, + self); } - // Wait a sec before querying for reboot status, - // race condition with Apt has been observed. - self->reboot_query = g_timeout_add_seconds (1, - apt_watcher_query_reboot_status, - self); } - + // Set the current state self->current_state = state; if (self->current_state != UPGRADE_IN_PROGRESS){ @@ -326,7 +326,7 @@ apt_watcher_transaction_state_simulation_update_cb (AptTransaction* trans, g_source_remove (self->reboot_query); self->reboot_query = 0; } - self->reboot_query = g_timeout_add_seconds (1, + self->reboot_query = g_timeout_add_seconds (2, apt_watcher_query_reboot_status, self); } -- cgit v1.2.3 From bc14f0aeb2dbd61c077f1f61c41303f0db4b9781 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Sep 2011 15:34:50 +0100 Subject: more hoop jumping for apt --- src/apt-watcher.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/apt-watcher.c') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index 1f88868..d2cd1b5 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -272,18 +272,23 @@ apt_watcher_transaction_state_real_update_cb (AptTransaction* trans, self->reboot_query = g_timeout_add_seconds (2, apt_watcher_query_reboot_status, self); + self->current_state = state; } else if (state == UPDATES_AVAILABLE){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Updates Available…")); + self->current_state = state; } else if (state == UPGRADE_IN_PROGRESS){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Updates Installing…")); + self->current_state = state; } else if (state == FINISHED){ + gboolean query_again = FALSE; + // Only query if the previous state was an upgrade. if (self->current_state == UPGRADE_IN_PROGRESS){ if (self->reboot_query != 0){ @@ -296,14 +301,30 @@ apt_watcher_transaction_state_real_update_cb (AptTransaction* trans, apt_watcher_query_reboot_status, self); } - } - // Set the current state - self->current_state = state; - - if (self->current_state != UPGRADE_IN_PROGRESS){ + else{ + query_again = TRUE; + } + self->current_state = state; + g_object_unref (G_OBJECT(self->current_transaction)); self->current_transaction = NULL; - } + // Mental ah yes, because a real transaction (like one which is manually triggered by the user + // by hitting check on update-mgr) does not return a 'dependency' prop update which means + // I cannot figure out from that transaction if an update is available. + // Only when it finishes and I'm confident it was not an transaction concerned with actually updating should i then fire off another transaction, + // this time being a simulation which 'should' figure out if an update is available. + // The Reality is all APT transactions behave differently, an obsolutely nightmare of an API to use. + if (query_again){ + g_dbus_proxy_call (self->proxy, + "UpgradeSystem", + g_variant_new("(b)", TRUE), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + apt_watcher_upgrade_system_cb, + self); + } + } } -- cgit v1.2.3 From 058f9cbcbfbe0ed93ce14ad31c5a7ccd14b6d61c Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Sep 2011 16:03:22 +0100 Subject: more hoop jumping for apt --- src/apt-watcher.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src/apt-watcher.c') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index d2cd1b5..bbb541a 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -261,17 +261,11 @@ apt_watcher_transaction_state_real_update_cb (AptTransaction* trans, AptWatcher* self = APT_WATCHER (user_data); AptState state = (AptState)update; + if (state == UP_TO_DATE){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Software Up to Date")); - if (self->reboot_query != 0){ - g_source_remove (self->reboot_query); - self->reboot_query = 0; - } - self->reboot_query = g_timeout_add_seconds (2, - apt_watcher_query_reboot_status, - self); self->current_state = state; } else if (state == UPDATES_AVAILABLE){ -- cgit v1.2.3 From b85f29bbd848238a4b60fe2eccf3ead06c47b979 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Sep 2011 21:20:42 +0100 Subject: tidy up --- src/apt-watcher.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/apt-watcher.c') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index bbb541a..e5e1d0e 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -302,12 +302,9 @@ apt_watcher_transaction_state_real_update_cb (AptTransaction* trans, g_object_unref (G_OBJECT(self->current_transaction)); self->current_transaction = NULL; - // Mental ah yes, because a real transaction (like one which is manually triggered by the user - // by hitting check on update-mgr) does not return a 'dependency' prop update which means - // I cannot figure out from that transaction if an update is available. - // Only when it finishes and I'm confident it was not an transaction concerned with actually updating should i then fire off another transaction, - // this time being a simulation which 'should' figure out if an update is available. - // The Reality is all APT transactions behave differently, an obsolutely nightmare of an API to use. + + // It is impossible to determine from a 'real' transaction whether + // updates are available ? if (query_again){ g_dbus_proxy_call (self->proxy, "UpgradeSystem", -- cgit v1.2.3