move polkit check authorization in one function
This commit is contained in:
parent
cad52d23e1
commit
3a1b338a6e
214
src/daemon.vala
214
src/daemon.vala
@ -139,7 +139,8 @@ namespace Pamac {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start_get_authorization (GLib.BusName sender) {
|
private async bool check_authorization (GLib.BusName sender) {
|
||||||
|
SourceFunc callback = check_authorization.callback;
|
||||||
bool authorized = false;
|
bool authorized = false;
|
||||||
try {
|
try {
|
||||||
Polkit.Authority authority = Polkit.Authority.get_sync ();
|
Polkit.Authority authority = Polkit.Authority.get_sync ();
|
||||||
@ -156,81 +157,48 @@ namespace Pamac {
|
|||||||
authorized = result.get_is_authorized ();
|
authorized = result.get_is_authorized ();
|
||||||
} catch (GLib.Error e) {
|
} catch (GLib.Error e) {
|
||||||
stderr.printf ("%s\n", e.message);
|
stderr.printf ("%s\n", e.message);
|
||||||
} finally {
|
|
||||||
get_authorization_finished (authorized);
|
|
||||||
}
|
}
|
||||||
|
Idle.add ((owned) callback);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} catch (GLib.Error e) {
|
} catch (GLib.Error e) {
|
||||||
get_authorization_finished (authorized);
|
|
||||||
stderr.printf ("%s\n", e.message);
|
stderr.printf ("%s\n", e.message);
|
||||||
}
|
}
|
||||||
|
yield;
|
||||||
|
return authorized;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start_get_authorization (GLib.BusName sender) {
|
||||||
|
check_authorization.begin (sender, (obj, res) => {
|
||||||
|
bool authorized = check_authorization.end (res);
|
||||||
|
get_authorization_finished (authorized);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start_write_pamac_config (HashTable<string,Variant> new_pamac_conf, GLib.BusName sender) {
|
public void start_write_pamac_config (HashTable<string,Variant> new_pamac_conf, GLib.BusName sender) {
|
||||||
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
||||||
try {
|
check_authorization.begin (sender, (obj, res) => {
|
||||||
Polkit.Authority authority = Polkit.Authority.get_sync ();
|
bool authorized = check_authorization.end (res);
|
||||||
Polkit.Subject subject = Polkit.SystemBusName.new (sender);
|
if (authorized ) {
|
||||||
authority.check_authorization.begin (
|
pamac_config.write (new_pamac_conf);
|
||||||
subject,
|
pamac_config.reload ();
|
||||||
"org.manjaro.pamac.commit",
|
}
|
||||||
null,
|
|
||||||
Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
|
|
||||||
null,
|
|
||||||
(obj, res) => {
|
|
||||||
try {
|
|
||||||
var result = authority.check_authorization.end (res);
|
|
||||||
if (result.get_is_authorized ()) {
|
|
||||||
pamac_config.write (new_pamac_conf);
|
|
||||||
pamac_config.reload ();
|
|
||||||
}
|
|
||||||
} catch (GLib.Error e) {
|
|
||||||
stderr.printf ("%s\n", e.message);
|
|
||||||
} finally {
|
|
||||||
write_pamac_config_finished (pamac_config.refresh_period, pamac_config.enable_aur,
|
|
||||||
pamac_config.recurse, pamac_config.no_update_hide_icon,
|
|
||||||
pamac_config.check_aur_updates, pamac_config.no_confirm_build);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} catch (GLib.Error e) {
|
|
||||||
write_pamac_config_finished (pamac_config.refresh_period, pamac_config.enable_aur,
|
write_pamac_config_finished (pamac_config.refresh_period, pamac_config.enable_aur,
|
||||||
pamac_config.recurse, pamac_config.no_update_hide_icon,
|
pamac_config.recurse, pamac_config.no_update_hide_icon,
|
||||||
pamac_config.check_aur_updates, pamac_config.no_confirm_build);
|
pamac_config.check_aur_updates, pamac_config.no_confirm_build);
|
||||||
stderr.printf ("%s\n", e.message);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start_write_alpm_config (HashTable<string,Variant> new_alpm_conf, GLib.BusName sender) {
|
public void start_write_alpm_config (HashTable<string,Variant> new_alpm_conf, GLib.BusName sender) {
|
||||||
try {
|
check_authorization.begin (sender, (obj, res) => {
|
||||||
Polkit.Authority authority = Polkit.Authority.get_sync ();
|
bool authorized = check_authorization.end (res);
|
||||||
Polkit.Subject subject = Polkit.SystemBusName.new (sender);
|
if (authorized ) {
|
||||||
authority.check_authorization.begin (
|
alpm_config.write (new_alpm_conf);
|
||||||
subject,
|
alpm_config.reload ();
|
||||||
"org.manjaro.pamac.commit",
|
refresh_handle ();
|
||||||
null,
|
}
|
||||||
Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
|
|
||||||
null,
|
|
||||||
(obj, res) => {
|
|
||||||
try {
|
|
||||||
var result = authority.check_authorization.end (res);
|
|
||||||
if (result.get_is_authorized ()) {
|
|
||||||
alpm_config.write (new_alpm_conf);
|
|
||||||
alpm_config.reload ();
|
|
||||||
refresh_handle ();
|
|
||||||
}
|
|
||||||
} catch (GLib.Error e) {
|
|
||||||
stderr.printf ("%s\n", e.message);
|
|
||||||
} finally {
|
|
||||||
write_alpm_config_finished (get_checkspace ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} catch (GLib.Error e) {
|
|
||||||
write_alpm_config_finished (get_checkspace ());
|
write_alpm_config_finished (get_checkspace ());
|
||||||
stderr.printf ("%s\n", e.message);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool process_line (IOChannel channel, IOCondition condition, string stream_name) {
|
private bool process_line (IOChannel channel, IOCondition condition, string stream_name) {
|
||||||
@ -290,66 +258,28 @@ namespace Pamac {
|
|||||||
|
|
||||||
public void start_write_mirrors_config (HashTable<string,Variant> new_mirrors_conf, GLib.BusName sender) {
|
public void start_write_mirrors_config (HashTable<string,Variant> new_mirrors_conf, GLib.BusName sender) {
|
||||||
var mirrors_config = new Alpm.MirrorsConfig ("/etc/pacman-mirrors.conf");
|
var mirrors_config = new Alpm.MirrorsConfig ("/etc/pacman-mirrors.conf");
|
||||||
try {
|
check_authorization.begin (sender, (obj, res) => {
|
||||||
Polkit.Authority authority = Polkit.Authority.get_sync ();
|
bool authorized = check_authorization.end (res);
|
||||||
Polkit.Subject subject = Polkit.SystemBusName.new (sender);
|
if (authorized) {
|
||||||
authority.check_authorization.begin (
|
mirrors_config.write (new_mirrors_conf);
|
||||||
subject,
|
mirrors_config.reload ();
|
||||||
"org.manjaro.pamac.commit",
|
}
|
||||||
null,
|
|
||||||
Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
|
|
||||||
null,
|
|
||||||
(obj, res) => {
|
|
||||||
try {
|
|
||||||
var result = authority.check_authorization.end (res);
|
|
||||||
if (result.get_is_authorized ()) {
|
|
||||||
mirrors_config.write (new_mirrors_conf);
|
|
||||||
mirrors_config.reload ();
|
|
||||||
}
|
|
||||||
} catch (GLib.Error e) {
|
|
||||||
stderr.printf ("%s\n", e.message);
|
|
||||||
} finally {
|
|
||||||
write_mirrors_config_finished (mirrors_config.choosen_country, mirrors_config.choosen_generation_method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} catch (GLib.Error e) {
|
|
||||||
write_mirrors_config_finished (mirrors_config.choosen_country, mirrors_config.choosen_generation_method);
|
write_mirrors_config_finished (mirrors_config.choosen_country, mirrors_config.choosen_generation_method);
|
||||||
stderr.printf ("%s\n", e.message);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start_set_pkgreason (string pkgname, uint reason, GLib.BusName sender) {
|
public void start_set_pkgreason (string pkgname, uint reason, GLib.BusName sender) {
|
||||||
try {
|
check_authorization.begin (sender, (obj, res) => {
|
||||||
Polkit.Authority authority = Polkit.Authority.get_sync ();
|
bool authorized = check_authorization.end (res);
|
||||||
Polkit.Subject subject = Polkit.SystemBusName.new (sender);
|
if (authorized) {
|
||||||
authority.check_authorization.begin (
|
unowned Alpm.Package? pkg = alpm_config.handle.localdb.get_pkg (pkgname);
|
||||||
subject,
|
if (pkg != null) {
|
||||||
"org.manjaro.pamac.commit",
|
pkg.reason = (Alpm.Package.Reason) reason;
|
||||||
null,
|
refresh_handle ();
|
||||||
Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
|
|
||||||
null,
|
|
||||||
(obj, res) => {
|
|
||||||
try {
|
|
||||||
var result = authority.check_authorization.end (res);
|
|
||||||
if (result.get_is_authorized ()) {
|
|
||||||
unowned Alpm.Package? pkg = alpm_config.handle.localdb.get_pkg (pkgname);
|
|
||||||
if (pkg != null) {
|
|
||||||
pkg.reason = (Alpm.Package.Reason) reason;
|
|
||||||
refresh_handle ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (GLib.Error e) {
|
|
||||||
stderr.printf ("%s\n", e.message);
|
|
||||||
} finally {
|
|
||||||
set_pkgreason_finished ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
} catch (GLib.Error e) {
|
|
||||||
set_pkgreason_finished ();
|
set_pkgreason_finished ();
|
||||||
stderr.printf ("%s\n", e.message);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refresh () {
|
private void refresh () {
|
||||||
@ -1097,44 +1027,23 @@ namespace Pamac {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start_trans_commit (GLib.BusName sender) {
|
public void start_trans_commit (GLib.BusName sender) {
|
||||||
var err = ErrorInfos ();
|
check_authorization.begin (sender, (obj, res) => {
|
||||||
try {
|
bool authorized = check_authorization.end (res);
|
||||||
Polkit.Authority authority = Polkit.Authority.get_sync ();
|
if (authorized) {
|
||||||
Polkit.Subject subject = Polkit.SystemBusName.new (sender);
|
try {
|
||||||
authority.check_authorization.begin (
|
thread_pool.add (new AlpmAction (trans_commit));
|
||||||
subject,
|
} catch (ThreadError e) {
|
||||||
"org.manjaro.pamac.commit",
|
stderr.printf ("Thread Error %s\n", e.message);
|
||||||
null,
|
|
||||||
Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
|
|
||||||
null,
|
|
||||||
(obj, res) => {
|
|
||||||
try {
|
|
||||||
var result = authority.check_authorization.end (res);
|
|
||||||
if (result.get_is_authorized ()) {
|
|
||||||
thread_pool.add (new AlpmAction (trans_commit));
|
|
||||||
} else {
|
|
||||||
err.message = _("Authentication failed");
|
|
||||||
trans_release ();
|
|
||||||
refresh_handle ();
|
|
||||||
trans_commit_finished (err);
|
|
||||||
intern_lock = false;
|
|
||||||
}
|
|
||||||
} catch (GLib.Error e) {
|
|
||||||
stderr.printf ("%s\n", e.message);
|
|
||||||
trans_release ();
|
|
||||||
refresh_handle ();
|
|
||||||
trans_commit_finished (err);
|
|
||||||
intern_lock = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
} else {
|
||||||
} catch (GLib.Error e) {
|
var err = ErrorInfos ();
|
||||||
stderr.printf ("%s\n", e.message);
|
err.message = _("Authentication failed");
|
||||||
trans_release ();
|
trans_release ();
|
||||||
refresh_handle ();
|
refresh_handle ();
|
||||||
trans_commit_finished (err);
|
trans_commit_finished (err);
|
||||||
intern_lock = false;
|
intern_lock = false;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public int trans_release () {
|
public int trans_release () {
|
||||||
@ -1144,9 +1053,14 @@ namespace Pamac {
|
|||||||
public void trans_cancel () {
|
public void trans_cancel () {
|
||||||
if (alpm_config.handle.trans_interrupt () == 0) {
|
if (alpm_config.handle.trans_interrupt () == 0) {
|
||||||
// a transaction is being interrupted
|
// a transaction is being interrupted
|
||||||
|
// it will end the normal way
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var err = ErrorInfos ();
|
||||||
trans_release ();
|
trans_release ();
|
||||||
|
refresh_handle ();
|
||||||
|
trans_commit_finished (err);
|
||||||
|
intern_lock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DBus (no_reply = true)]
|
[DBus (no_reply = true)]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef ALPM_VALA_H
|
#ifndef ALPM_UTIL_H
|
||||||
#define ALPM_VALA_H
|
#define ALPM_UTIL_H
|
||||||
|
|
||||||
#include <alpm.h>
|
#include <alpm.h>
|
||||||
|
|
||||||
@ -20,4 +20,4 @@ void* alpm_list_iterator_next_value (alpm_list_iterator_t *iter);
|
|||||||
alpm_pkg_t* alpm_pkg_load_file (alpm_handle_t *handle, const char *filename, int full, alpm_siglevel_t level);
|
alpm_pkg_t* alpm_pkg_load_file (alpm_handle_t *handle, const char *filename, int full, alpm_siglevel_t level);
|
||||||
alpm_list_t* alpm_pkg_get_files_list (alpm_pkg_t* pkg);
|
alpm_list_t* alpm_pkg_get_files_list (alpm_pkg_t* pkg);
|
||||||
|
|
||||||
#endif //!ALPM_VALA_H
|
#endif //!ALPM_UTIL_H
|
||||||
|
Loading…
Reference in New Issue
Block a user