control: tags -1 + patch

Hi,

Found joinded patch to honor DPKG_ROOT. Tested using test suite
From 2d870b20534bac2847b55b544351c112a85595e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastien=20ROUCARI=C3=88S?= <roucaries.bast...@gmail.com>
Date: Mon, 20 Mar 2017 16:27:09 +0100
Subject: [PATCH 5/5] Honor DPKG_ROOT in dir to symlink

---
 scripts/dpkg-maintscript-helper.sh | 83 +++++++++++++++++++++++---------------
 1 file changed, 51 insertions(+), 32 deletions(-)

diff --git a/scripts/dpkg-maintscript-helper.sh b/scripts/dpkg-maintscript-helper.sh
index 0b867d805..5becba33a 100755
--- a/scripts/dpkg-maintscript-helper.sh
+++ b/scripts/dpkg-maintscript-helper.sh
@@ -354,10 +354,10 @@ dir_to_symlink() {
 	      "PACKAGE=$PACKAGE LASTVERSION=$LASTVERSION ACTION=$1 PARAM=$2"
 
 	case "$DPKG_MAINTSCRIPT_NAME" in
-	preinst)
+	    preinst)
 		if [ "$1" = "install" -o "$1" = "upgrade" ] &&
 		   [ -n "$2" ] &&
-		   [ ! -h "$PATHNAME" ] && [ -d "$PATHNAME" ] &&
+		   [ ! -h "$DPKG_ROOT$PATHNAME" ] && [ -d "$DPKG_ROOT$PATHNAME" ] &&
 		   dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
 			prepare_dir_to_symlink "$PACKAGE" "$PATHNAME"
 		fi
@@ -368,24 +368,24 @@ dir_to_symlink() {
 		# have been unpacked, then upgraded with an unpack and thus
 		# never been configured before.
 		if [ "$1" = "configure" ] &&
-		   [ -d "${PATHNAME}.dpkg-backup" ] &&
-		   [ ! -h "$PATHNAME" ] && [ -d "$PATHNAME" ] &&
-		   [ -f "$PATHNAME/.dpkg-staging-dir" ]; then
+		   [ -d "$DPKG_ROOT${PATHNAME}.dpkg-backup" ] &&
+		   [ ! -h "$DPKG_ROOT$PATHNAME" ] && [ -d "$DPKG_ROOT$PATHNAME" ] &&
+		   [ -f "$DPKG_ROOT$PATHNAME/.dpkg-staging-dir" ]; then
 			finish_dir_to_symlink "$PATHNAME" "$SYMLINK_TARGET"
 		fi
 		;;
 	postrm)
-		if [ "$1" = "purge" ] && [ -d "${PATHNAME}.dpkg-backup" ]; then
-		    rm -rf "${PATHNAME}.dpkg-backup"
+		if [ "$1" = "purge" ] && [ -d "$DPKG_ROOT${PATHNAME}.dpkg-backup" ]; then
+		    rm -rf "$DPKG_ROOT${PATHNAME}.dpkg-backup"
 		fi
 		if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ] &&
 		   [ -n "$2" ] &&
-		   [ -d "${PATHNAME}.dpkg-backup" ] &&
-		   [ \( ! -h "$PATHNAME" -a -d "$PATHNAME" -a \
-		        -f "$PATHNAME/.dpkg-staging-dir" \) -o \
-		     \( -h "$PATHNAME" -a symlink_match "$PATHNAME" "$SYMLINK_TARGET" \)] &&
+		   [ -d "$DPKG_ROOT${PATHNAME}.dpkg-backup" ] &&
+		   [ \( ! -h "$DPKG_ROOT$PATHNAME" -a -d "$DPKG_ROOT$PATHNAME" -a \
+		        -f "$DPKG_ROOT$PATHNAME/.dpkg-staging-dir" \) -o \
+		     \( -h "$DPKG_ROOT$PATHNAME" -a symlink_match "$PATHNAME" "$SYMLINK_TARGET" \)] &&
 		   dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
-			abort_dir_to_symlink "$PATHNAME"
+			abort_dir_to_symlink "$DPKG_ROOT$PATHNAME"
 		fi
 		;;
 	*)
@@ -412,10 +412,23 @@ prepare_dir_to_symlink()
 
 	# If there are locally created files or files owned by another package
 	# we should not perform the switch.
-	find "$PATHNAME" -print0 | xargs -0 -n1 \
-		dpkg-maintscript-helper package_owns_file_or_error $PACKAGE || \
-		error "directory '$PATHNAME' contains files not owned by" \
-		      "package $PACKAGE, cannot switch to symlink"
+	if [ -n "$DPKG_ROOT" ]; then
+	        find "$PATHNAME" -print0 | xargs -0 -n1 \
+		       dpkg-maintscript-helper package_owns_file_or_error $PACKAGE || \
+		              error "directory '$PATHNAME' contains files not owned by" \
+		                    "package $PACKAGE, cannot switch to symlink"
+	else
+	    find "$DPKG_ROOT$PATHNAME" -printf "%P\0" | xargs -0 -n1 \
+		       sh -c '
+		       	  file=$2
+			  pathname=$1
+		       	  echo -n "$pathname/$file"; printf "\0"' \
+			  addpathname $PATHNAME | \
+		       xargs -0 -n1 \
+		       dpkg-maintscript-helper package_owns_file_or_error $PACKAGE || \
+		              error "directory '$PATHNAME' contains files not owned by" \
+		                    "package $PACKAGE, cannot switch to symlink"
+	fi
 
 	# At this point, we know that the directory either contains no files,
 	# or only non-conffiles owned by the package.
@@ -431,11 +444,11 @@ prepare_dir_to_symlink()
 	# So we need to create a staging directory, to avoid removing files
 	# from other packages, and to trap any new files in the directory
 	# to move them to their correct place later on.
-	mv -f "$PATHNAME" "${PATHNAME}.dpkg-backup"
-	mkdir "$PATHNAME"
+	mv -f "$DPKG_ROOT$PATHNAME" "$DPKG_ROOT${PATHNAME}.dpkg-backup"
+	mkdir "$DPKG_ROOT$PATHNAME"
 
 	# Mark it as a staging directory, so that we can track things.
-	touch "$PATHNAME/.dpkg-staging-dir"
+	touch "$DPKG_ROOT$PATHNAME/.dpkg-staging-dir"
 }
 
 finish_dir_to_symlink()
@@ -452,19 +465,25 @@ finish_dir_to_symlink()
 	else
 		ABS_SYMLINK_TARGET="$SYMLINK_TARGET"
 	fi
-	rm "$PATHNAME/.dpkg-staging-dir"
-	find "$PATHNAME" -mindepth 1 -print0 | \
-		xargs -0 -i% mv -f "%" "$ABS_SYMLINK_TARGET/"
+	rm "$DPKG_ROOT$PATHNAME/.dpkg-staging-dir"
+	find "$DPKG_ROOT$PATHNAME" -mindepth 1 -print0 | \
+		xargs -0 -i% mv -f "%" "$DPKG_ROOT$ABS_SYMLINK_TARGET/"
 
 	# Remove the staging directory.
-	rmdir "$PATHNAME"
+	rmdir "$DPKG_ROOT$PATHNAME"
 
 	# Do the actual switch.
