From 689d9757c505258d500f178a473ea6d2460991ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Sun, 25 Oct 2015 11:23:51 +0100 Subject: [PATCH] stdenv/multiple-outputs: autoremove empty directories i.e. remove chains of empty dirs after moving contents out of them. --- pkgs/build-support/setup-hooks/multiple-outputs.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkgs/build-support/setup-hooks/multiple-outputs.sh b/pkgs/build-support/setup-hooks/multiple-outputs.sh index 74082cb474d7..ae00b0bf13f2 100644 --- a/pkgs/build-support/setup-hooks/multiple-outputs.sh +++ b/pkgs/build-support/setup-hooks/multiple-outputs.sh @@ -93,6 +93,13 @@ _moveToOutput() { mkdir -p $(readlink -m "$dstPath/..") # create the parent for $dstPath mv "$srcPath" "$dstPath" fi + + # remove empty directories, printing iff at least one gets removed + local srcParent="$(readlink -m "$srcPath/..")" + if rmdir "$srcParent"; then + echo "Removing empty $srcParent/ and (possibly) its parents" + rmdir -p --ignore-fail-on-non-empty "$(readlink -m "$srcParent/..")" + fi done done } @@ -107,11 +114,6 @@ _multioutDocs() { # the default outputMan is in $bin _moveToOutput share/man "${!outputMan}" _moveToOutput share/man/man3 "${!outputDocdev}" - - # Remove empty share directory. - if [ -d "$out/share" ]; then - rmdir "$out/share" --ignore-fail-on-non-empty - fi } # Move development-only stuff to the desired outputs.