1.1 --- a/plover-gtk/transactionhelper.c Thu Jul 16 19:54:45 2020 +0100
1.2 +++ b/plover-gtk/transactionhelper.c Mon Aug 31 07:12:39 2020 +0100
1.3 @@ -1,5 +1,5 @@
1.4 /*
1.5 - * Copyright (C) 2014, 2016, 2018 J. Ali Harlow <ali@juiblex.co.uk>
1.6 + * Copyright (C) 2014, 2016, 2018, 2020 J. Ali Harlow <ali@juiblex.co.uk>
1.7 *
1.8 * This program is free software; you can redistribute it and/or modify
1.9 * it under the terms of the GNU General Public License as published by
1.10 @@ -903,7 +903,7 @@
1.11 {
1.12 /*
1.13 * If there are no reportable packages tasked for action there
1.14 - * shouldn't by any packages at all, but let's be paranoid.
1.15 + * shouldn't be any packages at all, but let's be paranoid.
1.16 */
1.17 other_packages=FALSE;
1.18 razor_install_iterator_rewind(ii);
1.19 @@ -915,7 +915,9 @@
1.20 action=PLOVER_TRANSACTION_HELPER_REPORT_REMOVE;
1.21 else
1.22 continue;
1.23 - if (action==report_action)
1.24 + if (action==report_action ||
1.25 + razor_action==RAZOR_INSTALL_ACTION_ADD &&
1.26 + report_action==PLOVER_TRANSACTION_HELPER_REPORT_UPDATE)
1.27 {
1.28 razor_package_get_details(report_set,package,RAZOR_DETAIL_NAME,
1.29 &name,RAZOR_DETAIL_LAST);
1.30 @@ -1165,6 +1167,114 @@
1.31 }
1.32
1.33 /*
1.34 + * Returns TRUE if there is work to be done or FALSE if the group is
1.35 + * empty or on error.
1.36 + *
1.37 + * The default action is to:
1.38 + * - install (and update all) if any of the packages in @group are
1.39 + * missing or out of date,
1.40 + * - otherwise update all if any packages are out of date,
1.41 + * - otherwise remove ALL packages for distribution-local comps,
1.42 + * - otherwise remove all packages in @group, their dependants and leaves.
1.43 + */
1.44 +gboolean plover_transaction_helper_default_action_on_group(
1.45 + PloverTransactionHelper *helper,const char *group,GError **error)
1.46 +{
1.47 + gboolean distribution_local=FALSE,retval;
1.48 + GError *tmp_err=NULL;
1.49 + struct comps *comps;
1.50 + struct plover_vector *selected_packages;
1.51 + PloverTransaction *transaction;
1.52 + g_return_val_if_fail(PLOVER_IS_TRANSACTION_HELPER(helper),FALSE);
1.53 + selected_packages=plover_transaction_helper_group_get_default_packages(
1.54 + helper,group,error);
1.55 + if (!selected_packages)
1.56 + return FALSE;
1.57 + if (!selected_packages->len)
1.58 + {
1.59 + g_set_error(error,PLOVER_GENERAL_ERROR,
1.60 + PLOVER_GENERAL_ERROR_FAILED,"%s: no default packages",group);
1.61 + plover_vector_free(selected_packages);
1.62 + return FALSE;
1.63 + }
1.64 + comps=plover_transaction_helper_get_comps(helper,NULL);
1.65 + if (comps && comps->database==COMPS_DATABASE_DISTRIBUTION_LOCAL)
1.66 + distribution_local=TRUE;
1.67 + transaction=plover_transaction_helper_new_transaction(helper,error);
1.68 + if (!transaction)
1.69 + {
1.70 + plover_vector_free(selected_packages);
1.71 + return FALSE;
1.72 + }
1.73 + if (!plover_transaction_install_with_update_all(transaction,
1.74 + selected_packages->strings,error))
1.75 + {
1.76 + g_object_unref(transaction);
1.77 + plover_vector_free(selected_packages);
1.78 + return FALSE;
1.79 + }
1.80 + retval=plover_transaction_helper_add_transaction(helper,transaction,
1.81 + selected_packages,PLOVER_TRANSACTION_HELPER_REPORT_INSTALL,&tmp_err);
1.82 + g_object_unref(transaction);
1.83 + if (!retval)
1.84 + {
1.85 + if (!g_error_matches(tmp_err,PLOVER_GENERAL_ERROR,
1.86 + PLOVER_GENERAL_ERROR_NO_WORK))
1.87 + {
1.88 + g_propagate_error(error,tmp_err);
1.89 + plover_vector_free(selected_packages);
1.90 + return FALSE;
1.91 + }
1.92 + g_clear_error(&tmp_err);
1.93 + transaction=plover_transaction_helper_new_transaction(helper,error);
1.94 + if (!transaction)
1.95 + {
1.96 + plover_vector_free(selected_packages);
1.97 + return FALSE;
1.98 + }
1.99 + if (!plover_transaction_update(transaction,NULL,error))
1.100 + {
1.101 + g_object_unref(transaction);
1.102 + plover_vector_free(selected_packages);
1.103 + return FALSE;
1.104 + }
1.105 + retval=plover_transaction_helper_add_transaction(helper,transaction,
1.106 + selected_packages,PLOVER_TRANSACTION_HELPER_REPORT_UPDATE,&tmp_err);
1.107 + g_object_unref(transaction);
1.108 + if (!retval)
1.109 + {
1.110 + if (!g_error_matches(tmp_err,PLOVER_GENERAL_ERROR,
1.111 + PLOVER_GENERAL_ERROR_NO_WORK))
1.112 + {
1.113 + g_propagate_error(error,tmp_err);
1.114 + plover_vector_free(selected_packages);
1.115 + return FALSE;
1.116 + }
1.117 + g_clear_error(&tmp_err);
1.118 + transaction=plover_transaction_helper_new_transaction(helper,error);
1.119 + if (!transaction)
1.120 + {
1.121 + plover_vector_free(selected_packages);
1.122 + return FALSE;
1.123 + }
1.124 + if (!plover_transaction_remove_with_dependants_and_leaves(
1.125 + transaction,distribution_local?NULL:selected_packages->strings,
1.126 + error))
1.127 + {
1.128 + g_object_unref(transaction);
1.129 + plover_vector_free(selected_packages);
1.130 + return FALSE;
1.131 + }
1.132 + retval=plover_transaction_helper_add_transaction(helper,transaction,
1.133 + NULL,PLOVER_TRANSACTION_HELPER_REPORT_REMOVE,error);
1.134 + g_object_unref(transaction);
1.135 + }
1.136 + }
1.137 + plover_vector_free(selected_packages);
1.138 + return retval;
1.139 +}
1.140 +
1.141 +/*
1.142 * Returns TRUE if there is work to be done or FALSE if all updates have
1.143 * already been applied or on error.
1.144 */