-	ln -s "$SYMLINK_TARGET" "$PATHNAME"
-
+	case $SYMLINK_TARGET in
+	    /*)
+		ln -s "$DPKG_ROOT$SYMLINK_TARGET" "$DPKG_ROOT$PATHNAME"
+		;;
+	    *)
+		ln -s "$SYMLINK_TARGET" "$DPKG_ROOT$PATHNAME"
+		;;
+	esac
 	# We are left behind the old files owned by this package in the backup
 	# directory, just remove it.
-	rm -rf "${PATHNAME}.dpkg-backup"
+	rm -rf "$DPKG_ROOT${PATHNAME}.dpkg-backup"
 }
 
 abort_dir_to_symlink()
@@ -472,16 +491,16 @@ abort_dir_to_symlink()
 	local PATHNAME="$1"
 
 	echo "Restoring backup of $PATHNAME ..."
-	if [ -h "$PATHNAME" ]; then
-		rm -f "$PATHNAME"
+	if [ -h "$DPKG_ROOT$PATHNAME" ]; then
+		rm -f "$DPKG_ROOT$PATHNAME"
 	else
 		# The staging directory must be empty, as no other package
 		# should have been unpacked in between.
-		rm -f "$PATHNAME/.dpkg-staging-dir"
-		rmdir "$PATHNAME"
+		rm -f "$DPKG_ROOT$PATHNAME/.dpkg-staging-dir"
+		rmdir "$DPKG_ROOT$PATHNAME"
 	fi
 
-	mv "${PATHNAME}.dpkg-backup" "$PATHNAME"
+	mv "$DPKG_ROOT${PATHNAME}.dpkg-backup" "$DPKG_ROOT$PATHNAME"
 }
 
 # Common functions
@@ -512,7 +531,7 @@ ensure_package_owns_file() {
 
 package_owns_file_or_error() {
        local PACKAGE="$1"
-       local FILE="$2"
+       local FILE="${2%/}"
        if ! ensure_package_owns_file $PACKAGE $FILE ; then
 	   error "File '$FILE' not owned by package " \
 		 "'$PACKAGE'"
-- 
2.11.0

From 14814cd71ca2fac0857c51615dfcb0f6fd13655b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastien=20ROUCARI=C3=88S?= <roucaries.bast...@gmail.com>
Date: Wed, 15 Mar 2017 12:10:07 +0100
Subject: [PATCH 4/5] Factorize owns_file

---
 scripts/dpkg-maintscript-helper.sh | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/scripts/dpkg-maintscript-helper.sh b/scripts/dpkg-maintscript-helper.sh
index b4b3ac1b3..0b867d805 100755
--- a/scripts/dpkg-maintscript-helper.sh
+++ b/scripts/dpkg-maintscript-helper.sh
@@ -412,14 +412,8 @@ prepare_dir_to_symlink()
 
 	# If there are locally created files or files owned by another package
 	# we should not perform the switch.
-	find "$PATHNAME" -print0 | xargs -0 -n1 sh -c '
-		package="$1"
-		file="$2"
-		if ! dpkg-query -L "$package" | grep -F -q -x "$file"; then
-			exit 1
-		fi
-		exit 0
-	' check-files-ownership "$PACKAGE" || \
+	find "$PATHNAME" -print0 | xargs -0 -n1 \
+		dpkg-maintscript-helper package_owns_file_or_error $PACKAGE || \
 		error "directory '$PATHNAME' contains files not owned by" \
 		      "package $PACKAGE, cannot switch to symlink"
 
@@ -515,6 +509,18 @@ ensure_package_owns_file() {
 	return 0
 }
 
+
+package_owns_file_or_error() {
+       local PACKAGE="$1"
+       local FILE="$2"
+       if ! ensure_package_owns_file $PACKAGE $FILE ; then
+	   error "File '$FILE' not owned by package " \
+		 "'$PACKAGE'"
+	   return 1
+       fi
+       return 0
+}
+
 symlink_match()
 {
          local SYMLINK="$1"
@@ -614,6 +620,9 @@ symlink_to_dir)
 dir_to_symlink)
 	dir_to_symlink "$@"
 	;;
+package_owns_file_or_error)
+        package_owns_file_or_error "$@"
+        ;;
 --help|help|-?)
 	usage
 	;;
-- 
2.11.0

From f680a1705a529d65f374667b44251fcf12b9abbb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastien=20ROUCARI=C3=88S?= <roucaries.bast...@gmail.com>
Date: Tue, 14 Mar 2017 21:57:38 +0100
Subject: [PATCH 3/5] Symplify a condition by using a function

---
 scripts/dpkg-maintscript-helper.sh | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/scripts/dpkg-maintscript-helper.sh b/scripts/dpkg-maintscript-helper.sh
index 4cf7f04eb..b4b3ac1b3 100755
--- a/scripts/dpkg-maintscript-helper.sh
+++ b/scripts/dpkg-maintscript-helper.sh
@@ -383,9 +383,7 @@ dir_to_symlink() {
 		   [ -d "${PATHNAME}.dpkg-backup" ] &&
 		   [ \( ! -h "$PATHNAME" -a -d "$PATHNAME" -a \
 		        -f "$PATHNAME/.dpkg-staging-dir" \) -o \
-		     \( -h "$PATHNAME" -a \
-		        \( "$(readlink "$PATHNAME")" = "$SYMLINK_TARGET" -o \
-		           "$(readlink -f "$PATHNAME")" = "$SYMLINK_TARGET" \) \) ] &&
+		     \( -h "$PATHNAME" -a symlink_match "$PATHNAME" "$SYMLINK_TARGET" \)] &&
 		   dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
 			abort_dir_to_symlink "$PATHNAME"
 		fi
-- 
2.11.0

From e1331be07812900c9bee7525547b046120ab2329 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastien=20ROUCARI=C3=88S?= <roucaries.bast...@gmail.com>
Date: Tue, 14 Mar 2017 15:05:53 +0100
Subject: [PATCH 2/5] Use DPKG_ROOT for symlink to dir

---
 scripts/dpkg-maintscript-helper.sh | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/scripts/dpkg-maintscript-helper.sh b/scripts/dpkg-maintscript-helper.sh
index e0e66f921..4cf7f04eb 100755
--- a/scripts/dpkg-maintscript-helper.sh
+++ b/scripts/dpkg-maintscript-helper.sh
@@ -280,10 +280,10 @@ symlink_to_dir() {
 	case "$DPKG_MAINTSCRIPT_NAME" in
 	preinst)
 		if [ "$1" = "install" -o "$1" = "upgrade" ] &&
-		   [ -n "$2" ] && [ -h "$SYMLINK" ] &&
+		   [ -n "$2" ] && [ -h "${DPKG_ROOT}$SYMLINK" ] &&
 		   symlink_match "$SYMLINK" "$SYMLINK_TARGET" &&
 		   dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
-			mv -f "$SYMLINK" "${SYMLINK}.dpkg-backup"
+			mv -f "${DPKG_ROOT}$SYMLINK" "${DPKG_ROOT}${SYMLINK}.dpkg-backup"
 		fi
 		;;
 	postinst)
@@ -291,23 +291,23 @@ symlink_to_dir() {
 		# know what was the last configured version, and we might
 		# have been unpacked, then upgraded with an unpack and thus
 		# never been configured before.
-		if [ "$1" = "configure" ] && [ -h "${SYMLINK}.dpkg-backup" ] &&
+		if [ "$1" = "configure" ] && [ -h "${DPKG_ROOT}${SYMLINK}.dpkg-backup" ] &&
 		   symlink_match "${SYMLINK}.dpkg-backup" "$SYMLINK_TARGET"
 		then
-			rm -f "${SYMLINK}.dpkg-backup"
+			rm -f "${DPKG_ROOT}${SYMLINK}.dpkg-backup"
 		fi
 		;;
 	postrm)
-		if [ "$1" = "purge" ] && [ -h "${SYMLINK}.dpkg-backup" ]; then
-		    rm -f "${SYMLINK}.dpkg-backup"
+		if [ "$1" = "purge" ] && [ -h "${DPKG_ROOT}${SYMLINK}.dpkg-backup" ]; then
+		    rm -f "${DPKG_ROOT}${SYMLINK}.dpkg-backup"
 		fi
 		if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ] &&
 		   [ -n "$2" ] &&
-		   [ ! -e "$SYMLINK" ] && [ -h "${SYMLINK}.dpkg-backup" ] &&
+		   [ ! -e "${DPKG_ROOT}$SYMLINK" ] && [ -h "${DPKG_ROOT}${SYMLINK}.dpkg-backup" ] &&
 		   symlink_match "${SYMLINK}.dpkg-backup" "$SYMLINK_TARGET" &&
 		   dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
 			echo "Restoring backup of $SYMLINK ..."
-			mv "${SYMLINK}.dpkg-backup" "$SYMLINK"
+			mv "${DPKG_ROOT}${SYMLINK}.dpkg-backup" "${DPKG_ROOT}$SYMLINK"
 		fi
 		;;
 	*)
@@ -519,11 +519,15 @@ ensure_package_owns_file() {
 
 symlink_match()
 {
-	local SYMLINK="$1"
-	local SYMLINK_TARGET="$2"
-
-	[ "$(readlink "$SYMLINK")" = "$SYMLINK_TARGET" ] || \
-	[ "$(readlink -f "$SYMLINK")" = "$SYMLINK_TARGET" ]
+         local SYMLINK="$1"
+	 local SYMLINK_TARGET="$2"
+	 local DPKG_ROOT_CANON=""
+         if [ -n $DPKG_ROOT ]; then
+	     DPKG_ROOT_CANON="$(readlink -f "$DPKG_ROOT")"
+	 fi
+
+	 [ "$(readlink "$SYMLINK")" = "$SYMLINK_TARGET" ] || \
+	 [ "$(readlink -f "${DPKG_ROOT_CANON}$SYMLINK")" = "${DPKG_ROOT_CANON}$SYMLINK_TARGET" ]
 }
 
 debug() {
-- 
2.11.0

From 47311959ef71a67768ecfef357883e27027867b0 Mon Sep 17 00:00:00 2001
From: David Kalnischkies <da...@kalnischkies.de>
Date: Sat, 23 Jul 2016 10:07:53 +0200
Subject: [PATCH 1/5] dpkg-maintscript-helper: support DPKG_ROOT for config
 file
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

As dpkg-maintscript-helper "works around known dpkg limitations in
maintainer scripts" it should behave as if it were a maintainerscript
and prepend DPKG_ROOT to all paths it uses.

This is preferred over having the conffile parameter(s) be prepended
with DPKG_ROOT by the maintainerscripts calling the helper as the helper
would then need to strip DPKG_ROOT from the path to verify if the
conffile belongs to the package – it also means that it magically works
for all callers instantly instead of requiring e.g. dh_installdeb to be
patched and packages to be rebuilt against a patched version.
---
 scripts/dpkg-maintscript-helper.sh | 62 +++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/scripts/dpkg-maintscript-helper.sh b/scripts/dpkg-maintscript-helper.sh
index 2366dcbdb..e0e66f921 100755
--- a/scripts/dpkg-maintscript-helper.sh
+++ b/scripts/dpkg-maintscript-helper.sh
@@ -69,8 +69,8 @@ rm_conffile() {
 		;;
 	postrm)
 		if [ "$1" = "purge" ]; then
-			rm -f "$CONFFILE.dpkg-bak" "$CONFFILE.dpkg-remove" \
-			      "$CONFFILE.dpkg-backup"
+			rm -f "${DPKG_ROOT}$CONFFILE.dpkg-bak" "${DPKG_ROOT}$CONFFILE.dpkg-remove" \
+			      "${DPKG_ROOT}$CONFFILE.dpkg-backup"
 		fi
 		if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ] &&
 		   [ -n "$2" ] &&
@@ -88,31 +88,31 @@ prepare_rm_conffile() {
 	local CONFFILE="$1"
 	local PACKAGE="$2"
 
-	[ -e "$CONFFILE" ] || return 0
+	[ -e "${DPKG_ROOT}$CONFFILE" ] || return 0
 	ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
 
 	local md5sum old_md5sum
-	md5sum="$(md5sum "$CONFFILE" | sed -e 's/ .*//')"
+	md5sum="$(md5sum "${DPKG_ROOT}$CONFFILE" | sed -e 's/ .*//')"
 	old_md5sum="$(dpkg-query -W -f='${Conffiles}' "$PACKAGE" | \
 		sed -n -e "\'^ $CONFFILE ' { s/ obsolete$//; s/.* //; p }")"
 	if [ "$md5sum" != "$old_md5sum" ]; then
-		mv -f "$CONFFILE" "$CONFFILE.dpkg-backup"
+		mv -f "${DPKG_ROOT}$CONFFILE" "${DPKG_ROOT}$CONFFILE.dpkg-backup"
 	else
-		mv -f "$CONFFILE" "$CONFFILE.dpkg-remove"
+		mv -f "${DPKG_ROOT}$CONFFILE" "${DPKG_ROOT}$CONFFILE.dpkg-remove"
 	fi
 }
 
 finish_rm_conffile() {
 	local CONFFILE="$1"
 
-	if [ -e "$CONFFILE.dpkg-backup" ]; then
-		echo "Obsolete conffile $CONFFILE has been modified by you."
-		echo "Saving as $CONFFILE.dpkg-bak ..."
-		mv -f "$CONFFILE.dpkg-backup" "$CONFFILE.dpkg-bak"
+	if [ -e "${DPKG_ROOT}$CONFFILE.dpkg-backup" ]; then
+		echo "Obsolete conffile ${DPKG_ROOT}$CONFFILE has been modified by you."
+		echo "Saving as ${DPKG_ROOT}$CONFFILE.dpkg-bak ..."
+		mv -f "${DPKG_ROOT}$CONFFILE.dpkg-backup" "${DPKG_ROOT}$CONFFILE.dpkg-bak"
 	fi
-	if [ -e "$CONFFILE.dpkg-remove" ]; then
-		echo "Removing obsolete conffile $CONFFILE ..."
-		rm -f "$CONFFILE.dpkg-remove"
+	if [ -e "${DPKG_ROOT}$CONFFILE.dpkg-remove" ]; then
+		echo "Removing obsolete conffile ${DPKG_ROOT}$CONFFILE ..."
+		rm -f "${DPKG_ROOT}$CONFFILE.dpkg-remove"
 	fi
 }
 
