diff options
| author | Peter Kjellerstedt <pkj@axis.com> | 2024-08-20 03:08:03 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-09-01 11:05:20 +0100 |
| commit | 36fb595c62d9cc52caaac38e22de3c31350feb37 (patch) | |
| tree | 7e172325f2216710a261758a298b5a1241e091cc | |
| parent | 5f380586305a74b8e2f5cecb57ae252e38b84bdc (diff) | |
| download | poky-36fb595c62d9cc52caaac38e22de3c31350feb37.tar.gz | |
systemd.bbclass: Clean up empty parent directories
Previously, rm_systemd_unitdir() would remove one parent directory of
${systemd_unitdir} if it was empty after removing ${systemd_unitdir}.
rm_sysvinit_initddir() would not remove any parent directory. Thus, if
the only directory created in /etc was /etc/init.d, an empty /etc would
remain after the cleanup and would be packaged.
Simplify rm_systemd_unitdir() and rm_sysvinit_initddir() by rewriting
them in shell, and use rmdir -p to remove all empty parent directories.
(From OE-Core rev: 73159c0bbc636a08934f47690885d75fd37b701a)
Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/classes-recipe/systemd.bbclass | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index 0f7e3b5a08..7324af8555 100644 --- a/meta/classes-recipe/systemd.bbclass +++ b/meta/classes-recipe/systemd.bbclass | |||
| @@ -208,33 +208,28 @@ python systemd_populate_packages() { | |||
| 208 | 208 | ||
| 209 | PACKAGESPLITFUNCS =+ "systemd_populate_packages" | 209 | PACKAGESPLITFUNCS =+ "systemd_populate_packages" |
| 210 | 210 | ||
| 211 | python rm_systemd_unitdir (){ | 211 | rm_systemd_unitdir() { |
| 212 | import shutil | 212 | rm -rf ${D}${systemd_unitdir} |
| 213 | if not bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d): | 213 | # Change into ${D} and use a relative path with rmdir -p to avoid |
| 214 | systemd_unitdir = oe.path.join(d.getVar("D"), d.getVar('systemd_unitdir')) | 214 | # having it remove ${D} if it becomes empty. |
| 215 | if os.path.exists(systemd_unitdir): | 215 | (cd ${D} && rmdir -p $(dirname ${systemd_unitdir#/}) 2>/dev/null || :) |
| 216 | shutil.rmtree(systemd_unitdir) | ||
| 217 | systemd_libdir = os.path.dirname(systemd_unitdir) | ||
| 218 | if (os.path.exists(systemd_libdir) and not os.listdir(systemd_libdir)): | ||
| 219 | os.rmdir(systemd_libdir) | ||
| 220 | } | 216 | } |
| 221 | 217 | ||
| 222 | python rm_sysvinit_initddir (){ | 218 | rm_sysvinit_initddir() { |
| 223 | import shutil | 219 | local sysv_initddir=${INIT_D_DIR} |
| 224 | sysv_initddir = oe.path.join(d.getVar("D"), (d.getVar('INIT_D_DIR') or "/etc/init.d")) | 220 | : ${sysv_initddir:=${sysconfdir}/init.d} |
| 225 | |||
| 226 | if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d) and \ | ||
| 227 | not bb.utils.contains('DISTRO_FEATURES', 'sysvinit', True, False, d) and \ | ||
| 228 | os.path.exists(sysv_initddir): | ||
| 229 | systemd_system_unitdir = oe.path.join(d.getVar("D"), d.getVar('systemd_system_unitdir')) | ||
| 230 | 221 | ||
| 231 | # If systemd_system_unitdir contains anything, delete sysv_initddir | 222 | # If systemd_system_unitdir contains anything, delete sysv_initddir |
| 232 | if (os.path.exists(systemd_system_unitdir) and os.listdir(systemd_system_unitdir)): | 223 | if [ "$(ls -A ${D}${systemd_system_unitdir} 2>/dev/null)" ]; then |
| 233 | shutil.rmtree(sysv_initddir) | 224 | rm -rf ${D}$sysv_initddir |
| 225 | rmdir -p $(dirname ${D}$sysv_initddir) 2>/dev/null || : | ||
| 226 | fi | ||
| 234 | } | 227 | } |
| 235 | 228 | ||
| 236 | do_install[postfuncs] += "${RMINITDIR} " | 229 | do_install[postfuncs] += "${RMINITDIR}" |
| 237 | RMINITDIR:class-target = " rm_sysvinit_initddir rm_systemd_unitdir " | 230 | RMINITDIR = " \ |
| 238 | RMINITDIR:class-nativesdk = " rm_sysvinit_initddir rm_systemd_unitdir " | 231 | ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', '', 'rm_systemd_unitdir', d)} \ |
| 239 | RMINITDIR = "" | 232 | ${@'rm_sysvinit_initddir' if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d) and \ |
| 240 | 233 | not bb.utils.contains('DISTRO_FEATURES', 'sysvinit', True, False, d) else ''} \ | |
| 234 | " | ||
| 235 | RMINITDIR:class-native = "" | ||
