From c578e6bee9e9275e4896ef6a361ae0f1f24ffe4e Mon Sep 17 00:00:00 2001 From: guinux Date: Fri, 27 Mar 2015 16:31:07 +0100 Subject: [PATCH] another try to fix #37, please test and report --- src/common.vala | 5 ++++ src/daemon.vala | 65 ++++++++++++++++++++------------------------ src/transaction.vala | 8 ++++-- src/tray.vala | 6 +++- 4 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/common.vala b/src/common.vala index 41ac89a..224593f 100644 --- a/src/common.vala +++ b/src/common.vala @@ -30,6 +30,11 @@ namespace Pamac { public bool is_syncfirst; public UpdateInfos[] repos_updates; public UpdateInfos[] aur_updates; + public Updates () { + is_syncfirst = false; + repos_updates = {}; + aur_updates = {}; + } } public enum Mode { diff --git a/src/daemon.vala b/src/daemon.vala index e07f42c..ff042fb 100644 --- a/src/daemon.vala +++ b/src/daemon.vala @@ -35,9 +35,8 @@ namespace Pamac { public Mutex provider_mutex; public int? choosen_provider; private Mutex databases_lock_mutex; - private HashTable aur_results; - private UpdateInfos[] aur_updates; - private bool aur_updates_checked; + private HashTable aur_search_results; + private Json.Array aur_updates_results; private bool intern_lock; private bool extern_lock; @@ -61,8 +60,8 @@ namespace Pamac { public Daemon () { alpm_config = new Alpm.Config ("/etc/pacman.conf"); databases_lock_mutex = Mutex (); - aur_results = new HashTable (str_hash, str_equal); - aur_updates_checked = false; + aur_search_results = new HashTable (str_hash, str_equal); + aur_updates_results = new Json.Array (); intern_lock = false; extern_lock = false; Timeout.add (500, check_pacman_running); @@ -91,7 +90,6 @@ namespace Pamac { if (extern_lock) { if (lockfile.query_exists () == false) { extern_lock = false; - aur_updates_checked = false; refresh_handle (); } } else { @@ -424,11 +422,11 @@ namespace Pamac { } if (search_from_aur) { Json.Array aur_pkgs; - if (aur_results.contains (search_string)) { - aur_pkgs = aur_results.get (search_string); + if (aur_search_results.contains (search_string)) { + aur_pkgs = aur_search_results.get (search_string); } else { aur_pkgs = AUR.search (splitted); - aur_results.insert (search_string, aur_pkgs); + aur_search_results.insert (search_string, aur_pkgs); } foreach (var node in aur_pkgs.get_elements ()) { var aur_pkg = node.get_object (); @@ -613,7 +611,6 @@ namespace Pamac { var infos = UpdateInfos (); UpdateInfos[] updates_infos = {}; var updates = Updates (); - updates.aur_updates = {}; unowned Alpm.Package? pkg = null; unowned Alpm.Package? candidate = null; foreach (var name in alpm_config.syncfirsts) { @@ -663,34 +660,32 @@ namespace Pamac { } } } - updates.is_syncfirst = false; updates.repos_updates = updates_infos; if (enable_aur) { - if (aur_updates_checked == false) { - // get aur updates - aur_updates = {}; - var aur_pkgs = AUR.multiinfo (local_pkgs); - int cmp; - unowned Json.Object pkg_info; - string version; - string name; - foreach (var node in aur_pkgs.get_elements ()) { - pkg_info = node.get_object (); - version = pkg_info.get_string_member ("Version"); - name = pkg_info.get_string_member ("Name"); - cmp = Alpm.pkg_vercmp (version, alpm_config.handle.localdb.get_pkg (name).version); - if (cmp == 1) { - infos.name = name; - infos.version = version; - infos.db_name = "AUR"; - infos.tarpath = pkg_info.get_string_member ("URLPath"); - infos.download_size = 0; - aur_updates += infos; - } - } - aur_updates_checked = true; + // get aur updates + if (aur_updates_results.get_length () == 0) { + aur_updates_results = AUR.multiinfo (local_pkgs); } - updates.aur_updates = aur_updates; + int cmp; + unowned Json.Object pkg_info; + string version; + string name; + updates_infos = {}; + foreach (var node in aur_updates_results.get_elements ()) { + pkg_info = node.get_object (); + version = pkg_info.get_string_member ("Version"); + name = pkg_info.get_string_member ("Name"); + cmp = Alpm.pkg_vercmp (version, alpm_config.handle.localdb.get_pkg (name).version); + if (cmp == 1) { + infos.name = name; + infos.version = version; + infos.db_name = "AUR"; + infos.tarpath = pkg_info.get_string_member ("URLPath"); + infos.download_size = 0; + updates_infos += infos; + } + } + updates.aur_updates = updates_infos; } return updates; } diff --git a/src/transaction.vala b/src/transaction.vala index 94f4b67..5ebb2ee 100644 --- a/src/transaction.vala +++ b/src/transaction.vala @@ -1368,8 +1368,12 @@ namespace Pamac { Source.remove (pulse_timeout_id); to_build.steal_all (); build_status = status; - var err = ErrorInfos (); - on_trans_commit_finished (err); + // let the time to the daemon to update packages + Timeout.add (1000, () => { + var err = ErrorInfos (); + on_trans_commit_finished (err); + return false; + }); } void on_write_pamac_config_finished (int refresh_period, bool aur_enabled, bool recurse) { diff --git a/src/tray.vala b/src/tray.vala index 791cd41..a252651 100644 --- a/src/tray.vala +++ b/src/tray.vala @@ -197,7 +197,11 @@ namespace Pamac { if (locked) { if (lockfile.query_exists () == false) { locked = false; - check_updates (); + // let the time to the daemon to update packages + Timeout.add (1000, () => { + check_updates (); + return false; + }); } } else { if (lockfile.query_exists () == true) {