@@ -122,13 +122,13 @@ abort_rm_conffile() {
 
 	ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
 
-	if [ -e "$CONFFILE.dpkg-remove" ]; then
-		echo "Reinstalling $CONFFILE that was moved away"
-		mv "$CONFFILE.dpkg-remove" "$CONFFILE"
+	if [ -e "${DPKG_ROOT}$CONFFILE.dpkg-remove" ]; then
+		echo "Reinstalling ${DPKG_ROOT}$CONFFILE that was moved away"
+		mv "${DPKG_ROOT}$CONFFILE.dpkg-remove" "${DPKG_ROOT}$CONFFILE"
 	fi
-	if [ -e "$CONFFILE.dpkg-backup" ]; then
-		echo "Reinstalling $CONFFILE that was backupped"
-		mv "$CONFFILE.dpkg-backup" "$CONFFILE"
+	if [ -e "${DPKG_ROOT}$CONFFILE.dpkg-backup" ]; then
+		echo "Reinstalling ${DPKG_ROOT}$CONFFILE that was backupped"
+		mv "${DPKG_ROOT}$CONFFILE.dpkg-backup" "${DPKG_ROOT}$CONFFILE"
 	fi
 }
 
@@ -196,16 +196,16 @@ prepare_mv_conffile() {
 	local CONFFILE="$1"
 	local PACKAGE="$2"
 
-	[ -e "$CONFFILE" ] || return 0
+	[ -e "${DPKG_ROOT}$CONFFILE" ] || return 0
 
 	ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
 
 	local md5sum old_md5sum
-	md5sum="$(md5sum "$CONFFILE" | sed -e 's/ .*//')"
+	md5sum="$(md5sum "${DPKG_ROOT}$CONFFILE" | sed -e 's/ .*//')"
 	old_md5sum="$(dpkg-query -W -f='${Conffiles}' "$PACKAGE" | \
 		sed -n -e "\'^ $CONFFILE ' { s/ obsolete$//; s/.* //; p }")"
 	if [ "$md5sum" = "$old_md5sum" ]; then
-		mv -f "$CONFFILE" "$CONFFILE.dpkg-remove"
+		mv -f "${DPKG_ROOT}$CONFFILE" "${DPKG_ROOT}$CONFFILE.dpkg-remove"
 	fi
 }
 
@@ -214,16 +214,16 @@ finish_mv_conffile() {
 	local NEWCONFFILE="$2"
 	local PACKAGE="$3"
 
-	rm -f "$OLDCONFFILE.dpkg-remove"
+	rm -f "${DPKG_ROOT}$OLDCONFFILE.dpkg-remove"
 
-	[ -e "$OLDCONFFILE" ] || return 0
+	[ -e "${DPKG_ROOT}$OLDCONFFILE" ] || return 0
 	ensure_package_owns_file "$PACKAGE" "$OLDCONFFILE" || return 0
 
-	echo "Preserving user changes to $NEWCONFFILE (renamed from $OLDCONFFILE)..."
-	if [ -e "$NEWCONFFILE" ]; then
-		mv -f "$NEWCONFFILE" "$NEWCONFFILE.dpkg-new"
+	echo "Preserving user changes to ${DPKG_ROOT}$NEWCONFFILE (renamed from ${DPKG_ROOT}$OLDCONFFILE)..."
+	if [ -e "${DPKG_ROOT}$NEWCONFFILE" ]; then
+		mv -f "${DPKG_ROOT}$NEWCONFFILE" "${DPKG_ROOT}$NEWCONFFILE.dpkg-new"
 	fi
-	mv -f "$OLDCONFFILE" "$NEWCONFFILE"
+	mv -f "${DPKG_ROOT}$OLDCONFFILE" "${DPKG_ROOT}$NEWCONFFILE"
 }
 
 abort_mv_conffile() {
@@ -232,9 +232,9 @@ abort_mv_conffile() {
 
 	ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
 
-	if [ -e "$CONFFILE.dpkg-remove" ]; then
-		echo "Reinstalling $CONFFILE that was moved away"
-		mv "$CONFFILE.dpkg-remove" "$CONFFILE"
+	if [ -e "${DPKG_ROOT}$CONFFILE.dpkg-remove" ]; then
+		echo "Reinstalling ${DPKG_ROOT}$CONFFILE that was moved away"
+		mv "${DPKG_ROOT}$CONFFILE.dpkg-remove" "${DPKG_ROOT}$CONFFILE"
 	fi
 }
 
-- 
2.11.0

From 0a617a8d24e7264c1058f6252717a1a670f014de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastien=20ROUCARI=C3=88S?= <roucaries.bast...@gmail.com>
Date: Mon, 20 Mar 2017 16:26:09 +0100
Subject: [PATCH 5/5] Adapt t-switch-dir-to-symlink-rel/Makefile to honor
 DPKG_ROOT

---
 t-switch-dir-to-symlink-rel/Makefile | 118 +++++++++++++++++------------------
 1 file changed, 59 insertions(+), 59 deletions(-)

diff --git a/t-switch-dir-to-symlink-rel/Makefile b/t-switch-dir-to-symlink-rel/Makefile
index a347944..c2f81f1 100644
--- a/t-switch-dir-to-symlink-rel/Makefile
+++ b/t-switch-dir-to-symlink-rel/Makefile
@@ -8,31 +8,31 @@ include ../Test.mk
 test-case:
 	# Cannot switch a directory containing conffiles
 	$(DPKG_INSTALL) pkg-dir-conffile-0.deb
-	test -d /test-path/test-subpath
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
 	! $(DPKG_INSTALL) pkg-dir-conffile-1.deb
-	test -d /test-path/test-subpath
+	test -d '$(DPKG_INSTDIR)//test-path/test-subpath'
 	$(DPKG_PURGE) pkg-dir-conffile
 
 	# Cannot switch a directory containing files owned by another package
 	$(DPKG_INSTALL) pkg-dir-file-other.deb
 	$(DPKG_INSTALL) pkg-dir-symlink-int-0.deb
-	test -d /test-path/test-subpath
-	! test -h /test-path/test-subpath
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	! test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
 	! $(DPKG_INSTALL) pkg-dir-symlink-int-1.deb
-	test -d /test-path/test-subpath
-	! test -h /test-path/test-subpath
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	! test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_PURGE) pkg-dir-symlink-int
 	$(DPKG_PURGE) pkg-dir-file-other
 
 	# Cannot switch a directory containing local files
 	$(DPKG_INSTALL) pkg-dir-symlink-int-0.deb
-	test -d /test-path/test-subpath
-	! test -h /test-path/test-subpath
-	touch '/test-path/test-subpath/local file'
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	! test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
+	touch '$(DPKG_INSTDIR)/test-path/test-subpath/local file'
 	! $(DPKG_INSTALL) pkg-dir-symlink-int-1.deb
-	test -d /test-path/test-subpath
-	! test -h /test-path/test-subpath
-	rm '/test-path/test-subpath/local file'
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	! test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
+	rm '$(DPKG_INSTDIR)/test-path/test-subpath/local file'
 	$(DPKG_PURGE) pkg-dir-symlink-int
 
 	#
@@ -42,93 +42,93 @@ test-case:
 	# Switch a directory to a symlink, contents moved within the package,
 	# with intermediate full installs.
 	$(DPKG_INSTALL) pkg-dir-symlink-int-0.deb
-	test -d /test-path/test-subpath
-	! test -h /test-path/test-subpath
+	test -d '$(DPKG_INSTDIR)//test-path/test-subpath'
+	! test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_INSTALL) pkg-dir-symlink-int-1.deb
-	test -h /test-path/test-subpath
+	test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_PURGE) pkg-dir-symlink-int
-	! test -e /test-path/test-subpath
+	! test -e '$(DPKG_INSTDIR)/test-path/test-subpath'
 
 	# Switch a directory to a symlink, contents moved within the package,
 	# with full install, upgrade with upack and configure.
 	$(DPKG_INSTALL) pkg-dir-symlink-int-0.deb
