mirror of
https://github.com/nix-community/home-manager
synced 2024-11-27 21:49:48 +01:00
home-environment: fix error when deleting empty directories
With --ignore-fail-on-non-empty, non-emptiness is the only failure
that gets ignored by rmdir. In the case that rmdir reaches $HOME and
considers deleting it, it will detect insufficient permissions and
subsequently exit with an error, even if $HOME is not empty.
Prevent this by calling rmdir with a relative path that excludes
$HOME.
(cherry picked from commit da5b7bea78
)
This commit is contained in:
parent
758d2ef9c1
commit
9865e3ce29
1 changed files with 10 additions and 6 deletions
|
@ -315,16 +315,20 @@ in
|
||||||
else
|
else
|
||||||
echo "Checking $targetPath gone (deleting)"
|
echo "Checking $targetPath gone (deleting)"
|
||||||
$DRY_RUN_CMD rm $VERBOSE_ARG "$targetPath"
|
$DRY_RUN_CMD rm $VERBOSE_ARG "$targetPath"
|
||||||
targetDir="$(dirname "$targetPath")"
|
|
||||||
|
|
||||||
# Recursively remove the containing directory. We only
|
# Recursively delete empty parent directories.
|
||||||
# do this if the containing folder is not $HOME since
|
targetDir="$(dirname "$relativePath")"
|
||||||
# running rmdir on $HOME will result in a harmless but
|
if [[ "$targetDir" != "." ]] ; then
|
||||||
# unpleasant error message.
|
pushd "$HOME" > /dev/null
|
||||||
if [[ "$targetDir" != "$HOME" ]] ; then
|
|
||||||
|
# Call rmdir with a relative path excluding $HOME.
|
||||||
|
# Otherwise, it might try to delete $HOME and exit
|
||||||
|
# with a permission error.
|
||||||
$DRY_RUN_CMD rmdir $VERBOSE_ARG \
|
$DRY_RUN_CMD rmdir $VERBOSE_ARG \
|
||||||
-p --ignore-fail-on-non-empty \
|
-p --ignore-fail-on-non-empty \
|
||||||
"$targetDir"
|
"$targetDir"
|
||||||
|
|
||||||
|
popd > /dev/null
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue