Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 28 additions & 89 deletions src/Core/FlatpakBackend.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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 ();
Expand All @@ -1882,22 +1843,18 @@ 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 ();
return;
}
}

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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
});

Expand All @@ -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;
Expand All @@ -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) {
Expand Down
Loading