-	! test -h /test-path/test-subpath
-	test -d /test-path/test-subpath
+	! test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_UNPACK) pkg-dir-symlink-int-1.deb
-	! test -h /test-path/test-subpath
-	test -d /test-path/test-subpath
+	! test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_CONFIGURE) pkg-dir-symlink-int
-	test -h /test-path/test-subpath
+	test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_PURGE) pkg-dir-symlink-int
-	! test -e /test-path/test-subpath
+	! test -e '$(DPKG_INSTDIR)/test-path/test-subpath'
 
 	# Switch a directory to a symlink, contents moved within the package,
 	# with two unpacks and configure.
 	$(DPKG_UNPACK) pkg-dir-symlink-int-0.deb
-	! test -h /test-path/test-subpath
-	test -d /test-path/test-subpath
+	! test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_UNPACK) pkg-dir-symlink-int-1.deb
-	! test -h /test-path/test-subpath
-	test -d /test-path/test-subpath
+	! test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_CONFIGURE) pkg-dir-symlink-int
-	test -h /test-path/test-subpath
+	test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_PURGE) pkg-dir-symlink-int
-	! test -e /test-path/test-subpath
+	! test -e '$(DPKG_INSTDIR)/test-path/test-subpath'
 
 	# Switch a directory to a symlink, contents moved to another package,
 	# with intermediate full installs.
 	$(DPKG_INSTALL) pkg-dir-symlink-ext-0.deb
