[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#812404: [PATCH initramfs-tools] copy_file: Skip duplicating symlink if it points to the target file



Control: tag -1 patch moreinfo

I couldn't reproduce this failure but I think I understand the
problem.  Does this patch work for you?

Ben.
---
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>
---
 hook-functions | 14 +++++++++-----
 1 file 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}"

Attachment: signature.asc
Description: Digital signature


Reply to: