[dpkg] 21/192: dpkg-maintscript-helper: Print all unowned files from a directory

Ximin Luo infinity0 at debian.org
Tue Oct 17 11:03:52 UTC 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch pu/reproducible_builds
in repository dpkg.

commit 8ffbe5f5c0012c740e1b61c460cea093ac080dea
Author: Guillem Jover <guillem at debian.org>
Date:   Sat Apr 22 18:48:10 2017 +0200

    dpkg-maintscript-helper: Print all unowned files from a directory
    
    Add a new internal command that is not part of the public interface,
    that takes care of checking whether a pathname is owned by a package.
    
    This internal command has some logic to prevent external abuse, by
    checking whether the parent has set a specific environment variable
    with a token that changes per release.
    
    The code will list all unowned files because xargs does not short-circuit
    on the first command erroring out, as long these do not terminate with an
    exit code of 255.
    
    Closes: #813454, #860238
    Based-on-patch-by: Bastien ROUCARIÈS <roucaries.bastien at gmail.com>
---
 debian/changelog                   |  4 ++++
 scripts/dpkg-maintscript-helper.sh | 31 +++++++++++++++++++++++--------
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 92b2b27..d582817 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -6,6 +6,10 @@ dpkg (1.18.24) UNRELEASED; urgency=medium
     when scanning symbols/shlibs files. This was causing generation of bogus
     dependencies when multiple packages provide the same SONAME on different
     directories. Regression introduced in dpkg 1.18.17. Closes: #860979
+  * Make dpkg-maintscript-helper print all unowned files from a directory
+    when printing the error message, to ease debugging those problems after
+    the fact. Closes: #813454, #860238
+    Based on a patch by Bastien ROUCARIÈS <roucaries.bastien at gmail.com>.
   * Architecture support:
     - Add support for ARM64 ILP32. Closes: #824742
       Thanks to Wookey <wookey at wookware.org>.
diff --git a/scripts/dpkg-maintscript-helper.sh b/scripts/dpkg-maintscript-helper.sh
index 1a0459f..378d03c 100755
--- a/scripts/dpkg-maintscript-helper.sh
+++ b/scripts/dpkg-maintscript-helper.sh
@@ -414,16 +414,12 @@ 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" || \
+	export DPKG_MAINTSCRIPT_HELPER_INTERNAL_API="$version"
+	find "$PATHNAME" -print0 | \
+		xargs -0 -n1 $0 _internal_pkg_must_own_file "$PACKAGE" || \
 		error "directory '$PATHNAME' contains files not owned by" \
 		      "package $PACKAGE, cannot switch to symlink"
+	unset DPKG_MAINTSCRIPT_HELPER_INTERNAL_API
 
 	# At this point, we know that the directory either contains no files,
 	# or only non-conffiles owned by the package.
@@ -517,6 +513,21 @@ ensure_package_owns_file() {
 	return 0
 }
 
+internal_pkg_must_own_file()
+{
+	local PACKAGE="$1"
+	local FILE="$2"
+
+	if [ "$DPKG_MAINTSCRIPT_HELPER_INTERNAL_API" != "$version" ]; then
+		error "internal API used by external command"
+	fi
+
+	if ! ensure_package_owns_file "$PACKAGE" "$FILE"; then
+		error "file '$FILE' not owned by package '$PACKAGE'"
+	fi
+	return 0
+}
+
 symlink_match()
 {
 	local SYMLINK="$1"
@@ -612,6 +623,10 @@ symlink_to_dir)
 dir_to_symlink)
 	dir_to_symlink "$@"
 	;;
+_internal_pkg_must_own_file)
+	# This is an internal command, must not be used outside this program.
+	internal_pkg_must_own_file "$@"
+	;;
 --help|help|-?)
 	usage
 	;;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list