From 0f13f3bd7918b84955eaa0ceeea0f964877a93f7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 17 Nov 2015 14:04:40 +0100 Subject: core: move check whether a unit is suitable to become transient into unit.c Lets introduce unit_is_pristine() that verifies whether a unit is suitable to become a transient unit, by checking that it is no referenced yet and has no data on disk assigned. --- src/core/unit.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/core/unit.c') diff --git a/src/core/unit.c b/src/core/unit.c index d199d87bf8..7809bfd754 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -3704,3 +3704,23 @@ int unit_fail_if_symlink(Unit *u, const char* where) { return -ELOOP; } + +bool unit_is_pristine(Unit *u) { + assert(u); + + /* Check if the unit already exists or is already referenced, + * in a number of different ways. Note that to cater for unit + * types such as slice, we are generally fine with units that + * are marked UNIT_LOADED even even though nothing was + * actually loaded, as those unit types don't require a file + * on disk to validly load. */ + + return !(!IN_SET(u->load_state, UNIT_NOT_FOUND, UNIT_LOADED) || + u->fragment_path || + u->source_path || + !strv_isempty(u->dropin_paths) || + u->refs || + set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0 || + u->job || + u->merged_into); +} -- cgit v1.2.3-54-g00ecf