-	test -d /test-path/test-subpath
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_INSTALL) pkg-dir-file-moved.deb
-	test -d /test-path/test-subpath
-	test -d /test-dir
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-dir'
 	$(DPKG_INSTALL) pkg-dir-symlink-ext-1.deb
-	test -h /test-path/test-subpath
-	test -d /test-path/test-subpath
-	test "`readlink /test-path/test-subpath`" = "../test-dir"
-	! test -h /test-dir
-	test -d /test-dir
-	test -f /test-dir/file-normal
+	test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test "`readlink '$(DPKG_INSTDIR)/test-path/test-subpath'`" = "../test-dir"
+	! test -h '$(DPKG_INSTDIR)/test-dir'
+	test -d '$(DPKG_INSTDIR)/test-dir'
+	test -f '$(DPKG_INSTDIR)/test-dir/file-normal'
 	$(DPKG_PURGE) pkg-dir-symlink-ext
 	$(DPKG_PURGE) pkg-dir-file-moved
 
 	# Switch a directory to a symlink, contents moved to another package,
 	# with full installs, upgrade with upack and configure.
 	$(DPKG_INSTALL) pkg-dir-symlink-ext-0.deb
-	test -d /test-path/test-subpath
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_INSTALL) pkg-dir-file-moved.deb
-	test -d /test-path/test-subpath
-	test -d /test-dir
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-dir'
 	$(DPKG_UNPACK) pkg-dir-symlink-ext-1.deb
-	test -d /test-path/test-subpath
-	test -d /test-dir
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-dir'
 	$(DPKG_CONFIGURE) -a
-	test -h /test-path/test-subpath
-	test -d /test-path/test-subpath
-	test "`readlink /test-path/test-subpath`" = "../test-dir"
-	! test -h /test-dir
-	test -d /test-dir
-	test -f /test-dir/file-normal
+	test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test "`readlink '$(DPKG_INSTDIR)/test-path/test-subpath'`" = "../test-dir"
+	! test -h '$(DPKG_INSTDIR)/test-dir'
+	test -d '$(DPKG_INSTDIR)/test-dir'
+	test -f '$(DPKG_INSTDIR)/test-dir/file-normal'
 	$(DPKG_PURGE) pkg-dir-symlink-ext
 	$(DPKG_PURGE) pkg-dir-file-moved
 
 	# Switch a directory to a symlink, contents moved to another package,
 	# with three unpacks and configure.
 	$(DPKG_UNPACK) pkg-dir-symlink-ext-0.deb
-	test -d /test-path/test-subpath
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
 	$(DPKG_UNPACK) pkg-dir-file-moved.deb
-	test -d /test-path/test-subpath
-	test -d /test-dir
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-dir'
 	$(DPKG_UNPACK) pkg-dir-symlink-ext-1.deb
-	test -d /test-path/test-subpath
-	test -d /test-dir
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-dir'
 	$(DPKG_CONFIGURE) -a
-	test -h /test-path/test-subpath
-	test -d /test-path/test-subpath
-	test "`readlink /test-path/test-subpath`" = "../test-dir"
-	! test -h /test-dir
-	test -d /test-dir
-	test -f /test-dir/file-normal
+	test -h '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test -d '$(DPKG_INSTDIR)/test-path/test-subpath'
+	test "`readlink '$(DPKG_INSTDIR)/test-path/test-subpath'`" = "../test-dir"
+	! test -h '$(DPKG_INSTDIR)/test-dir'
+	test -d '$(DPKG_INSTDIR)/test-dir'
+	test -f '$(DPKG_INSTDIR)/test-dir/file-normal'
 	$(DPKG_PURGE) pkg-dir-symlink-ext
 	$(DPKG_PURGE) pkg-dir-file-moved
 
-- 
2.11.0

From 9397c0f58e3611886d1fdcdb4543a0739372bef2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastien=20ROUCARI=C3=88S?= <roucaries.bast...@gmail.com>
Date: Mon, 20 Mar 2017 00:39:46 +0100
Subject: [PATCH 4/5] Fix t-switch-dir-to-symlink-abs/

---
 Makefile                             |   4 +-
 t-switch-dir-to-symlink-abs/Makefile | 117 +++++++++++++++++------------------
 2 files changed, 60 insertions(+), 61 deletions(-)

diff --git a/Makefile b/Makefile
index 99c58bf..458e8d3 100644
--- a/Makefile
+++ b/Makefile
@@ -123,10 +123,10 @@ ifdef DPKG_HAS_MAINTSCRIPT_SWITCH_DIR_SYMLINK
 # FIXME: dpkg-maintscript-helper does not support $DPKG_ROOT (#832176)
 TESTS_PASS += t-switch-symlink-abs-to-dir
 TESTS_PASS += t-switch-symlink-rel-to-dir
-ifndef DPKG_NOT_ROOT
+#ifndef DPKG_NOT_ROOT
 TESTS_PASS += t-switch-dir-to-symlink-abs
 TESTS_PASS += t-switch-dir-to-symlink-rel
-endif
+#endif
 endif
 TESTS_PASS += t-source-minimal
 TESTS_PASS += t-substvars
diff --git a/t-switch-dir-to-symlink-abs/Makefile b/t-switch-dir-to-symlink-abs/Makefile
index c5f8c84..7852cb8 100644
--- a/t-switch-dir-to-symlink-abs/Makefile
+++ b/t-switch-dir-to-symlink-abs/Makefile
@@ -8,31 +8,31 @@ include ../Test.mk
 test-case:
 	# Cannot switch a directory containing conffiles
 	$(DPKG_INSTALL) pkg-dir-conffile-0.deb
-	test -d /test-path
+	test -d '$(DPKG_INSTDIR)/test-path'
 	! $(DPKG_INSTALL) pkg-dir-conffile-1.deb
-	test -d /test-path
+	test -d '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_PURGE) pkg-dir-conffile
 
 	# Cannot switch a directory containing files owned by another package
 	$(DPKG_INSTALL) pkg-dir-file-other.deb
 	$(DPKG_INSTALL) pkg-dir-symlink-int-0.deb
-	test -d /test-path
-	! test -h /test-path
+	test -d '$(DPKG_INSTDIR)/test-path'
+	! test -h '$(DPKG_INSTDIR)/test-path'
 	! $(DPKG_INSTALL) pkg-dir-symlink-int-1.deb
-	test -d /test-path
-	! test -h /test-path
+	test -d '$(DPKG_INSTDIR)/test-path'
+	! test -h '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_PURGE) pkg-dir-symlink-int
 	$(DPKG_PURGE) pkg-dir-file-other
 
 	# Cannot switch a directory containing local files
 	$(DPKG_INSTALL) pkg-dir-symlink-int-0.deb
-	test -d /test-path
-	! test -h /test-path
-	touch '/test-path/local file'
+	test -d '$(DPKG_INSTDIR)/test-path'
+	! test -h '$(DPKG_INSTDIR)/test-path'
+	touch '$(DPKG_INSTDIR)/test-path/local file'
 	! $(DPKG_INSTALL) pkg-dir-symlink-int-1.deb
-	test -d /test-path
-	! test -h /test-path
-	rm '/test-path/local file'
+	test -d '$(DPKG_INSTDIR)/test-path'
+	! test -h '$(DPKG_INSTDIR)/test-path'
+	rm '$(DPKG_INSTDIR)/test-path/local file'
 	$(DPKG_PURGE) pkg-dir-symlink-int
 
 	#
@@ -42,93 +42,92 @@ test-case:
 	# Switch a directory to a symlink, contents moved within the package,
 	# with intermediate full installs.
 	$(DPKG_INSTALL) pkg-dir-symlink-int-0.deb
-	test -d /test-path
-	! test -h /test-path
+	test -d '$(DPKG_INSTDIR)/test-path'
+	! test -h '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_INSTALL) pkg-dir-symlink-int-1.deb
-	test -h /test-path
+	test -h '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_PURGE) pkg-dir-symlink-int
-	! test -e /test-path
+	! test -e '$(DPKG_INSTDIR)/test-path'
 
 	# Switch a directory to a symlink, contents moved within the package,
 	# with full install, upgrade with upack and configure.
 	$(DPKG_INSTALL) pkg-dir-symlink-int-0.deb
-	! test -h /test-path
-	test -d /test-path
+	! test -h '$(DPKG_INSTDIR)/test-path'
+	test -d '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_UNPACK) pkg-dir-symlink-int-1.deb
-	! test -h /test-path
-	test -d /test-path
+	! test -h '$(DPKG_INSTDIR)/test-path'
+	test -d '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_CONFIGURE) pkg-dir-symlink-int
-	test -h /test-path
+	test -h '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_PURGE) pkg-dir-symlink-int
-	! test -e /test-path
+	! test -e '$(DPKG_INSTDIR)/test-path'
 
 	# Switch a directory to a symlink, contents moved within the package,
 	# with two unpacks and configure.
 	$(DPKG_UNPACK) pkg-dir-symlink-int-0.deb
-	! test -h /test-path
-	test -d /test-path
+	! test -h '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_UNPACK) pkg-dir-symlink-int-1.deb
-	! test -h /test-path
-	test -d /test-path
+	! test -h '$(DPKG_INSTDIR)/test-path'
+	test -d '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_CONFIGURE) pkg-dir-symlink-int
-	test -h /test-path
+	test -h '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_PURGE) pkg-dir-symlink-int
-	! test -e /test-path
+	! test -e '$(DPKG_INSTDIR)/test-path'
 
 	# Switch a directory to a symlink, contents moved to another package,
 	# with intermediate full installs.
 	$(DPKG_INSTALL) pkg-dir-symlink-ext-0.deb
-	test -d /test-path
+	test -d '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_INSTALL) pkg-dir-file-moved.deb
-	test -d /test-path
-	test -d /test-dir
+	test -d '$(DPKG_INSTDIR)/test-path'
+	test -d '$(DPKG_INSTDIR)/test-dir'
 	$(DPKG_INSTALL) pkg-dir-symlink-ext-1.deb
-	test -h /test-path
-	test -d /test-path
-	test "`readlink -f /test-path`" = "/test-dir"
-	! test -h /test-dir
-	test -d /test-dir
-	test -f /test-dir/file-normal
+	test -h '$(DPKG_INSTDIR)/test-path'
+	test -d '$(DPKG_INSTDIR)/test-path'
+	test "`readlink -f '$(DPKG_INSTDIR)/test-path'`" = "`readlink -f $(DPKG_INSTDIR)/test-dir`"
+	! test -h '$(DPKG_INSTDIR)/test-dir'
+	test -d '$(DPKG_INSTDIR)/test-dir'
+	test -f '$(DPKG_INSTDIR)/test-dir/file-normal'
 	$(DPKG_PURGE) pkg-dir-symlink-ext
 	$(DPKG_PURGE) pkg-dir-file-moved
 
 	# Switch a directory to a symlink, contents moved to another package,
 	# with full installs, upgrade with upack and configure.
 	$(DPKG_INSTALL) pkg-dir-symlink-ext-0.deb
-	test -d /test-path
+	test -d '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_INSTALL) pkg-dir-file-moved.deb
-	test -d /test-path
-	test -d /test-dir
+	test -d '$(DPKG_INSTDIR)/test-path'
+	test -d '$(DPKG_INSTDIR)/test-dir'
 	$(DPKG_UNPACK) pkg-dir-symlink-ext-1.deb
-	test -d /test-path
-	test -d /test-dir
+	test -d '$(DPKG_INSTDIR)/test-path'
+	test -d '$(DPKG_INSTDIR)/test-dir'
 	$(DPKG_CONFIGURE) -a
-	test -h /test-path
-	test -d /test-path
-	test "`readlink -f /test-path`" = "/test-dir"
-	! test -h /test-dir
-	test -d /test-dir
-	test -f /test-dir/file-normal
+	test -h '$(DPKG_INSTDIR)/test-path'
+	test -d '$(DPKG_INSTDIR)/test-path'
+	test "`readlink -f '$(DPKG_INSTDIR)/test-path'`" = "`readlink -f $(DPKG_INSTDIR)/test-dir`"
+	! test -h '$(DPKG_INSTDIR)/test-dir'
+	test -d '$(DPKG_INSTDIR)/test-dir'
+	test -f '$(DPKG_INSTDIR)/test-dir/file-normal'
 	$(DPKG_PURGE) pkg-dir-symlink-ext
 	$(DPKG_PURGE) pkg-dir-file-moved
 
 	# Switch a directory to a symlink, contents moved to another package,
 	# with three unpacks and configure.
 	$(DPKG_UNPACK) pkg-dir-symlink-ext-0.deb
-	test -d /test-path
+	test -d '$(DPKG_INSTDIR)/test-path'
 	$(DPKG_UNPACK) pkg-dir-file-moved.deb
-	test -d /test-path
-	test -d /test-dir
+	test -d '$(DPKG_INSTDIR)/test-path'
+	test -d '$(DPKG_INSTDIR)/test-dir'
 	$(DPKG_UNPACK) pkg-dir-symlink-ext-1.deb
-	test -d /test-path
-	test -d /test-dir
+	test -d '$(DPKG_INSTDIR)/test-path'
+	test -d '$(DPKG_INSTDIR)/test-dir'
 	$(DPKG_CONFIGURE) -a
-	test -h /test-path
-	test -d /test-path
-	test "`readlink -f /test-path`" = "/test-dir"
-	! test -h /test-dir
-	test -d /test-dir
-	test -f /test-dir/file-normal
+	test -h '$(DPKG_INSTDIR)/test-path'
+	test -d '$(DPKG_INSTDIR)/test-path'
+	test "`readlink -f '$(DPKG_INSTDIR)/test-path'`" = "`readlink -f '$(DPKG_INSTDIR)/test-dir'`"
+	! test -h '$(DPKG_INSTDIR)/test-dir'
+	test -d '$(DPKG_INSTDIR)/test-dir'
+	test -f '$(DPKG_INSTDIR)/test-dir/file-normal'
 	$(DPKG_PURGE) pkg-dir-symlink-ext
 	$(DPKG_PURGE) pkg-dir-file-moved
 
-- 
2.11.0

From 34d6693e7cf198e932849144403619ebb2045472 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastien=20ROUCARI=C3=88S?= <roucaries.bast...@gmail.com>
Date: Tue, 14 Mar 2017 18:54:56 +0100
Subject: [PATCH 3/5] Fix symlink-to-dir testsuite

---
 Makefile                             | 2 +-
 dpkgdb/updates/.gitignore            | 1 -
 t-switch-symlink-rel-to-dir/Makefile | 8 ++++----
 3 files changed, 5 insertions(+), 6 deletions(-)
 delete mode 100644 dpkgdb/updates/.gitignore

diff --git a/Makefile b/Makefile
index c5261f7..99c58bf 100644
--- a/Makefile
+++ b/Makefile
@@ -120,10 +120,10 @@ TESTS_PASS += t-package-type
 TESTS_PASS += t-symlink-dir
 # This only works with dpkg >= 1.17.x
 ifdef DPKG_HAS_MAINTSCRIPT_SWITCH_DIR_SYMLINK
-ifndef DPKG_NOT_ROOT
 # FIXME: dpkg-maintscript-helper does not support $DPKG_ROOT (#832176)
 TESTS_PASS += t-switch-symlink-abs-to-dir
 TESTS_PASS += t-switch-symlink-rel-to-dir
+ifndef DPKG_NOT_ROOT
 TESTS_PASS += t-switch-dir-to-symlink-abs
 TESTS_PASS += t-switch-dir-to-symlink-rel
 endif
diff --git a/dpkgdb/updates/.gitignore b/dpkgdb/updates/.gitignore
deleted file mode 100644
index df20a03..0000000
--- a/dpkgdb/updates/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-[0-9]*
diff --git a/t-switch-symlink-rel-to-dir/Makefile b/t-switch-symlink-rel-to-dir/Makefile
index 79a6a14..3af8ce7 100644
--- a/t-switch-symlink-rel-to-dir/Makefile
+++ b/t-switch-symlink-rel-to-dir/Makefile
@@ -6,14 +6,14 @@ test-case:
 	$(DPKG_INSTALL) pkg-dir-real.deb
 
 	$(DPKG_INSTALL) pkg-dir-symlink-0.deb
-	test -h /test-path/test-symlink
+	test -h '$(DPKG_INSTDIR)/test-path/test-symlink'
 
 	$(DPKG_INSTALL) pkg-dir-symlink-1.deb
-	! test -h /test-path/test-symlink
-	test -d /test-path/test-symlink
+	! test -h '$(DPKG_INSTDIR)/test-path/test-symlink'
+	test -d '$(DPKG_INSTDIR)/test-path/test-symlink'
 
 	$(DPKG_PURGE) pkg-dir-symlink
-	! test -e /test-path/test-symlink
+	! test -e '$(DPKG_INSTDIR)/test-path/test-symlink'
 
 	$(DPKG_PURGE) pkg-dir-real
 
-- 
2.11.0

From 60704a422ca895ce85889c691d2f1b956b34186e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastien=20ROUCARI=C3=88S?= <roucaries.bast...@gmail.com>
Date: Tue, 14 Mar 2017 18:32:53 +0100
Subject: [PATCH 2/5] Fix t-conffile-rename in case of DPKG_ROOT

---
 Makefile                                            | 3 ---
 t-conffile-rename/Makefile                          | 4 ++--
 t-conffile-rename/pkg-conff-rename-1/DEBIAN/preinst | 2 +-
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index a96df30..c5261f7 100644
--- a/Makefile
+++ b/Makefile
@@ -114,10 +114,7 @@ TESTS_PASS += t-conffile-replaces-existing
 TESTS_PASS += t-conffile-replaces-existing-and-upgrade
 TESTS_PASS += t-conffile-replaces-disappear
 TESTS_PASS += t-conffile-versioned-replaces-downgrade
-ifndef DPKG_NOT_ROOT
-# FIXME: dpkg-maintscript-helper does not support $DPKG_ROOT (#832176)
 TESTS_PASS += t-conffile-rename
-endif
 TESTS_PASS += t-queue-process-deconf-dupe
 TESTS_PASS += t-package-type
 TESTS_PASS += t-symlink-dir
diff --git a/t-conffile-rename/Makefile b/t-conffile-rename/Makefile
index a96ad67..a8d0272 100644
--- a/t-conffile-rename/Makefile
+++ b/t-conffile-rename/Makefile
@@ -21,9 +21,9 @@ test-case:
 	$(DPKG_PURGE) pkg-conff-rename
 	# Abort-upgrade restores the to-be-renamed conffile
 	$(DPKG_INSTALL) pkg-conff-rename-0.deb
-	$(BEROOT) touch /fail-preinst
+	$(BEROOT) touch '$(DPKG_INSTDIR)/fail-preinst'
 	$(DPKG_INSTALL) pkg-conff-rename-1.deb || true
