diff --git a/src/Core/FlatpakBackend.vala b/src/Core/FlatpakBackend.vala index ef843fdda..55aa08dc2 100644 --- a/src/Core/FlatpakBackend.vala +++ b/src/Core/FlatpakBackend.vala @@ -1575,15 +1575,15 @@ public class AppCenterCore.FlatpakBackend : Object { var bundle = package.component.get_bundle (AppStream.BundleKind.FLATPAK); if (bundle == null) { - job.result = Value (typeof (bool)); - job.result.set_boolean (false); + warning ("Failed to install package: component %s has no flatpak bundle", package.component.get_name ()); + job.error = new IOError.FAILED (_("Component has no flatpak bundle")); job.results_ready (); return; } if (fp_package == null || fp_package.installation == null) { critical ("Error getting flatpak installation"); - job.result = false; + job.error = new IOError.FAILED (_("Error getting flatpak installation")); job.results_ready (); return; } @@ -1594,8 +1594,7 @@ public class AppCenterCore.FlatpakBackend : Object { transaction.add_default_dependency_sources (); } catch (Error e) { critical ("Error creating transaction for flatpak install: %s", e.message); - job.result = Value (typeof (bool)); - job.result.set_boolean (false); + job.error = e; job.results_ready (); return; } @@ -1604,8 +1603,6 @@ public class AppCenterCore.FlatpakBackend : Object { transaction.add_install (package.component.get_origin (), bundle.get_id (), null); } catch (Error e) { critical ("Error setting up transaction for flatpak install: %s", e.message); - job.result = Value (typeof (bool)); - job.result.set_boolean (false); job.error = e; job.results_ready (); return; @@ -1634,13 +1631,8 @@ public class AppCenterCore.FlatpakBackend : Object { }); }); - bool success = false; - transaction.operation_error.connect ((operation, e, detail) => { warning ("Flatpak installation failed: %s (detail: %d)", e.message, detail); - if (e is GLib.IOError.CANCELLED) { - success = true; - } // Only cancel the transaction if this is fatal var should_continue = detail == Flatpak.TransactionErrorDetails.NON_FATAL; @@ -1659,25 +1651,18 @@ public class AppCenterCore.FlatpakBackend : Object { current_operation = 0; try { - success = transaction.run (cancellable); + transaction.run (cancellable); } catch (Error e) { - if (e is GLib.IOError.CANCELLED) { - success = true; - } else { - success = false; - // Don't overwrite any previous errors as the first is probably most important - if (job.error != null) { - job.error = e; - } + // Don't overwrite any previous errors as the first is probably most important + if (job.error == null) { + job.error = e; } } - job.result = Value (typeof (bool)); - job.result.set_boolean (success); job.results_ready (); } - public async bool install_package (Package package, ChangeInformation change_info) throws GLib.Error { + public async void install_package (Package package, ChangeInformation change_info) throws GLib.Error { var job_args = new InstallPackageArgs (); job_args.package = package; job_args.change_info = change_info; @@ -1686,8 +1671,6 @@ public class AppCenterCore.FlatpakBackend : Object { if (job.error != null) { throw job.error; } - - return job.result.get_boolean (); } private void remove_package_internal (Job job) { @@ -1699,8 +1682,8 @@ public class AppCenterCore.FlatpakBackend : Object { unowned var bundle = package.component.get_bundle (AppStream.BundleKind.FLATPAK); if (bundle == null) { - job.result = Value (typeof (bool)); - job.result.set_boolean (false); + warning ("Failed to remove package: component %s has no flatpak bundle", package.component.get_name ()); + job.error = new IOError.FAILED (_("Component has no flatpak bundle")); job.results_ready (); return; } @@ -1710,15 +1693,14 @@ public class AppCenterCore.FlatpakBackend : Object { flatpak_ref = Flatpak.Ref.parse (bundle.get_id ()); } catch (Error e) { critical ("Error parsing flatpak ref for removal: %s", e.message); - job.result = Value (typeof (bool)); - job.result.set_boolean (false); + job.error = e; job.results_ready (); return; } if (fp_package == null || fp_package.installation == null) { critical ("Error getting flatpak installation for removal"); - job.result = false; + job.error = new IOError.FAILED (_("Error getting flatpak installation for removal")); job.results_ready (); return; } @@ -1729,8 +1711,7 @@ public class AppCenterCore.FlatpakBackend : Object { transaction.add_default_dependency_sources (); } catch (Error e) { critical ("Error creating transaction for flatpak removal: %s", e.message); - job.result = Value (typeof (bool)); - job.result.set_boolean (false); + job.error = e; job.results_ready (); return; } @@ -1739,8 +1720,6 @@ public class AppCenterCore.FlatpakBackend : Object { transaction.add_uninstall (bundle.get_id ()); } catch (Error e) { critical ("Error setting up transaction for flatpak removal: %s", e.message); - job.result = Value (typeof (bool)); - job.result.set_boolean (false); job.error = e; job.results_ready (); return; @@ -1763,13 +1742,8 @@ public class AppCenterCore.FlatpakBackend : Object { }); }); - bool success = false; - transaction.operation_error.connect ((operation, e, detail) => { warning ("Flatpak removal failed: %s (detail: %d)", e.message, detail); - if (e is GLib.IOError.CANCELLED) { - success = true; - } // Only cancel the transaction if this is fatal var should_continue = detail == Flatpak.TransactionErrorDetails.NON_FATAL; @@ -1788,25 +1762,18 @@ public class AppCenterCore.FlatpakBackend : Object { current_operation = 0; try { - success = transaction.run (cancellable); + transaction.run (cancellable); } catch (Error e) { - if (e is GLib.IOError.CANCELLED) { - success = true; - } else { - success = false; - // Don't overwrite any previous errors as the first is probably most important - if (job.error != null) { - job.error = e; - } + // Don't overwrite any previous errors as the first is probably most important + if (job.error == null) { + job.error = e; } } - job.result = Value (typeof (bool)); - job.result.set_boolean (success); job.results_ready (); } - public async bool remove_package (Package package, ChangeInformation change_info) throws GLib.Error { + public async void remove_package (Package package, ChangeInformation change_info) throws GLib.Error { var job_args = new RemovePackageArgs (); job_args.package = package; job_args.change_info = change_info; @@ -1815,8 +1782,6 @@ public class AppCenterCore.FlatpakBackend : Object { if (job.error != null) { throw job.error; } - - return job.result.get_boolean (); } private void update_package_internal (Job job) { @@ -1827,7 +1792,7 @@ public class AppCenterCore.FlatpakBackend : Object { if (user_installation == null && system_installation == null) { critical ("Error getting flatpak installation"); - job.result = false; + job.error = new IOError.FAILED (_("Error getting flatpak installation")); job.results_ready (); return; } @@ -1841,8 +1806,8 @@ public class AppCenterCore.FlatpakBackend : Object { var split_success = get_package_list_key_parts (updatable, out system, null, out bundle_id); if (!split_success) { - job.result = Value (typeof (bool)); - job.result.set_boolean (false); + warning ("Failed to update package: failed to split package key \"%s\"", updatable); + job.error = new IOError.FAILED (_("Failed to split package key")); job.results_ready (); return; } @@ -1866,13 +1831,9 @@ public class AppCenterCore.FlatpakBackend : Object { transactions++; } - bool success = true; - if (run_system) { try { - if (!run_updates_transaction (true, system_updates, change_info, cancellable)) { - success = false; - } + run_updates_transaction (true, system_updates, change_info, cancellable); } catch (Error e) { job.error = e; job.results_ready (); @@ -1882,9 +1843,7 @@ public class AppCenterCore.FlatpakBackend : Object { if (run_user) { try { - if (!run_updates_transaction (false, user_updates, change_info, cancellable)) { - success = false; - } + run_updates_transaction (false, user_updates, change_info, cancellable); } catch (Error e) { job.error = e; job.results_ready (); @@ -1892,12 +1851,10 @@ public class AppCenterCore.FlatpakBackend : Object { } } - job.result = Value (typeof (bool)); - job.result.set_boolean (success); job.results_ready (); } - private bool run_updates_transaction (bool system, string[] ids, ChangeInformation? change_info, Cancellable? cancellable) throws GLib.Error { + private void run_updates_transaction (bool system, string[] ids, ChangeInformation? change_info, Cancellable? cancellable) throws GLib.Error { Flatpak.Transaction transaction; try { if (system) { @@ -1908,7 +1865,7 @@ public class AppCenterCore.FlatpakBackend : Object { } } catch (Error e) { critical ("Error creating transaction for flatpak updates: %s", e.message); - return false; + throw e; } try { @@ -1942,14 +1899,8 @@ public class AppCenterCore.FlatpakBackend : Object { }); }); - bool success = false; - transaction.operation_error.connect ((operation, e, detail) => { warning ("Flatpak installation failed: %s", e.message); - if (e is GLib.IOError.CANCELLED) { - success = true; - } - return false; }); @@ -1960,20 +1911,10 @@ public class AppCenterCore.FlatpakBackend : Object { current_operation = 0; - try { - success = transaction.run (cancellable); - } catch (Error e) { - if (e is GLib.IOError.CANCELLED) { - success = true; - } else { - throw e; - } - } - - return success; + transaction.run (cancellable); } - public async bool update_package (Package package, ChangeInformation change_info) throws GLib.Error { + public async void update_package (Package package, ChangeInformation change_info) throws GLib.Error { var job_args = new UpdatePackageArgs (); job_args.package = package; job_args.change_info = change_info; @@ -1982,8 +1923,6 @@ public class AppCenterCore.FlatpakBackend : Object { if (job.error != null) { throw job.error; } - - return job.result.get_boolean (); } private void get_updates_internal (Job job) { diff --git a/src/Core/Package.vala b/src/Core/Package.vala index 0fa27a4ca..3989e436f 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -462,28 +462,28 @@ public class AppCenterCore.Package : Object { /** * Instructs the backend to update this package */ - public async bool update () throws GLib.Error { + public async void update () throws GLib.Error { if (state != State.UPDATE_AVAILABLE) { - return false; + return; } - return yield perform_operation (State.UPDATING, State.INSTALLED, State.UPDATE_AVAILABLE); + yield perform_operation (State.UPDATING); } - public async bool install () throws Error { + public async void install () throws Error { if (state != State.NOT_INSTALLED) { - return false; + return; } - return yield perform_operation (State.INSTALLING, State.INSTALLED, State.NOT_INSTALLED); + yield perform_operation (State.INSTALLING); } - public async bool uninstall () throws Error { + public async void uninstall () throws Error { if (state != INSTALLED && state != State.UPDATE_AVAILABLE) { throw new PackageUninstallError.APP_STATE_NOT_INSTALLED (_("Application state not set as installed in AppCenter for package: %s").printf (name)); } - return yield perform_operation (State.REMOVING, State.NOT_INSTALLED, state); + yield perform_operation (State.REMOVING); } public void launch () throws Error { @@ -498,9 +498,7 @@ public class AppCenterCore.Package : Object { } } - private async bool perform_operation (State performing, State after_success, State after_fail) throws GLib.Error { - bool success = false; - + private async void perform_operation (State performing) throws GLib.Error { change_information.start (); state = performing; @@ -508,7 +506,7 @@ public class AppCenterCore.Package : Object { flatpak_backend.notify_package_changed (this); try { - success = yield perform_package_operation (); + yield perform_package_operation (); flatpak_backend.operation_finished (this, performing, null); } catch (GLib.Error e) { warning ("Operation failed for package %s - %s", name, e.message); @@ -516,43 +514,31 @@ public class AppCenterCore.Package : Object { throw e; } finally { change_information.complete (); - - if (success) { - state = after_success; - } else { - state = after_fail; - } - - flatpak_backend.notify_package_changed (this); + update_state (); } - - return success; } - private async bool perform_package_operation () throws GLib.Error { + private async void perform_package_operation () throws GLib.Error { unowned var backend = AppCenterCore.FlatpakBackend.get_default (); switch (state) { case State.UPDATING: - var success = yield backend.update_package (this, change_information); - if (success) { - change_information.clear_update_info (); - update_state (); - } + yield backend.update_package (this, change_information); + change_information.clear_update_info (); + break; - return success; case State.INSTALLING: - var success = yield backend.install_package (this, change_information); - _installed = success; - update_state (); - return success; + yield backend.install_package (this, change_information); + _installed = true; + break; + case State.REMOVING: - var success = yield backend.remove_package (this, change_information); - _installed = !success; - update_state (); - return success; + yield backend.remove_package (this, change_information); + _installed = false; + break; + default: - return false; + assert_not_reached (); } }