Browse Source

dpkg-maintscript-helper: Fix dir_to_symlink to handle relative symlink targets

When invoking dir_to_symlink, dpkg-maintscript-helper was assuming the
target to be absolute, but Debian policy 10.5 requires relative symlinks
in a few places. So it now works with relative targets.

Signed-off-by: Helmut Grohne <helmut@subdivi.de>
Signed-off-by: Guillem Jover <guillem@debian.org>
Helmut Grohne 12 years ago
parent
commit
7fe9dcdd57
3 changed files with 16 additions and 5 deletions
  1. 2 0
      debian/changelog
  2. 4 3
      man/dpkg-maintscript-helper.1
  3. 10 2
      scripts/dpkg-maintscript-helper.sh

+ 2 - 0
debian/changelog

@@ -10,6 +10,8 @@ dpkg (1.17.13) UNRELEASED; urgency=low
     - Split --remove and --purge options in dpkg(1). This also clarifies on
       which package states each option can operate. Closes: #576338
     - Remove duplicate “of the” in dpkg-maintscript-helper(1).
+  * Fix dpkg-maintscript-helper dir_to_symlink to handle relative symlink
+    targets. Thanks to Helmut Grohne <helmut@subdivi.de>.
 
   [ Updated programs translations ]
   * Czech (Miroslav Kure).

+ 4 - 3
man/dpkg-maintscript-helper.1

@@ -197,9 +197,10 @@ scripts:
     dpkg\-maintscript\-helper dir_to_symlink \\
         \fIpathname\fP \fInew-target\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
 .P
-\fIpathname\fP is the name of the old directory (the path will be a
-symlink at the end of the installation) and \fInew-target\fP is the target
-of the new symlink at \fIpathname\fP.
+\fIpathname\fP is the absolute name of the old directory (the path
+will be a symlink at the end of the installation) and \fInew-target\fP is
+the target of the new symlink at \fIpathname\fP. It can either be absolute
+or relative to the directory containing \fIpathname\fP.
 .P
 Current implementation: the \fBpreinst\fP checks if the directory
 exists, does not contain conffiles, pathnames owned by other packages,

+ 10 - 2
scripts/dpkg-maintscript-helper.sh

@@ -325,6 +325,8 @@ dir_to_symlink() {
 		error "environment variable DPKG_MAINTSCRIPT_NAME is required"
 	[ -n "$PACKAGE" ] || error "cannot identify the package"
 	[ -n "$PATHNAME" ] || error "directory parameter is missing"
+	[ "${PATHNAME#/}" = "$PATHNAME" ] && \
+		error "directory parameter is not an absolute path"
 	[ -n "$SYMLINK_TARGET" ] || error "new symlink target is missing"
 	[ -n "$1" ] || error "maintainer script parameters are missing"
 
@@ -364,7 +366,7 @@ dir_to_symlink() {
 		   [ \( ! -h "$PATHNAME" -a -d "$PATHNAME" -a \
 		        -f "$PATHNAME/.dpkg-staging-dir" \) -o \
 		     \( -h "$PATHNAME" -a \
-		        "$(readlink -f $PATHNAME)" = "$SYMLINK_TARGET" \) ] &&
+		        "$(readlink $PATHNAME)" = "$SYMLINK_TARGET" \) ] &&
 		   dpkg --compare-versions "$2" le-nl "$LASTVERSION"; then
 			abort_dir_to_symlink "$PATHNAME"
 		fi
@@ -429,9 +431,15 @@ finish_dir_to_symlink()
 	# Move the contents of the staging directory to the symlink target,
 	# as those are all new files installed between this package being
 	# unpacked and configured.
+	local ABS_SYMLINK_TARGET
+	if [ "${SYMLINK_TARGET#/}" = "$SYMLINK_TARGET" ]; then
+		ABS_SYMLINK_TARGET="$(dirname "$PATHNAME")/$SYMLINK_TARGET"
+	else
+		ABS_SYMLINK_TARGET="$SYMLINK_TARGET"
+	fi
 	rm "$PATHNAME/.dpkg-staging-dir"
 	find "$PATHNAME" -mindepth 1 -print0 | \
-		xargs -0 -i% mv -f "%" "$SYMLINK_TARGET/"
+		xargs -0 -i% mv -f "%" "$ABS_SYMLINK_TARGET/"
 
 	# Remove the staging directory.
 	rmdir "$PATHNAME"