diff --git a/src/daemon.vala b/src/daemon.vala index 6961836..26eb5d5 100644 --- a/src/daemon.vala +++ b/src/daemon.vala @@ -126,6 +126,7 @@ namespace Pamac { public Timer timer; public Cancellable cancellable; public Curl.Easy curl; + private bool authorized; public signal void emit_event (uint primary_event, uint secondary_event, string[] details); public signal void emit_providers (string depend, string[] providers); @@ -164,6 +165,7 @@ namespace Pamac { create_thread_pool (); cancellable = new Cancellable (); curl = new Curl.Easy (); + authorized = false; } public void set_environment_variables (HashTable variables) { @@ -261,8 +263,10 @@ namespace Pamac { } private async bool check_authorization (GLib.BusName sender) { + if (authorized) { + return true; + } SourceFunc callback = check_authorization.callback; - bool authorized = false; try { Polkit.Authority authority = Polkit.Authority.get_sync (); Polkit.Subject subject = Polkit.SystemBusName.new (sender); @@ -286,6 +290,11 @@ namespace Pamac { } catch (GLib.Error e) { stderr.printf ("%s\n", e.message); } + if (!authorized) { + current_error = ErrorInfos () { + message = _("Authentication failed") + }; + } return authorized; } @@ -348,10 +357,6 @@ namespace Pamac { } catch (ThreadError e) { stderr.printf ("Thread Error %s\n", e.message); } - } else { - current_error = ErrorInfos () { - message = _("Authentication failed") - }; } }); } @@ -372,10 +377,6 @@ namespace Pamac { } catch (Error e) { stderr.printf ("Error: %s\n", e.message); } - } else { - current_error = ErrorInfos () { - message = _("Authentication failed") - }; } }); } @@ -2152,9 +2153,6 @@ namespace Pamac { stderr.printf ("Thread Error %s\n", e.message); } } else { - current_error = ErrorInfos () { - message = _("Authentication failed") - }; trans_release (); trans_commit_finished (false); } diff --git a/src/transaction.vala b/src/transaction.vala index 118316c..a827456 100644 --- a/src/transaction.vala +++ b/src/transaction.vala @@ -263,7 +263,8 @@ namespace Pamac { public async void run_preferences_dialog () { SourceFunc callback = run_preferences_dialog.callback; - ulong handler_id = daemon.get_authorization_finished.connect ((authorized) => { + check_authorization.begin ((obj, res) => { + bool authorized = check_authorization.end (res); if (authorized) { var preferences_dialog = new PreferencesDialog (this); preferences_dialog.run (); @@ -274,9 +275,7 @@ namespace Pamac { } Idle.add ((owned) callback); }); - start_get_authorization (); yield; - daemon.disconnect (handler_id); } public void run_about_dialog () { @@ -300,12 +299,21 @@ namespace Pamac { } } - void start_get_authorization () { + async bool check_authorization () { + SourceFunc callback = check_authorization.callback; + bool authorized = false; + ulong handler_id = daemon.get_authorization_finished.connect ((authorized_) => { + authorized = authorized_; + Idle.add ((owned) callback); + }); try { daemon.start_get_authorization (); } catch (IOError e) { stderr.printf ("IOError: %s\n", e.message); } + yield; + daemon.disconnect (handler_id); + return authorized; } public void start_write_pamac_config (HashTable new_pamac_conf) { @@ -1634,7 +1642,15 @@ namespace Pamac { if (to_build_queue.get_length () != 0) { show_in_term (""); clear_previous_lists (); - build_aur_packages.begin (); + check_authorization.begin ((obj, res) => { + bool authorized = check_authorization.end (res); + if (authorized) { + build_aur_packages.begin (); + } else { + to_build_queue.clear (); + on_trans_commit_finished (false); + } + }); } else { clear_previous_lists (); if (sysupgrade_after_trans) { @@ -1667,6 +1683,7 @@ namespace Pamac { to_load.remove_all (); } clear_previous_lists (); + to_build_queue.clear (); warning_textbuffer = new StringBuilder (); handle_error (err); }