#include "strv.h"
#include "transaction.h"
+static bool job_matters_to_anchor(Job *job);
static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies);
static void transaction_delete_job(Transaction *tr, Job *j, bool delete_dependencies) {
return -EINVAL;
}
-static int transaction_merge_jobs(Transaction *tr, sd_bus_error *e) {
+static int transaction_ensure_mergeable(Transaction *tr, bool matters_to_anchor, sd_bus_error *e) {
Job *j;
int r;
assert(tr);
- /* First step, check whether any of the jobs for one specific
- * task conflict. If so, try to drop one of them. */
HASHMAP_FOREACH(j, tr->jobs) {
JobType t;
+ if (job_matters_to_anchor(j) != matters_to_anchor)
+ continue;
+
t = j->type;
LIST_FOREACH(transaction, k, j->transaction_next) {
if (job_type_merge_and_collapse(&t, k->type, j->unit) >= 0)
}
}
- /* Second step, merge the jobs. */
+ return 0;
+}
+
+static int transaction_merge_jobs(Transaction *tr, sd_bus_error *e) {
+ Job *j;
+ int r;
+
+ assert(tr);
+
+ /* First step, try to drop unmergeable jobs for jobs that matter to anchor. */
+ r = transaction_ensure_mergeable(tr, /* matters_to_anchor = */ true, e);
+ if (r < 0)
+ return r;
+
+ /* Second step, do the same for jobs that not matter to anchor. */
+ r = transaction_ensure_mergeable(tr, /* matters_to_anchor = */ false, e);
+ if (r < 0)
+ return r;
+
+ /* Third step, merge the jobs. */
HASHMAP_FOREACH(j, tr->jobs) {
JobType t = j->type;