-	$(BEROOT) rm -f /fail-preinst
+	$(BEROOT) rm -f '$(DPKG_INSTDIR)/fail-preinst'
 	test -f '$(DPKG_INSTDIR)/test-conffile-old'
 	test ! -f '$(DPKG_INSTDIR)/test-conffile-new'
 	test ! -f '$(DPKG_INSTDIR)/test-conffile-old.dpkg-remove'
diff --git a/t-conffile-rename/pkg-conff-rename-1/DEBIAN/preinst b/t-conffile-rename/pkg-conff-rename-1/DEBIAN/preinst
index 534210d..775093f 100755
--- a/t-conffile-rename/pkg-conff-rename-1/DEBIAN/preinst
+++ b/t-conffile-rename/pkg-conff-rename-1/DEBIAN/preinst
@@ -3,7 +3,7 @@ if dpkg-maintscript-helper supports mv_conffile; then
     dpkg-maintscript-helper mv_conffile /test-conffile-old /test-conffile-new 0 -- "$@"
 fi
 
-if [ -e /fail-preinst ]; then
+if [ -e "$DPKG_ROOT/fail-preinst" ]; then
     exit 1
 fi
 
-- 
2.11.0

From af56555734c975ff7742ab4e7d9e33a36fd45da9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastien=20ROUCARI=C3=88S?= <roucaries.bast...@gmail.com>
Date: Tue, 14 Mar 2017 18:25:07 +0100
Subject: [PATCH 1/5] Allow pkg-conff-obsolete to run with DPKG_ROOT

---
 Makefile                                           |  3 +-
 t-conffile-obsolete/Makefile                       | 36 +++++++++++-----------
 .../pkg-conff-obsolete-2/DEBIAN/preinst            |  2 +-
 3 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/Makefile b/Makefile
index 996fab1..a96df30 100644
--- a/Makefile
+++ b/Makefile
@@ -97,9 +97,8 @@ TESTS_PASS += t-file-replaces
 TESTS_PASS += t-file-replaces-disappear
 TESTS_PASS += t-file-replaces-versioned
 TESTS_PASS += t-conffile-normal
-ifndef DPKG_NOT_ROOT
-# FIXME: dpkg-maintscript-helper does not support $DPKG_ROOT (#832176)
 TESTS_PASS += t-conffile-obsolete
+ifndef DPKG_NOT_ROOT
 # FIXME: Somehow pkg-conff-takeover cannot take over /test-conffile
 TESTS_PASS += t-conffile-orphan
 endif
diff --git a/t-conffile-obsolete/Makefile b/t-conffile-obsolete/Makefile
index 89a4499..5fdda82 100644
--- a/t-conffile-obsolete/Makefile
+++ b/t-conffile-obsolete/Makefile
@@ -5,37 +5,37 @@ include ../Test.mk
 test-case:
 	$(DPKG_INSTALL) pkg-conff-obsolete-0.deb
 	$(DPKG_INSTALL) pkg-conff-obsolete-1.deb
-	test -f /test-conffile
+	test -f '$(DPKG_INSTDIR)/test-conffile'
 	$(DPKG_PURGE) pkg-conff-obsolete
-	test ! -f /test-conffile
+	test ! -f '$(DPKG_INSTDIR)/test-conffile'
 	# Unmodified conffile is autoremoved for the user
 	$(DPKG_INSTALL) pkg-conff-obsolete-0.deb
 	$(DPKG_UNPACK) pkg-conff-obsolete-2.deb
-	test -f /test-conffile.dpkg-remove
-	test ! -f /test-conffile.dpkg-backup
+	test -f '$(DPKG_INSTDIR)/test-conffile.dpkg-remove'
+	test ! -f '$(DPKG_INSTDIR)/test-conffile.dpkg-backup'
 	$(DPKG_CONFIGURE) pkg-conff-obsolete
-	test ! -f /test-conffile
-	test ! -f /test-conffile.dpkg-bak
-	test ! -f /test-conffile.dpkg-backup
-	test ! -f /test-conffile.dpkg-remove
+	test ! -f '$(DPKG_INSTDIR)/test-conffile'
+	test ! -f '$(DPKG_INSTDIR)/test-conffile.dpkg-bak'
+	test ! -f '$(DPKG_INSTDIR)/test-conffile.dpkg-backup'
+	test ! -f '$(DPKG_INSTDIR)/test-conffile.dpkg-remove'
 	$(DPKG_PURGE) pkg-conff-obsolete
 	# Modified conffile is moved away in .dpkg-bak for the user
 	$(DPKG_INSTALL) pkg-conff-obsolete-0.deb
-	$(BEROOT) sh -c "echo foo >>/test-conffile"
+	$(BEROOT) sh -c "echo foo >> '$(DPKG_INSTDIR)/test-conffile'"
 	$(DPKG_INSTALL) pkg-conff-obsolete-2.deb
-	test ! -f /test-conffile
-	test -f /test-conffile.dpkg-bak
+	test ! -f '$(DPKG_INSTDIR)/test-conffile'
+	test -f '$(DPKG_INSTDIR)/test-conffile.dpkg-bak'
 	$(DPKG_PURGE) pkg-conff-obsolete
-	test ! -f /test-conffile.dpkg-bak
+	test ! -f '$(DPKG_INSTDIR)/test-conffile.dpkg-bak'
 	# Abort-upgrade restores the to-be-removed conffile
 	$(DPKG_INSTALL) pkg-conff-obsolete-0.deb
-	$(BEROOT) touch /fail-preinst
+	$(BEROOT) touch '$(DPKG_INSTDIR)/fail-preinst'
 	$(DPKG_INSTALL) pkg-conff-obsolete-2.deb || true
-	$(BEROOT) rm -f /fail-preinst
-	test -f /test-conffile
-	test ! -f /test-conffile.dpkg-remove
-	test ! -f /test-conffile.dpkg-bak
-	test ! -f /test-conffile.dpkg-backup
+	$(BEROOT) rm -f '$(DPKG_INSTDIR)/fail-preinst'
+	test -f '$(DPKG_INSTDIR)/test-conffile'
+	test ! -f '$(DPKG_INSTDIR)/test-conffile.dpkg-remove'
+	test ! -f '$(DPKG_INSTDIR)/test-conffile.dpkg-bak'
+	test ! -f '$(DPKG_INSTDIR)/test-conffile.dpkg-backup'
 
 test-clean:
 	$(DPKG_PURGE) pkg-conff-obsolete
diff --git a/t-conffile-obsolete/pkg-conff-obsolete-2/DEBIAN/preinst b/t-conffile-obsolete/pkg-conff-obsolete-2/DEBIAN/preinst
index de6b54a..c0e592b 100755
--- a/t-conffile-obsolete/pkg-conff-obsolete-2/DEBIAN/preinst
+++ b/t-conffile-obsolete/pkg-conff-obsolete-2/DEBIAN/preinst
@@ -3,7 +3,7 @@ if dpkg-maintscript-helper supports rm_conffile; then
     dpkg-maintscript-helper rm_conffile /test-conffile 0 -- "$@"
 fi
 
-if [ -e /fail-preinst ]; then
+if [ -e "$DPKG_ROOT/fail-preinst" ]; then
     exit 1
 fi
 
-- 
2.11.0

Reply via email to