From bddad857dfea2d90d60684374ada1994da4961f4 Mon Sep 17 00:00:00 2001 From: Marcin Owsiany Date: Fri, 11 Mar 2011 09:37:35 +0000 Subject: [PATCH] Use dpkg-query rather than directly access dpkg database files. git-svn-id: svn://svn.debian.org/cruft/trunk@210 14f89510-8efc-0310-927e-d869d0d96f2b --- README | 10 +++++---- common.sh | 50 ++++++++++++++++++++++++++++++++++++++--- debian/changelog | 9 ++++++++ explain/apt-listchanges | 4 +--- explain/cvs2svn | 4 +--- explain/linda | 4 +--- explain/reportbug | 4 +--- explain/rubber | 4 +--- filters_list | 6 ++--- 9 files changed, 70 insertions(+), 25 deletions(-) diff --git a/README b/README index ebe3aa8..d92c9ee 100644 --- a/README +++ b/README @@ -85,9 +85,11 @@ the same name. So if you want to override /usr/lib/cruft/explain/foo, just create an executable file called /etc/cruft/explain/foo. Also, any explain script will be run only if any of the following is true: - - a package with the same name as the file is not completly purged (that - means, a .list, .postrm or .prerm file for this package exists in - /var/lib/dpkg/info) + - a package with the same name as the file is not completly purged - that is, + at least one of the following exist for the package: + * a non-empty file list, + * a postrm file, + * a prerm file. - the name of the file contains no lower-case characters. Thus, the way to have a script run regardless of any package being installed, just name it in UPPER_CASE @@ -101,7 +103,7 @@ following filter files will be selected: - /etc/cruft/filters-TYPE/* - /etc/cruft/filters/* - - /var/lib/dpkg/info/*.extrafiles + - installed "extrafiles" control files (in dpkg database) - /usr/lib/cruft/filters-TYPE/* - /usr/lib/cruft/filters/* diff --git a/common.sh b/common.sh index b3a9dc9..f9238e0 100644 --- a/common.sh +++ b/common.sh @@ -163,12 +163,56 @@ fixup_slashes() sed 's:/\.$:/:;s:/$::;s:^$:/:' } +package_has_script() +{ + local pkg="$1" + local script="$2" + local ctrl_path_tmp=$(mktemp) + if ! dpkg-query --control-path "${pkg}" "${script}" >"${ctrl_path_tmp}" 2>/dev/null + then + rm -f "${ctrl_path_tmp}" + # error, most likely ${pkg} is not installed + return 1 + else + lines=$(wc -l < "${ctrl_path_tmp}") + rm -f "${ctrl_path_tmp}" + if [ "${lines}" -eq 0 ] + then + # no path returned + return 1 + else + return 0 + fi + fi +} + +package_has_files() +{ + local pkg="$1" + local list_tmp=$(mktemp) + if ! dpkg-query --listfiles "${pkg}" >"${list_tmp}" 2>/dev/null + then + rm -f "${list_tmp}" + # error, most likely ${pkg} is not installed + return 1 + else + lines=$(wc -l < "${list_tmp}") + if [ "${lines}" -eq 0 ] + then + # has no files + return 1 + else + return 0 + fi + fi +} + package_installed() { local pkg="$1" - [ -f "/var/lib/dpkg/info/${pkg}.list" ] || - [ -f "/var/lib/dpkg/info/${pkg}.prerm" ] || - [ -f "/var/lib/dpkg/info/${pkg}.postrm" ] + package_has_script "${pkg}" prerm || + package_has_script "${pkg}" postrm || + package_has_files "${pkg}" } # return 0 if file with that name is to be processed diff --git a/debian/changelog b/debian/changelog index 4be0851..16b73c7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +cruft (0.9.14) unstable; urgency=low + + * Instead of directly accessing installed maintainer scripts and dpkg "list" + files, call dpkg-query as appropriate. This makes it much slower in some + cases but at least it will let us survive the incoming revolution in dpkg + database (closes: Bug#616068) + + -- Marcin Owsiany Wed, 09 Mar 2011 09:21:40 +0000 + cruft (0.9.13) experimental; urgency=high * Changed all bash and sh scripts to use dash, because bash makes it hard to diff --git a/explain/apt-listchanges b/explain/apt-listchanges index 3b16439..224e2d3 100755 --- a/explain/apt-listchanges +++ b/explain/apt-listchanges @@ -1,6 +1,4 @@ #!/bin/dash p='apt-listchanges' -f="/var/lib/dpkg/info/$p.list" set -e -if [ ! -e "$f" ]; then exit 1; fi -cat "$f" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done +dpkg-query --listfiles "${p}" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done diff --git a/explain/cvs2svn b/explain/cvs2svn index 8d4f886..ba4903f 100755 --- a/explain/cvs2svn +++ b/explain/cvs2svn @@ -1,6 +1,4 @@ #!/bin/dash p='cvs2svn' -f="/var/lib/dpkg/info/$p.list" set -e -if [ ! -e "$f" ]; then exit 1; fi -cat "$f" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done +dpkg-query --listfiles "${p}" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done diff --git a/explain/linda b/explain/linda index bf44235..582eb2f 100755 --- a/explain/linda +++ b/explain/linda @@ -1,6 +1,4 @@ #!/bin/dash p='linda' -f="/var/lib/dpkg/info/$p.list" set -e -if [ ! -e "$f" ]; then exit 1; fi -cat "$f" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done +dpkg-query --listfiles "${p}" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done diff --git a/explain/reportbug b/explain/reportbug index ff2fd81..726111c 100755 --- a/explain/reportbug +++ b/explain/reportbug @@ -1,6 +1,4 @@ #!/bin/dash p='reportbug' -f="/var/lib/dpkg/info/$p.list" set -e -if [ ! -e "$f" ]; then exit 1; fi -cat "$f" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done +dpkg-query --listfiles "${p}" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done diff --git a/explain/rubber b/explain/rubber index 1238eed..d9bbdea 100755 --- a/explain/rubber +++ b/explain/rubber @@ -1,6 +1,4 @@ #!/bin/dash p='rubber' -f="/var/lib/dpkg/info/$p.list" set -e -if [ ! -e "$f" ]; then exit 1; fi -cat "$f" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done +dpkg-query --listfiles "${p}" | awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | while read o; do if [ -e "$o" ]; then echo "$o"; fi; done diff --git a/filters_list b/filters_list index 458645f..4150675 100755 --- a/filters_list +++ b/filters_list @@ -11,7 +11,7 @@ get_all_filter_basenames() { # the trick with cat is to detect "disk full" conditions but not fail on directory empty ( - if cd /var/lib/dpkg/info 2>/dev/null ; then ls *.extrafiles 2>/dev/null | sed 's,\.extrafiles$,,' ; fi + dpkg-query -W | awk '{print $1}' | xargs -I '{}' dpkg-query --control-path '{}' extrafiles | xargs -r -n 1 basename | sed 's,\.extrafiles$,,' if cd /etc/cruft/filters 2>/dev/null ; then ls * 2>/dev/null | cat ; fi if cd /usr/lib/cruft/filters 2>/dev/null ; then ls * 2>/dev/null | cat ; fi if [ -n "${type}" ] ; then @@ -27,8 +27,8 @@ for f in $(get_all_filter_basenames) ; do echo "/etc/cruft/filters-${type}/${f}" elif [ -e "/etc/cruft/filters/${f}" ] ; then echo "${LIST}/etc/cruft/filters/${f}" - elif [ -e "/var/lib/dpkg/info/${f}.extrafiles" ] ; then - echo "${LIST}/var/lib/dpkg/info/${f}.extrafiles" + elif package_has_script "${f}" extrafiles ; then + dpkg-query --control-path "${f}" extrafiles | sed "s,^,${LIST}," elif [ -n "${type}" -a -e "/usr/lib/cruft/filters-${type}/${f}" ] ; then echo "${LIST}/usr/lib/cruft/filters-${type}/${f}" elif [ -e "/usr/lib/cruft/filters/${f}" ] ; then