CPack/STGZ: Avoid replacing directory symlinks if possible

When installing into a prefix with existing directory symlinks, tell
`tar` not to replace them with real directories from the package.

Fixes: #21119
This commit is contained in:
Brad King
2025-12-17 17:21:20 -05:00
parent 70dcdffb1f
commit ecbe5a8479

View File

@@ -136,8 +136,16 @@ echo ""
use_new_tail_syntax="-n"
tail $use_new_tail_syntax +1 "$0" > /dev/null 2> /dev/null || use_new_tail_syntax=""
extractor="pax -r"
command -v pax > /dev/null 2> /dev/null || extractor="tar xf -"
if command -v pax > /dev/null 2> /dev/null; then
extractor="pax -r"
else
# Avoid replacing directory symlinks with directories from the package.
if tar --help 2> /dev/null | grep "keep-directory-symlink" > /dev/null 2> /dev/null; then
extractor="tar --keep-directory-symlink -xf -"
else
extractor="tar xf -"
fi
fi
tail $use_new_tail_syntax +###CPACK_HEADER_LENGTH### "$0" | gunzip | (cd "${toplevel}" && ${extractor}) || cpack_echo_exit "Problem unpacking the @CPACK_PACKAGE_FILE_NAME@"