hook-functions: Restore copy_file's handling of target ending in slash

Until recently, copy_file would treat a target ending in a slash as a
target directory.  This was not intended behaviour, but had worked
since at least v0.98.8.  It broke when I started using 'realpath' to
canonicalise the target, which stripped the slash.

Add a specific check for a trailing slash, and document that
behaviour.

Fixes: 984bdc7d727f ("hook-functions: copy_file: Canonicalise target filename")
Closes: #1082647
Signed-off-by: Ben Hutchings <benh@debian.org>
This commit is contained in:
Ben Hutchings 2024-09-26 18:02:35 +02:00
parent 140c572128
commit 765db02680

View File

@ -158,7 +158,8 @@ add_builtin_firmware()
# * If the target is not specified, it defaults to the source file
# name.
# * If the target is specified and exists as a directory under
# $DESTDIR, the basename of the source is appended to it.
# $DESTDIR or ends in a slash, the basename of the source is
# appended to it.
#
# The target file's containing directories are created if necessary.
#
@ -180,7 +181,7 @@ copy_file() {
[ -f "${src}" ] || return 2
if [ -d "${DESTDIR}/${target}" ]; then
if [ -d "${DESTDIR}/${target}" ] || [ "${target%/}" != "$target" ]; then
target="${target}/${src##*/}"
fi