hook_functions: Fix copy_file with source including a directory symlink
Debian bug #1076539 (and its many duplicates) involved a firmware package with a directory structure like:
vendor/model1/
vendor/model1/firmware.bin
vendor/model2 -> model1
vendor/model3 -> model1
...and the associated kernel module referred to firmware names like
vendor/model1/firmware.bin, vendor/model2/firmware.bin, etc.
copy_file currently checks whether the source itself is a symlink, and
all of the filenames resolve to a regular file, so copy_file would
happily install multiple copies of that.
The particular problem with firmware was fixed by the switch to
dracut-install, but the same problem could occur with other files.
Also, that change is not suitable for backporting.
To handle directory symlinks as well, replace this check with a comparison of:
- The canonicalised filename with symlinks dereferenced, as produced
by readlink -f.
- The canonicalised filename without symlinks dereferenced, as
produced by realpath -s.
Signed-off-by: Ben Hutchings benh@debian.org