diff --git a/src/transaction.vala b/src/transaction.vala index 9ca85255a447fe8d9d5310667f3480c4ec7ae87a..7ae3e62a453e5e93b97ea1ef8f5a6963a2ed938d 100644 --- a/src/transaction.vala +++ b/src/transaction.vala @@ -107,7 +107,11 @@ namespace Pamac { } public void quit_daemon () { - transaction_interface.quit_daemon (); + try { + transaction_interface.quit_daemon (); + } catch (Error e) { + critical ("quit_daemon: %s\n", e.message); + } } protected virtual bool ask_commit (TransactionSummary summary) { @@ -158,7 +162,7 @@ namespace Pamac { } } } - } catch (GLib.Error e) { + } catch (Error e) { critical ("%s\n", e.message); } return (owned) files; @@ -175,19 +179,33 @@ namespace Pamac { } ErrorInfos get_current_error () { - return transaction_interface.get_current_error (); + try { + return transaction_interface.get_current_error (); + } catch (Error e) { + var error = ErrorInfos (); + error.message = e.message; + return error; + } } public bool get_authorization () { - return transaction_interface.get_authorization (); + try { + return transaction_interface.get_authorization (); + } catch (Error e) { + emit_error ("Daemon Error", {"get_authorization: %s".printf (e.message)}); + } + return false; } public void generate_mirrors_list (string country) { - string country_copy = country; emit_action (dgettext (null, "Refreshing mirrors list") + "..."); important_details_outpout (false); transaction_interface.generate_mirrors_list_data.connect (on_generate_mirrors_list_data); - transaction_interface.generate_mirrors_list (country_copy); + try { + transaction_interface.generate_mirrors_list (country); + } catch (Error e) { + emit_error ("Daemon Error", {"generate_mirrors_list: %s".printf (e.message)}); + } transaction_interface.generate_mirrors_list_data.disconnect (on_generate_mirrors_list_data); database.refresh (); } @@ -204,34 +222,49 @@ namespace Pamac { while (iter.next (out name, null)) { array.add (name); } - bool success = transaction_interface.clean_cache (array.data); - if (!success) { - handle_error (get_current_error ()); + try { + bool success = transaction_interface.clean_cache (array.data); + if (!success) { + handle_error (get_current_error ()); + } + } catch (Error e) { + emit_error ("Daemon Error", {"clean_cache: %s".printf (e.message)}); } } public void clean_build_files () { - bool success = transaction_interface.clean_build_files (database.config.aur_build_dir); + try { + bool success = transaction_interface.clean_build_files (database.config.aur_build_dir); + if (!success) { + handle_error (get_current_error ()); + } + } catch (Error e) { + emit_error ("Daemon Error", {"clean_build_files: %s".printf (e.message)}); + } // recreate buildir here to have good permissions try { Process.spawn_command_line_sync ("mkdir -p %s".printf (database.config.aur_build_dir)); } catch (SpawnError e) { - stderr.printf ("SpawnError: %s\n", e.message); - } - if (!success) { - handle_error (get_current_error ()); + emit_error ("SpawnError: %s".printf (e.message), {}); } } public bool set_pkgreason (string pkgname, uint reason) { - string pkgname_copy = pkgname; - bool success = transaction_interface.set_pkgreason (pkgname_copy, reason); + try { + return transaction_interface.set_pkgreason (pkgname, reason); + } catch (Error e) { + emit_error ("Daemon Error", {"set_pkgreason: %s".printf (e.message)}); + } database.refresh (); - return success; + return false; } public void download_updates () { - transaction_interface.download_updates (); + try { + transaction_interface.download_updates (); + } catch (Error e) { + emit_error ("Daemon Error", {"download_updates: %s".printf (e.message)}); + } } void compute_aur_build_list () { @@ -316,7 +349,7 @@ namespace Pamac { dep_to_check.add (filename); } } - } catch (GLib.Error e) { + } catch (Error e) { critical ("%s\n", e.message); } continue; @@ -565,7 +598,7 @@ namespace Pamac { if (global_validpgpkeys.length () > 0) { yield check_signature (pkgname, global_validpgpkeys); } - } catch (GLib.Error e) { + } catch (Error e) { critical ("%s\n", e.message); continue; } @@ -617,6 +650,10 @@ namespace Pamac { } public bool run () { + if (transaction_interface == null) { + emit_error ("Daemon Error", {"failed to connect to dbus daemon"}); + return false; + } bool success = true; if (sysupgrading || to_install.length > 0 || @@ -733,7 +770,11 @@ namespace Pamac { connecting_signals (); add_optdeps (); if (sysupgrading) { - transaction_interface.set_enable_downgrade (database.config.enable_downgrade); + try { + transaction_interface.set_enable_downgrade (database.config.enable_downgrade); + } catch (Error e) { + emit_error ("Daemon Error", {"set_enable_downgrade: %s".printf (e.message)}); + } if (database.config.check_aur_updates) { // add aur updates var aur_updates = database.get_aur_updates (); @@ -758,12 +799,23 @@ namespace Pamac { return false; } } - return transaction_interface.trans_run (); + try { + return transaction_interface.trans_run (); + } catch (Error e) { + emit_error ("Daemon Error", {"trans_run: %s".printf (e.message)}); + return false; + } } bool wait_for_lock () { bool success = true; - if (transaction_interface.get_lock ()) { + try { + success = transaction_interface.get_lock (); + } catch (Error e) { + emit_error ("Daemon Error", {"get_lock: %s".printf (e.message)}); + return false; + } + if (success) { return true; } else { waiting = true; @@ -777,7 +829,12 @@ namespace Pamac { loop.quit (); return false; } - waiting = !transaction_interface.get_lock (); + try { + waiting = !transaction_interface.get_lock (); + } catch (Error e) { + emit_error ("Daemon Error", {"get_lock: %s".printf (e.message)}); + return false; + } if (waiting) { pass++; // wait 10 min max @@ -798,47 +855,87 @@ namespace Pamac { } public void set_flags (int flags) { - transaction_interface.set_trans_flags (flags); + try { + transaction_interface.set_trans_flags (flags); + } catch (Error e) { + emit_error ("Daemon Error", {"set_trans_flags: %s".printf (e.message)}); + } } public void add_pkg_to_install (string name) { to_install.add (name); - transaction_interface.add_pkg_to_install (name); + try { + transaction_interface.add_pkg_to_install (name); + } catch (Error e) { + emit_error ("Daemon Error", {"add_pkg_to_install: %s".printf (e.message)}); + } } public void add_pkg_to_remove (string name) { to_remove.add (name); - transaction_interface.add_pkg_to_remove (name); + try { + transaction_interface.add_pkg_to_remove (name); + } catch (Error e) { + emit_error ("Daemon Error", {"add_pkg_to_remove: %s".printf (e.message)}); + } } public void add_path_to_load (string path) { to_load.add (path); - transaction_interface.add_path_to_load (path); + try { + transaction_interface.add_path_to_load (path); + } catch (Error e) { + emit_error ("Daemon Error", {"add_path_to_load: %s".printf (e.message)}); + } } public void add_aur_pkg_to_build (string name) { to_build.add (name); - transaction_interface.add_aur_pkg_to_build (name); + try { + transaction_interface.add_aur_pkg_to_build (name); + } catch (Error e) { + emit_error ("Daemon Error", {"add_aur_pkg_to_build: %s".printf (e.message)}); + } } public void add_temporary_ignore_pkg (string name) { temporary_ignorepkgs.add (name); - transaction_interface.add_temporary_ignore_pkg (name); + try { + transaction_interface.add_temporary_ignore_pkg (name); + } catch (Error e) { + emit_error ("Daemon Error", {"add_temporary_ignore_pkg: %s".printf (e.message)}); + } } public void add_overwrite_file (string glob) { - transaction_interface.add_overwrite_file (glob); + try { + transaction_interface.add_overwrite_file (glob); + } catch (Error e) { + emit_error ("Daemon Error", {"add_overwrite_file: %s".printf (e.message)}); + } } public void add_pkg_to_mark_as_dep (string name) { - transaction_interface.add_pkg_to_mark_as_dep (name); + try { + transaction_interface.add_pkg_to_mark_as_dep (name); + } catch (Error e) { + emit_error ("Daemon Error", {"add_pkg_to_mark_as_dep: %s".printf (e.message)}); + } } public void add_pkgs_to_upgrade (bool force_refresh) { if (force_refresh) { - transaction_interface.set_force_refresh (); + try { + transaction_interface.set_force_refresh (); + } catch (Error e) { + emit_error ("Daemon Error", {"set_force_refresh: %s".printf (e.message)}); + } + } + try { + transaction_interface.set_sysupgrade (); + } catch (Error e) { + emit_error ("Daemon Error", {"set_sysupgrade: %s".printf (e.message)}); } - transaction_interface.set_sysupgrade (); sysupgrading = true; } @@ -865,14 +962,23 @@ namespace Pamac { } snap_to_install.remove_all (); snap_to_remove.remove_all (); - return transaction_interface.snap_trans_run (snap_to_install_array.data, snap_to_remove_array.data); + try { + return transaction_interface.snap_trans_run (snap_to_install_array.data, snap_to_remove_array.data); + } catch (Error e) { + emit_error ("Daemon Error", {"snap_trans_run: %s".printf (e.message)}); + return false; + } } public bool snap_switch_channel (string snap_name, string channel) { connecting_signals (); - bool success = transaction_interface.snap_switch_channel (snap_name, channel); + try { + return transaction_interface.snap_switch_channel (snap_name, channel); + } catch (Error e) { + emit_error ("Daemon Error", {"snap_switch_channel: %s".printf (e.message)}); + } disconnecting_signals (); - return success; + return false; } #endif @@ -1013,9 +1119,14 @@ namespace Pamac { foreach (unowned string name in built_pkgs) { add_path_to_load (name); } - transaction_interface.set_no_confirm_commit (); - emit_script_output (""); - success = transaction_interface.trans_run (); + try { + transaction_interface.set_no_confirm_commit (); + emit_script_output (""); + success = transaction_interface.trans_run (); + } catch (Error e) { + emit_error ("Daemon Error", {"trans_run: %s".printf (e.message)}); + success = false; + } if (!success) { break; } @@ -1035,7 +1146,11 @@ namespace Pamac { } else if (waiting) { waiting = false; } else { - transaction_interface.trans_cancel (); + try { + transaction_interface.trans_cancel (); + } catch (Error e) { + emit_error ("Daemon Error", {"trans_cancel: %s".printf (e.message)}); + } } emit_script_output (""); emit_action (dgettext (null, "Transaction cancelled") + "."); diff --git a/src/transaction_interface.vala b/src/transaction_interface.vala index 6033ebca11b094d0472500f4511966ce486c6cee..f55d0279fc74d8ae0c5cdcce9bb4368b7411dac8 100644 --- a/src/transaction_interface.vala +++ b/src/transaction_interface.vala @@ -19,29 +19,29 @@ namespace Pamac { internal interface TransactionInterface : Object { - public abstract ErrorInfos get_current_error (); - public abstract bool get_lock (); - public abstract bool get_authorization (); - public abstract void generate_mirrors_list (string country); - public abstract bool clean_cache (string[] filenames); - public abstract bool clean_build_files (string aur_build_dir); - public abstract bool set_pkgreason (string pkgname, uint reason); - public abstract void download_updates (); - public abstract void set_trans_flags (int flags); - public abstract void add_pkg_to_install (string name); - public abstract void add_pkg_to_remove (string name); - public abstract void add_path_to_load (string path); - public abstract void add_aur_pkg_to_build (string name); - public abstract void add_temporary_ignore_pkg (string name); - public abstract void add_overwrite_file (string glob); - public abstract void add_pkg_to_mark_as_dep (string name); - public abstract void set_sysupgrade (); - public abstract void set_enable_downgrade (bool downgrade); - public abstract void set_no_confirm_commit (); - public abstract void set_force_refresh (); - public abstract bool trans_run (); - public abstract void trans_cancel (); - public abstract void quit_daemon (); + public abstract ErrorInfos get_current_error () throws Error; + public abstract bool get_lock () throws Error; + public abstract bool get_authorization () throws Error; + public abstract void generate_mirrors_list (string country) throws Error; + public abstract bool clean_cache (string[] filenames) throws Error; + public abstract bool clean_build_files (string aur_build_dir) throws Error; + public abstract bool set_pkgreason (string pkgname, uint reason) throws Error; + public abstract void download_updates () throws Error; + public abstract void set_trans_flags (int flags) throws Error; + public abstract void add_pkg_to_install (string name) throws Error; + public abstract void add_pkg_to_remove (string name) throws Error; + public abstract void add_path_to_load (string path) throws Error; + public abstract void add_aur_pkg_to_build (string name) throws Error; + public abstract void add_temporary_ignore_pkg (string name) throws Error; + public abstract void add_overwrite_file (string glob) throws Error; + public abstract void add_pkg_to_mark_as_dep (string name) throws Error; + public abstract void set_sysupgrade () throws Error; + public abstract void set_enable_downgrade (bool downgrade) throws Error; + public abstract void set_no_confirm_commit () throws Error; + public abstract void set_force_refresh () throws Error; + public abstract bool trans_run () throws Error; + public abstract void trans_cancel () throws Error; + public abstract void quit_daemon () throws Error; public signal int choose_provider (string depend, string[] providers); public signal void compute_aur_build_list (); public signal bool ask_edit_build_files (TransactionSummaryStruct summary); @@ -60,8 +60,8 @@ namespace Pamac { public signal void important_details_outpout (bool must_show); public signal void generate_mirrors_list_data (string line); #if ENABLE_SNAP - public abstract bool snap_trans_run (string[] to_install, string[] to_remove); - public abstract bool snap_switch_channel (string snap_name, string channel); + public abstract bool snap_trans_run (string[] to_install, string[] to_remove) throws Error; + public abstract bool snap_switch_channel (string snap_name, string channel) throws Error; #endif } } diff --git a/src/transaction_interface_daemon.vala b/src/transaction_interface_daemon.vala index 98d031beaf3499b6ad29aae71b323ab39f59ecb9..e04fa95a460ccd17dfc56654c1464daecae5f0c8 100644 --- a/src/transaction_interface_daemon.vala +++ b/src/transaction_interface_daemon.vala @@ -33,38 +33,38 @@ namespace Pamac { public TransactionInterfaceDaemon (Config config) { loop = new MainLoop (); - connecting_system_daemon (config); - connecting_dbus_signals (); + try { + connecting_system_daemon (config); + connecting_dbus_signals (); + } catch (Error e) { + critical ("failed to connect to dbus daemon: %s\n", e.message); + } } - ErrorInfos get_current_error () { + ErrorInfos get_current_error () throws Error { try { return system_daemon.get_current_error (); } catch (Error e) { - critical ("get_current_error: %s\n", e.message); - return ErrorInfos (); + throw e; } } - public bool get_lock () { - bool locked = false; + public bool get_lock () throws Error { try { - locked = system_daemon.get_lock (); + return system_daemon.get_lock (); } catch (Error e) { - critical ("get_lock: %s\n", e.message); + throw e; } - return locked; } - public bool get_authorization () { + public bool get_authorization () throws Error { try { system_daemon.start_get_authorization (); loop.run (); return get_authorization_authorized; } catch (Error e) { - critical ("start_get_authorization: %s\n", e.message); + throw e; } - return false; } void on_get_authorization_finished (bool authorized) { @@ -73,12 +73,12 @@ namespace Pamac { } - public void generate_mirrors_list (string country) { + public void generate_mirrors_list (string country) throws Error { try { system_daemon.start_generate_mirrors_list (country); loop.run (); } catch (Error e) { - critical ("generate_mirrors_list: %s\n", e.message); + throw e; } } @@ -86,15 +86,14 @@ namespace Pamac { loop.quit (); } - public bool clean_cache (string[] filenames) { + public bool clean_cache (string[] filenames) throws Error { try { system_daemon.start_clean_cache (filenames); loop.run (); return clean_cache_success; } catch (Error e) { - critical ("clean_cache: %s\n", e.message); + throw e; } - return false; } void on_clean_cache_finished (bool success) { @@ -102,15 +101,14 @@ namespace Pamac { loop.quit (); } - public bool clean_build_files (string aur_build_dir) { + public bool clean_build_files (string aur_build_dir) throws Error { try { system_daemon.start_clean_build_files (aur_build_dir); loop.run (); return clean_build_files_success; } catch (Error e) { - critical ("clean_build_files: %s\n", e.message); + throw e; } - return false; } void on_clean_clean_build_files_finished (bool success) { @@ -118,15 +116,14 @@ namespace Pamac { loop.quit (); } - public bool set_pkgreason (string pkgname, uint reason) { + public bool set_pkgreason (string pkgname, uint reason) throws Error { try { system_daemon.start_set_pkgreason (pkgname, reason); loop.run (); return set_pkgreason_success; } catch (Error e) { - critical ("set_pkgreason: %s\n", e.message); + throw e; } - return false; } void on_set_pkgreason_finished (bool success) { @@ -134,12 +131,12 @@ namespace Pamac { loop.quit (); } - public void download_updates () { + public void download_updates () throws Error { try { system_daemon.start_download_updates (); loop.run (); } catch (Error e) { - critical ("start_downloading_updates: %s\n", e.message); + throw e; } } @@ -147,103 +144,103 @@ namespace Pamac { loop.quit (); } - public void set_trans_flags (int flags) { + public void set_trans_flags (int flags) throws Error { try { system_daemon.set_trans_flags (flags); } catch (Error e) { - critical ("set_trans_flags: %s\n", e.message); + throw e; } } - public void set_no_confirm_commit () { + public void set_no_confirm_commit () throws Error { try { system_daemon.set_no_confirm_commit (); } catch (Error e) { - critical ("set_no_confirm_commit: %s\n", e.message); + throw e; } } - public void add_pkg_to_install (string name) { + public void add_pkg_to_install (string name) throws Error { try { system_daemon.add_pkg_to_install (name); } catch (Error e) { - critical ("add_pkg_to_install: %s\n", e.message); + throw e; } } - public void add_pkg_to_remove (string name) { + public void add_pkg_to_remove (string name) throws Error { try { system_daemon.add_pkg_to_remove (name); } catch (Error e) { - critical ("add_pkg_to_remove: %s\n", e.message); + throw e; } } - public void add_path_to_load (string path) { + public void add_path_to_load (string path) throws Error { try { system_daemon.add_path_to_load (path); } catch (Error e) { - critical ("add_path_to_load: %s\n", e.message); + throw e; } } - public void add_aur_pkg_to_build (string name) { + public void add_aur_pkg_to_build (string name) throws Error { try { system_daemon.add_aur_pkg_to_build (name); } catch (Error e) { - critical ("add_pkg_to_build: %s\n", e.message); + throw e; } } - public void add_temporary_ignore_pkg (string name) { + public void add_temporary_ignore_pkg (string name) throws Error { try { system_daemon.add_temporary_ignore_pkg (name); } catch (Error e) { - critical ("add_temporary_ignore_pkg: %s\n", e.message); + throw e; } } - public void add_overwrite_file (string glob) { + public void add_overwrite_file (string glob) throws Error { try { system_daemon.add_overwrite_file (glob); } catch (Error e) { - critical ("add_overwrite_file: %s\n", e.message); + throw e; } } - public void add_pkg_to_mark_as_dep (string name) { + public void add_pkg_to_mark_as_dep (string name) throws Error { try { system_daemon.add_pkg_to_mark_as_dep (name); } catch (Error e) { - critical ("add_pkg_to_mark_as_dep: %s\n", e.message); + throw e; } } - public void set_sysupgrade () { + public void set_sysupgrade () throws Error { try { system_daemon.set_sysupgrade (); } catch (Error e) { - critical ("set_sysupgrade: %s\n", e.message); + throw e; } } - public void set_enable_downgrade (bool downgrade) { + public void set_enable_downgrade (bool downgrade) throws Error { try { system_daemon.set_enable_downgrade (downgrade); } catch (Error e) { - critical ("set_enable_downgrade: %s\n", e.message); + throw e; } } - public void set_force_refresh () { + public void set_force_refresh () throws Error { try { system_daemon.set_force_refresh (); } catch (Error e) { - critical ("set_force_refresh: %s\n", e.message); + throw e; } } - public bool trans_run () { + public bool trans_run () throws Error { try { system_daemon.trans_run_finished.connect ((success) => { trans_run_success = success; @@ -253,29 +250,27 @@ namespace Pamac { loop.run (); return trans_run_success; } catch (Error e) { - critical ("start_trans_run: %s\n", e.message); + throw e; } - return false; } - public void trans_cancel () { + public void trans_cancel () throws Error { try { system_daemon.trans_cancel (); } catch (Error e) { - critical ("trans_cancel: %s\n", e.message); + throw e; } } #if ENABLE_SNAP - public bool snap_trans_run (string[] to_install, string[] to_remove) { + public bool snap_trans_run (string[] to_install, string[] to_remove) throws Error { try { system_daemon.start_snap_trans_run (to_install, to_remove); loop.run (); return snap_trans_run_success; } catch (Error e) { - critical ("start_snap_trans_run: %s\n", e.message); + throw e; } - return false; } void on_snap_trans_run_finished (bool success) { @@ -283,15 +278,14 @@ namespace Pamac { loop.quit (); } - public bool snap_switch_channel (string snap_name, string channel) { + public bool snap_switch_channel (string snap_name, string channel) throws Error { try { system_daemon.start_snap_switch_channel (snap_name, channel); loop.run (); return snap_switch_channel_success; } catch (Error e) { - critical ("start_snap_switch_channel: %s\n", e.message); + throw e; } - return false; } void on_snap_switch_channel_finished (bool success) { @@ -300,11 +294,11 @@ namespace Pamac { } #endif - public void quit_daemon () { + public void quit_daemon () throws Error { try { system_daemon.quit (); } catch (Error e) { - critical ("quit: %s\n", e.message); + throw e; } } @@ -353,14 +347,14 @@ namespace Pamac { } } - void connecting_system_daemon (Config config) { + void connecting_system_daemon (Config config) throws Error { if (system_daemon == null) { try { system_daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac.daemon", "/org/manjaro/pamac/daemon"); // Set environment variables system_daemon.set_environment_variables (config.environment_variables); } catch (Error e) { - stderr.printf ("set_environment_variables: %s\n", e.message); + throw e; } } } diff --git a/src/transaction_interface_root.vala b/src/transaction_interface_root.vala index 338098ea68e0012f6b8d8f860befc1b8097463e4..ac8a5f1268d0c4b13657b1e58f047d49728690da 100644 --- a/src/transaction_interface_root.vala +++ b/src/transaction_interface_root.vala @@ -64,7 +64,12 @@ namespace Pamac { important_details_outpout (must_show); }); alpm_utils.get_authorization.connect (() => { - return get_authorization (); + try { + return get_authorization (); + } catch (Error e) { + critical ("get_authorization: %s\n", e.message); + } + return false; }); alpm_utils.ask_commit.connect ((summary) => { return ask_commit (summary);