diff options
author | Ben Hutchings <ben@decadent.org.uk> | 2016-01-23 13:20:16 +0000 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2016-01-23 13:20:16 +0000 |
commit | e5476bff04c01e7a6d03054ca84e7842471f60bd (patch) | |
tree | f8852168a7d03d0e29f833bb2675ac78739138ab | |
parent | 07f2c88b2ca7e639201d1b76e1727fa2f70fae60 (diff) |
copy_file: Skip duplicating symlink if it points to the target file
When the source and target paths are different, it's possible that
the source is a symlink to the target path. In that case we must
only copy the file - there is no need for a symlink and currently
we create a broken symlink.
Closes: #812404
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | hook-functions | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/hook-functions b/hook-functions index 60f798c..78b6a88 100644 --- a/hook-functions +++ b/hook-functions @@ -134,13 +134,17 @@ copy_file() { mkdir -p "${DESTDIR}/${target%/*}" if [ -h "${src}" ]; then - [ "${verbose}" = "y" ] && echo "Adding ${type}-link ${src}" - # We don't need to replicate a chain of links completely; - # just link directly to the ultimate target. Create a - # relative link so it always points to the right place. + # just link directly to the ultimate target link_target="$(readlink -f "${src}")" || return $(($? + 1)) - ln -rs "${DESTDIR}/${link_target}" "${DESTDIR}/${target}" + + if [ "${link_target}" != "${target}" ]; then + [ "${verbose}" = "y" ] && echo "Adding ${type}-link ${src}" + + # Create a relative link so it always points + # to the right place + ln -rs "${DESTDIR}/${link_target}" "${DESTDIR}/${target}" + fi # Copy the link target if it doesn't already exist src="${link_target}" |